mirror of
https://github.com/Radiquum/AniX.git
synced 2025-09-04 05:25:36 +05:00
anix/refactor: index category page data fetcher
This commit is contained in:
parent
fd0ce8cb94
commit
a615af836b
2 changed files with 13 additions and 4 deletions
|
@ -4,9 +4,10 @@ import { Spinner } from "#/components/Spinner/Spinner";
|
|||
import { useState, useEffect } from "react";
|
||||
import { useScrollPosition } from "#/hooks/useScrollPosition";
|
||||
import { useUserStore } from "../store/auth";
|
||||
import { _FetchHomePageReleases } from "#/api/utils";
|
||||
import { FetchFilter } from "#/api/utils";
|
||||
import { Button, ButtonGroup } from "flowbite-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { slugToFilter } from "./IndexFilters";
|
||||
|
||||
export function IndexCategoryPage(props) {
|
||||
const token = useUserStore((state) => state.token);
|
||||
|
@ -20,7 +21,7 @@ export function IndexCategoryPage(props) {
|
|||
setIsLoading(true);
|
||||
setContent(null);
|
||||
|
||||
const data: any = await _FetchHomePageReleases(props.slug, token, page);
|
||||
const [ data ] = await FetchFilter(slugToFilter[props.slug].filter, page, token);
|
||||
|
||||
setContent(data.content);
|
||||
setIsLoading(false);
|
||||
|
@ -32,7 +33,7 @@ export function IndexCategoryPage(props) {
|
|||
|
||||
useEffect(() => {
|
||||
async function _loadNextReleasesPage() {
|
||||
const data: any = await _FetchHomePageReleases(props.slug, token, page);
|
||||
const [ data ] = await FetchFilter(slugToFilter[props.slug].filter, page, token);
|
||||
const newContent = [...content, ...data.content];
|
||||
setContent(newContent);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Filter, FilterDefault } from "#/api/utils";
|
||||
import { FilterDefault } from "#/api/utils";
|
||||
|
||||
export const ListLast = {
|
||||
name: "Последнее",
|
||||
|
@ -24,3 +24,11 @@ export const ListFilms = {
|
|||
name: "Фильмы",
|
||||
filter: { ...FilterDefault, category_id: 2, status_id: null },
|
||||
};
|
||||
|
||||
export const slugToFilter = {
|
||||
last: ListLast,
|
||||
ongoing: ListOngoing,
|
||||
announce: ListAnnounce,
|
||||
finished: ListFinished,
|
||||
films: ListFilms,
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue