diff --git a/app/favicon.ico b/app/favicon.ico
index 718d6fe..46ba219 100644
Binary files a/app/favicon.ico and b/app/favicon.ico differ
diff --git a/app/home/[slug]/page.js b/app/home/[slug]/page.js
index e2c04ec..e982c2b 100644
--- a/app/home/[slug]/page.js
+++ b/app/home/[slug]/page.js
@@ -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
failed to load
;
- if (isLoading)
- return (
-
-
-
- );
-
+export default function Index({ params }) {
+ const metadata = {
+ title: "AniX | " + SectionTitleMapping[params.slug],
+ };
return (
-
- {content && (
-
- )}
-
-
+
);
}
diff --git a/app/layout.js b/app/layout.js
index 0df3186..b13a990 100644
--- a/app/layout.js
+++ b/app/layout.js
@@ -2,7 +2,10 @@ import "./globals.css";
import { App } from "@/app/App";
export const metadata = {
- title: "Create Next App",
+ title: {
+ template: 'AniX | %s',
+ default: 'AniX',
+ },
description: "Generated by create next app",
};
diff --git a/app/page.js b/app/page.js
index cf1643c..b4797ec 100644
--- a/app/page.js
+++ b/app/page.js
@@ -1,54 +1,9 @@
-"use client";
-import useSWR from "swr";
-import { ReleaseCourusel } from "./components/ReleaseCourusel/ReleaseCourusel";
-import { Spinner } from "./components/Spinner/Spinner";
-const fetcher = (...args) => fetch(...args).then((res) => res.json());
+export const metadata = {
+ title: "AniX | Домашняя",
+};
-export default function Home() {
- function useFetchReleases(status) {
- const { data } = useSWR(`/api/home?status=${status}`, fetcher);
- return [data];
- }
+import { IndexPage } from "./pages/Index";
- const [lastReleasesData] = useFetchReleases("last");
- const [finishedReleasesData] = useFetchReleases("finished");
- const [ongoingReleasesData] = useFetchReleases("ongoing");
- const [announceReleasesData] = useFetchReleases("announce");
-
- return (
-
- {lastReleasesData ? (
-
- ) : (
-
-
-
- )}
- {finishedReleasesData && (
-
- )}
- {ongoingReleasesData && (
-
- )}
- {announceReleasesData && (
-
- )}
-
- );
+export default function Index() {
+ return ;
}
diff --git a/app/pages/Index.jsx b/app/pages/Index.jsx
new file mode 100644
index 0000000..c9e9ff4
--- /dev/null
+++ b/app/pages/Index.jsx
@@ -0,0 +1,54 @@
+"use client";
+import useSWR from "swr";
+import { ReleaseCourusel } from "@/app/components/ReleaseCourusel/ReleaseCourusel";
+import { Spinner } from "@/app/components/Spinner/Spinner";
+const fetcher = (...args) => fetch(...args).then((res) => res.json());
+
+export function IndexPage() {
+ function useFetchReleases(status) {
+ const { data } = useSWR(`/api/home?status=${status}`, fetcher);
+ return [data];
+ }
+
+ const [lastReleasesData] = useFetchReleases("last");
+ const [finishedReleasesData] = useFetchReleases("finished");
+ const [ongoingReleasesData] = useFetchReleases("ongoing");
+ const [announceReleasesData] = useFetchReleases("announce");
+
+ return (
+
+ {lastReleasesData ? (
+
+ ) : (
+
+
+
+ )}
+ {finishedReleasesData && (
+
+ )}
+ {ongoingReleasesData && (
+
+ )}
+ {announceReleasesData && (
+
+ )}
+
+ );
+}
diff --git a/app/pages/IndexCategory.jsx b/app/pages/IndexCategory.jsx
new file mode 100644
index 0000000..265e948
--- /dev/null
+++ b/app/pages/IndexCategory.jsx
@@ -0,0 +1,70 @@
+"use client";
+import useSWRInfinite from "swr/infinite";
+import { ReleaseSection } from "@/app/components/ReleaseSection/ReleaseSection";
+import { Spinner } from "@/app/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();
+};
+
+export function IndexCategoryPage(props) {
+ const getKey = (pageIndex, previousPageData) => {
+ if (previousPageData && !previousPageData.content.length) return null;
+ return `/api/home?status=${props.slug}&page=${pageIndex}`;
+ };
+
+ 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 failed to load
;
+ if (isLoading)
+ return (
+
+
+
+ );
+
+ return (
+
+ {content && (
+
+ )}
+
+
+ );
+}
diff --git a/app/pages/Search.jsx b/app/pages/Search.jsx
new file mode 100644
index 0000000..047a62d
--- /dev/null
+++ b/app/pages/Search.jsx
@@ -0,0 +1,154 @@
+"use client";
+import useSWRInfinite from "swr/infinite";
+import { ReleaseSection } from "@/app/components/ReleaseSection/ReleaseSection";
+import { Spinner } from "@/app/components/Spinner/Spinner";
+import { useState, useEffect } from "react";
+import { useScrollPosition } from "@/app/hooks/useScrollPosition";
+import { useRouter } from "next/navigation";
+import { useSearchParams } from "next/navigation";
+
+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();
+};
+
+export function SearchPage() {
+ const router = useRouter();
+ const searchParams = useSearchParams();
+ const [query, setQuery] = useState(searchParams.get("q") || null);
+
+ const getKey = (pageIndex, previousPageData) => {
+ if (previousPageData && !previousPageData.content.length) return null;
+
+ const url = new URL("/api/search", window.location.origin);
+ url.searchParams.set("page", pageIndex);
+
+ if (query) {
+ url.searchParams.set("q", query);
+ return url.toString();
+ }
+ return;
+ };
+
+ 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 failed to load
;
+
+ return (
+
+
+
+ {content ? (
+ content.length > 0 ? (
+
+ ) : (
+
+
+
Странно, аниме не найдено, попробуйте другой запрос...
+
+ )
+ ) : (
+ isLoading && (
+
+
+
+ )
+ )}
+ {!content && !isLoading && !query && (
+
+
+
Введите ваш запрос что-бы найти любимый тайтл
+
+ )}
+
+ {data && data[data.length - 1].content.length == 25 && (
+
+ )}
+
+ );
+}
diff --git a/app/search/page.js b/app/search/page.js
index 755407b..229a4d2 100644
--- a/app/search/page.js
+++ b/app/search/page.js
@@ -1,160 +1,16 @@
-"use client";
-import useSWRInfinite from "swr/infinite";
-import { ReleaseSection } from "@/app/components/ReleaseSection/ReleaseSection";
-import { Spinner } from "@/app/components/Spinner/Spinner";
-import { useState, useEffect } from "react";
-import { useScrollPosition } from "@/app/hooks/useScrollPosition";
-import { usePathname, useRouter } from "next/navigation";
-import { useSearchParams } from "next/navigation";
import dynamic from "next/dynamic";
+import { SearchPage } from "@/app/pages/Search";
-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();
-};
-
-function Search() {
- const router = useRouter();
- const searchParams = useSearchParams();
- const [query, setQuery] = useState(searchParams.get("q") || null);
-
- const getKey = (pageIndex, previousPageData) => {
- if (previousPageData && !previousPageData.content.length) return null;
-
- const url = new URL("/api/search", window.location.origin);
- url.searchParams.set("page", pageIndex);
-
- if (query) {
- url.searchParams.set("q", query);
- return url.toString();
- }
- return;
+export async function generateMetadata({ searchParams }) {
+ const query = searchParams.q;
+ return {
+ title: query || "Поиск",
};
-
- 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 failed to load
;
-
- return (
-
-
-
- {content ? (
- content.length > 0 ? (
-
- ) : (
-
-
-
Странно, аниме не найдено, попробуйте другой запрос...
-
- )
- ) : (
- isLoading && (
-
-
-
- )
- )}
- {!content && !isLoading && !query && (
-
-
-
Введите ваш запрос что-бы найти любимый тайтл
-
- )}
-
- {data && data[data.length - 1].content.length == 25 && (
-
- )}
-
- );
}
-const SearchDynamic = dynamic(() => Promise.resolve(Search), { ssr: false });
-export default function SearchPage() {
+const SearchDynamic = dynamic(() => Promise.resolve(SearchPage), {
+ ssr: false,
+});
+export default function Search() {
return ;
}