aboutsummaryrefslogtreecommitdiff
path: root/lib/anilist
diff options
context:
space:
mode:
Diffstat (limited to 'lib/anilist')
-rw-r--r--lib/anilist/aniAdvanceSearch.js127
-rw-r--r--lib/anilist/getMedia.js2
-rw-r--r--lib/anilist/useAnilist.js7
3 files changed, 100 insertions, 36 deletions
diff --git a/lib/anilist/aniAdvanceSearch.js b/lib/anilist/aniAdvanceSearch.js
index 02a5c53..cf344b0 100644
--- a/lib/anilist/aniAdvanceSearch.js
+++ b/lib/anilist/aniAdvanceSearch.js
@@ -23,37 +23,104 @@ export async function aniAdvanceSearch({
return result;
}, {});
- const response = await fetch("https://graphql.anilist.co/", {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({
- query: advanceSearchQuery,
- variables: {
- ...(search && {
- search: search,
- ...(!sort && { sort: "SEARCH_MATCH" }),
- }),
- ...(type && { type: type }),
- ...(seasonYear && { seasonYear: seasonYear }),
- ...(season && {
- season: season,
- ...(!seasonYear && { seasonYear: new Date().getFullYear() }),
- }),
- ...(categorizedGenres && { ...categorizedGenres }),
- ...(format && { format: format }),
- // ...(genres && { genres: genres }),
- // ...(tags && { tags: tags }),
- ...(perPage && { perPage: perPage }),
- ...(sort && { sort: sort }),
+ if (type === "MANGA") {
+ const response = await fetch("https://api.anify.tv/search-advanced", {
+ method: "POST",
+ body: JSON.stringify({
+ type: "manga",
+ genres: categorizedGenres,
+ ...(search && { query: search }),
...(page && { page: page }),
+ ...(perPage && { perPage: perPage }),
+ ...(format && { format: format }),
+ ...(seasonYear && { year: seasonYear }),
+ ...(type && { type: type }),
+ }),
+ });
+
+ const data = await response.json();
+ return {
+ pageInfo: {
+ hasNextPage: data.length >= (perPage ?? 20),
+ currentPage: page,
+ lastPage: Math.ceil(data.length / (perPage ?? 20)),
+ perPage: perPage ?? 20,
+ total: data.length,
+ },
+ media: data.map((item) => ({
+ averageScore: item.averageRating,
+ bannerImage: item.bannerImage,
+ chapters: item.totalChapters,
+ coverImage: {
+ color: item.color,
+ extraLarge: item.coverImage,
+ large: item.coverImage,
+ },
+ description: item.description,
+ duration: item.duration ?? null,
+ endDate: {
+ day: null,
+ month: null,
+ year: null,
+ },
+ mappings: item.mappings,
+ format: item.format,
+ genres: item.genres,
+ id: item.id,
+ isAdult: false,
+ mediaListEntry: null,
+ nextAiringEpisode: null,
+ popularity: item.averagePopularity,
+ season: null,
+ seasonYear: item.year,
+ startDate: {
+ day: null,
+ month: null,
+ year: item.year,
+ },
+ status: item.status,
+ studios: { edges: [] },
+ title: {
+ userPreferred:
+ item.title.english ?? item.title.romaji ?? item.title.native,
+ },
+ type: item.type,
+ volumes: item.totalVolumes ?? null,
+ })),
+ };
+ } else {
+ const response = await fetch("https://graphql.anilist.co/", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
},
- }),
- });
+ body: JSON.stringify({
+ query: advanceSearchQuery,
+ variables: {
+ ...(search && {
+ search: search,
+ ...(!sort && { sort: "SEARCH_MATCH" }),
+ }),
+ ...(type && { type: type }),
+ ...(seasonYear && { seasonYear: seasonYear }),
+ ...(season && {
+ season: season,
+ ...(!seasonYear && { seasonYear: new Date().getFullYear() }),
+ }),
+ ...(categorizedGenres && { ...categorizedGenres }),
+ ...(format && { format: format }),
+ // ...(genres && { genres: genres }),
+ // ...(tags && { tags: tags }),
+ ...(perPage && { perPage: perPage }),
+ ...(sort && { sort: sort }),
+ ...(page && { page: page }),
+ },
+ }),
+ });
- const datas = await response.json();
- // console.log(datas);
- const data = datas.data.Page;
- return data;
+ const datas = await response.json();
+ // console.log(datas);
+ const data = datas.data.Page;
+ return data;
+ }
}
diff --git a/lib/anilist/getMedia.js b/lib/anilist/getMedia.js
index 66bb1b0..2e1b0d0 100644
--- a/lib/anilist/getMedia.js
+++ b/lib/anilist/getMedia.js
@@ -115,6 +115,8 @@ export default function GetMedia(session, stats) {
data.data.Page.recommendations.map((i) => i.mediaRecommendation)
);
});
+
+ // eslint-disable-next-line react-hooks/exhaustive-deps
}, [username, accessToken, status?.stats]);
return { anime, manga, recommendations };
diff --git a/lib/anilist/useAnilist.js b/lib/anilist/useAnilist.js
index 17ab11b..20c1964 100644
--- a/lib/anilist/useAnilist.js
+++ b/lib/anilist/useAnilist.js
@@ -1,4 +1,4 @@
-import { toast } from "react-toastify";
+import { toast } from "sonner";
export const useAniList = (session) => {
const accessToken = session?.user?.token;
@@ -238,11 +238,6 @@ export const useAniList = (session) => {
console.log(`Progress Updated: ${progress}`, status);
toast.success(`Progress Updated: ${progress}`, {
position: "bottom-right",
- autoClose: 5000,
- hideProgressBar: false,
- closeOnClick: true,
- draggable: true,
- theme: "dark",
});
}
};