diff options
| author | Factiven <[email protected]> | 2023-04-17 13:33:37 +0700 |
|---|---|---|
| committer | Factiven <[email protected]> | 2023-04-17 13:33:37 +0700 |
| commit | 545d8a3473823f0a86cad3c177dbbb4ebb794a75 (patch) | |
| tree | 1606111911ea31c8fd8f9560dade41f5fedd6520 /lib | |
| parent | Update 7th (diff) | |
| download | moopa-545d8a3473823f0a86cad3c177dbbb4ebb794a75.tar.xz moopa-545d8a3473823f0a86cad3c177dbbb4ebb794a75.zip | |
Snapshot Moopa v3.2
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/useAnilist.js | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/lib/useAnilist.js b/lib/useAnilist.js index 71882c0..acae54f 100644 --- a/lib/useAnilist.js +++ b/lib/useAnilist.js @@ -1,14 +1,14 @@ import { useState, useEffect } from "react"; -export function useAniList(session) { +export function useAniList(session, stats) { const [media, setMedia] = useState([]); // const [aniAdvanceSearch, setAniAdvanceSearch] = useState([]); // Queries const queryMedia = ` - query ($username: String) { - MediaListCollection(userName: $username, type: ANIME) { + query ($username: String, $status: MediaListStatus) { + MediaListCollection(userName: $username, type: ANIME, status: $status) { lists { status name @@ -44,7 +44,7 @@ export function useAniList(session) { lastPage hasNextPage } - media (search: $search, type: $type, status: $status, season: $season, seasonYear: $year, genre_in: $genres, tag_in: $tags, sort: $sort) { + media (search: $search, type: $type, status: $status, season: $season, seasonYear: $year, genre_in: $genres, tag_in: $tags, sort: $sort, isAdult: false) { id title { userPreferred @@ -77,8 +77,8 @@ export function useAniList(session) { `; const progressWatched = ` - mutation($mediaId: Int, $progress: Int) { - SaveMediaListEntry(mediaId: $mediaId, progress: $progress, status: CURRENT) { + mutation($mediaId: Int, $progress: Int, $status: MediaListStatus) { + SaveMediaListEntry(mediaId: $mediaId, progress: $progress, status: $status) { id mediaId progress @@ -89,6 +89,8 @@ export function useAniList(session) { const username = session?.user?.name; const accessToken = session?.user?.token; + let statuss = stats || null; + // console.log(session); useEffect(() => { async function fetchData() { @@ -100,9 +102,37 @@ export function useAniList(session) { "Content-Type": "application/json", }, body: JSON.stringify({ - query: queryMedia, + query: ` + query ($username: String, $status: MediaListStatus) { + MediaListCollection(userName: $username, type: ANIME, status: $status) { + lists { + status + name + entries { + id + mediaId + status + progress + score + media { + id + title { + english + romaji + } + episodes + coverImage { + large + } + } + } + } + } + } + `, variables: { username: username, + status: statuss?.stats, }, }), }); @@ -139,7 +169,7 @@ export function useAniList(session) { } } - async function markProgress(mediaId, progress) { + async function markProgress(mediaId, progress, stats) { if (!accessToken) return; const response = await fetch("https://graphql.anilist.co/", { method: "POST", @@ -152,11 +182,12 @@ export function useAniList(session) { variables: { mediaId: mediaId, progress: progress, + status: stats, }, }), }); if (response.ok) { - console.log("Progress Updated"); + // console.log(`Progress Updated: ${progress}`); } else if (response.status === 401) { console.log("Unauthorized"); } else if (response.status === 400) { |