mirror of
https://github.com/Radiquum/AniX.git
synced 2025-09-06 06:23:53 +05:00
anix/refactor: change Filter Fetch Function
This commit is contained in:
parent
56334893b4
commit
fd0ce8cb94
5 changed files with 536 additions and 73 deletions
|
@ -3,15 +3,22 @@ import { ReleaseCourusel } from "#/components/ReleaseCourusel/ReleaseCourusel";
|
|||
import { Spinner } from "#/components/Spinner/Spinner";
|
||||
import { useUserStore } from "#/store/auth";
|
||||
import { useState, useEffect } from "react";
|
||||
import { _FetchHomePageReleases } from "#/api/utils";
|
||||
import { FetchFilter } from "#/api/utils";
|
||||
|
||||
import { usePreferencesStore } from "#/store/preferences";
|
||||
import { useRouter } from "next/navigation";
|
||||
import {
|
||||
ListAnnounce,
|
||||
ListFilms,
|
||||
ListFinished,
|
||||
ListLast,
|
||||
ListOngoing,
|
||||
} from "./IndexFilters";
|
||||
|
||||
export function IndexPage() {
|
||||
const token = useUserStore((state) => state.token);
|
||||
const preferenceStore = usePreferencesStore();
|
||||
const router = useRouter()
|
||||
const router = useRouter();
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [lastReleasesData, setLastReleasesData] = useState(null);
|
||||
const [ongoingReleasesData, setOngoingReleasesData] = useState(null);
|
||||
|
@ -21,7 +28,9 @@ export function IndexPage() {
|
|||
|
||||
useEffect(() => {
|
||||
if (preferenceStore.params.skipToCategory.enabled) {
|
||||
router.push(`/home/${preferenceStore.params.skipToCategory.homeCategory}`);
|
||||
router.push(
|
||||
`/home/${preferenceStore.params.skipToCategory.homeCategory}`
|
||||
);
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
@ -35,11 +44,19 @@ export function IndexPage() {
|
|||
setAnnounceReleasesData(null);
|
||||
setFilmsReleasesData(null);
|
||||
|
||||
const lastReleases = await _FetchHomePageReleases("last", token);
|
||||
const ongoingReleases = await _FetchHomePageReleases("ongoing", token);
|
||||
const finishedReleases = await _FetchHomePageReleases("finished", token);
|
||||
const announceReleases = await _FetchHomePageReleases("announce", token);
|
||||
const filmsReleases = await _FetchHomePageReleases("films", token);
|
||||
const [lastReleases] = await FetchFilter(ListLast.filter, 0, token);
|
||||
const [ongoingReleases] = await FetchFilter(ListOngoing.filter, 0, token);
|
||||
const [announceReleases] = await FetchFilter(
|
||||
ListAnnounce.filter,
|
||||
0,
|
||||
token
|
||||
);
|
||||
const [finishedReleases] = await FetchFilter(
|
||||
ListFinished.filter,
|
||||
0,
|
||||
token
|
||||
);
|
||||
const [filmsReleases] = await FetchFilter(ListFilms.filter, 0, token);
|
||||
|
||||
setLastReleasesData(lastReleases);
|
||||
setOngoingReleasesData(ongoingReleases);
|
||||
|
@ -56,16 +73,12 @@ export function IndexPage() {
|
|||
|
||||
return (
|
||||
<>
|
||||
{lastReleasesData ? (
|
||||
{lastReleasesData && (
|
||||
<ReleaseCourusel
|
||||
sectionTitle="Последние релизы"
|
||||
showAllLink="/home/last"
|
||||
content={lastReleasesData.content}
|
||||
/>
|
||||
) : (
|
||||
<div className="flex items-center justify-center min-w-full min-h-screen">
|
||||
<Spinner />
|
||||
</div>
|
||||
)}
|
||||
{finishedReleasesData && (
|
||||
<ReleaseCourusel
|
||||
|
@ -95,15 +108,11 @@ export function IndexPage() {
|
|||
content={filmsReleasesData.content}
|
||||
/>
|
||||
)}
|
||||
{!isLoading &&
|
||||
!lastReleasesData &&
|
||||
!finishedReleasesData &&
|
||||
!ongoingReleasesData &&
|
||||
!announceReleasesData && (
|
||||
<div className="flex items-center justify-center min-w-full min-h-screen">
|
||||
<h1 className="text-2xl">Ошибка загрузки контента...</h1>
|
||||
</div>
|
||||
)}
|
||||
{isLoading && (
|
||||
<div className="flex items-center justify-center h-32 min-w-full">
|
||||
<Spinner />
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
26
app/pages/IndexFilters.tsx
Normal file
26
app/pages/IndexFilters.tsx
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { Filter, FilterDefault } from "#/api/utils";
|
||||
|
||||
export const ListLast = {
|
||||
name: "Последнее",
|
||||
filter: FilterDefault,
|
||||
};
|
||||
|
||||
export const ListOngoing = {
|
||||
name: "Онгоинги",
|
||||
filter: { ...FilterDefault, status_id: 2 },
|
||||
};
|
||||
|
||||
export const ListAnnounce = {
|
||||
name: "Анонсы",
|
||||
filter: { ...FilterDefault, status_id: 3 },
|
||||
};
|
||||
|
||||
export const ListFinished = {
|
||||
name: "Завершённые",
|
||||
filter: { ...FilterDefault, status_id: 1 },
|
||||
};
|
||||
|
||||
export const ListFilms = {
|
||||
name: "Фильмы",
|
||||
filter: { ...FilterDefault, category_id: 2, status_id: null },
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue