mirror of
https://github.com/Radiquum/AniX.git
synced 2025-09-05 22:15: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 { useState, useEffect } from "react";
|
||||||
import { useScrollPosition } from "#/hooks/useScrollPosition";
|
import { useScrollPosition } from "#/hooks/useScrollPosition";
|
||||||
import { useUserStore } from "../store/auth";
|
import { useUserStore } from "../store/auth";
|
||||||
import { _FetchHomePageReleases } from "#/api/utils";
|
import { FetchFilter } from "#/api/utils";
|
||||||
import { Button, ButtonGroup } from "flowbite-react";
|
import { Button, ButtonGroup } from "flowbite-react";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
|
import { slugToFilter } from "./IndexFilters";
|
||||||
|
|
||||||
export function IndexCategoryPage(props) {
|
export function IndexCategoryPage(props) {
|
||||||
const token = useUserStore((state) => state.token);
|
const token = useUserStore((state) => state.token);
|
||||||
|
@ -20,7 +21,7 @@ export function IndexCategoryPage(props) {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
setContent(null);
|
setContent(null);
|
||||||
|
|
||||||
const data: any = await _FetchHomePageReleases(props.slug, token, page);
|
const [ data ] = await FetchFilter(slugToFilter[props.slug].filter, page, token);
|
||||||
|
|
||||||
setContent(data.content);
|
setContent(data.content);
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
|
@ -32,7 +33,7 @@ export function IndexCategoryPage(props) {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function _loadNextReleasesPage() {
|
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];
|
const newContent = [...content, ...data.content];
|
||||||
setContent(newContent);
|
setContent(newContent);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Filter, FilterDefault } from "#/api/utils";
|
import { FilterDefault } from "#/api/utils";
|
||||||
|
|
||||||
export const ListLast = {
|
export const ListLast = {
|
||||||
name: "Последнее",
|
name: "Последнее",
|
||||||
|
@ -24,3 +24,11 @@ export const ListFilms = {
|
||||||
name: "Фильмы",
|
name: "Фильмы",
|
||||||
filter: { ...FilterDefault, category_id: 2, status_id: null },
|
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