mirror of
https://github.com/Radiquum/AniX.git
synced 2025-04-29 17:39:41 +05:00
feat: add titles to metadata
This commit is contained in:
parent
751b61668f
commit
0ee1139cf1
8 changed files with 310 additions and 269 deletions
|
@ -1,22 +1,4 @@
|
|||
"use client";
|
||||
import useSWRInfinite from "swr/infinite";
|
||||
import { ReleaseSection } from "../../components/ReleaseSection/ReleaseSection";
|
||||
import { Spinner } from "../../components/Spinner/Spinner";
|
||||
import { useState, useEffect } from "react";
|
||||
import { useScrollPosition } from "@/app/hooks/useScrollPosition";
|
||||
|
||||
const fetcher = async url => {
|
||||
const res = await fetch(url);
|
||||
|
||||
if (!res.ok) {
|
||||
const error = new Error("An error occurred while fetching the data.");
|
||||
error.info = await res.json();
|
||||
error.status = res.status;
|
||||
throw error;
|
||||
}
|
||||
|
||||
return res.json();
|
||||
};
|
||||
import { IndexCategoryPage } from "@/app/pages/IndexCategory";
|
||||
|
||||
const SectionTitleMapping = {
|
||||
last: "Последние релизы",
|
||||
|
@ -25,53 +7,20 @@ const SectionTitleMapping = {
|
|||
announce: "Анонсированные релизы",
|
||||
};
|
||||
|
||||
export default function HomeStatus({ params }) {
|
||||
const getKey = (pageIndex, previousPageData) => {
|
||||
if (previousPageData && !previousPageData.content.length) return null;
|
||||
return `/api/home?status=${params.slug}&page=${pageIndex}`;
|
||||
export async function generateMetadata({ params }) {
|
||||
return {
|
||||
title: SectionTitleMapping[params.slug],
|
||||
};
|
||||
}
|
||||
|
||||
const { data, error, isLoading, size, setSize } = useSWRInfinite(
|
||||
getKey,
|
||||
fetcher,
|
||||
{"initialSize": 2, "revalidateFirstPage": false}
|
||||
);
|
||||
|
||||
const [content, setContent] = useState(null);
|
||||
useEffect(() => {
|
||||
if (data) {
|
||||
let allReleases = [];
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
allReleases.push(...data[i].content);
|
||||
}
|
||||
setContent(allReleases);
|
||||
}
|
||||
}, [data]);
|
||||
|
||||
const scrollPosition = useScrollPosition();
|
||||
useEffect(() => {
|
||||
if (scrollPosition >= 98 && scrollPosition <= 99) {
|
||||
setSize(size + 1)
|
||||
}
|
||||
}, [scrollPosition]);
|
||||
|
||||
if (error) return <div>failed to load</div>;
|
||||
if (isLoading)
|
||||
return (
|
||||
<main className="flex flex-col items-center justify-center min-w-full min-h-screen">
|
||||
<Spinner />
|
||||
</main>
|
||||
);
|
||||
|
||||
export default function Index({ params }) {
|
||||
const metadata = {
|
||||
title: "AniX | " + SectionTitleMapping[params.slug],
|
||||
};
|
||||
return (
|
||||
<main className="pt-2 pb-16 sm:pt-4 sm:pb-0">
|
||||
{content && (
|
||||
<ReleaseSection
|
||||
sectionTitle={SectionTitleMapping[params.slug]}
|
||||
content={content}
|
||||
/>
|
||||
)}
|
||||
<button className="mx-auto w-[calc(100%-10rem)] border border-black rounded-lg p-2 mb-6 flex items-center justify-center gap-2 hover:bg-black hover:text-white transition" onClick={() => setSize(size + 1)}> <span className="w-10 h-10 iconify mdi--plus"> </span> <span className="text-lg">Загрузить ещё</span></button>
|
||||
</main>
|
||||
<IndexCategoryPage
|
||||
slug={params.slug}
|
||||
SectionTitleMapping={SectionTitleMapping}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue