diff --git a/app/App.jsx b/app/App.jsx index 6fabfb3..d122cc3 100644 --- a/app/App.jsx +++ b/app/App.jsx @@ -6,10 +6,10 @@ import { useEffect } from "react"; const inter = Inter({ subsets: ["latin"] }); export const App = (props) => { - const userStore = useUserStore(); + const userStore = useUserStore((state) => state); useEffect(() => { userStore.checkAuth(); - }, []) + }, []); return ( @@ -17,4 +17,4 @@ export const App = (props) => { {props.children} ); -} +}; diff --git a/app/components/Navbar/Navbar.jsx b/app/components/Navbar/Navbar.jsx index b883423..8cb1e83 100644 --- a/app/components/Navbar/Navbar.jsx +++ b/app/components/Navbar/Navbar.jsx @@ -5,7 +5,7 @@ import { useUserStore } from "@/app/store/auth"; export const Navbar = () => { const pathname = usePathname(); - const userStore = useUserStore(); + const userStore = useUserStore((state) => state); const isNotAuthorizedStyle = "text-gray-700"; const navLinks = [ @@ -85,7 +85,7 @@ export const Navbar = () => { ); })} - {userStore.user ? ( + {userStore.isAuth ? (

{userStore.user.login}

diff --git a/app/components/ReleaseLink/ReleaseLink.jsx b/app/components/ReleaseLink/ReleaseLink.jsx index c26975d..8f6c7f6 100644 --- a/app/components/ReleaseLink/ReleaseLink.jsx +++ b/app/components/ReleaseLink/ReleaseLink.jsx @@ -2,6 +2,20 @@ import Link from "next/link"; export const ReleaseLink = (props) => { const grade = props.grade.toFixed(1); + const profile_lists = { + // 0: "Не смотрю", + 1: { name: "Смотрю", bg_color: "bg-green-500" }, + 2: { name: "В планах", bg_color: "bg-purple-500" }, + 3: { name: "Просмотрено", bg_color: "bg-blue-500" }, + 4: { name: "Отложено", bg_color: "bg-yellow-500" }, + 5: { name: "Брошено", bg_color: "bg-red-500" }, + }; + + const profile_list_status = props.profile_list_status; + let user_list = null; + if (profile_list_status != null || profile_list_status != 0) { + user_list = profile_lists[profile_list_status]; + } return (
@@ -11,22 +25,38 @@ export const ReleaseLink = (props) => { src={props.image} alt="" /> -
-

- {grade} -

+
+
+
+

+ {grade} +

+
+ {props.is_favorite && ( +
+ +
+ )} +
+ {user_list && ( +
+

+ {user_list.name} +

+
+ )}
{props.status ? ( diff --git a/app/pages/Index.jsx b/app/pages/Index.jsx index f91075b..5db6093 100644 --- a/app/pages/Index.jsx +++ b/app/pages/Index.jsx @@ -3,10 +3,20 @@ 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()); +import { useUserStore } from "@/app/store/auth"; export function IndexPage() { + const userStore = useUserStore((state) => state); + const token = userStore.token; + function useFetchReleases(status) { - const { data } = useSWR(`/api/home?status=${status}`, fetcher); + let url; + + url = `/api/home?status=${status}`; + if (token) { + url += `&token=${token}`; + } + const { data } = useSWR(url, fetcher); return [data]; } diff --git a/app/pages/IndexCategory.jsx b/app/pages/IndexCategory.jsx index 1f813c4..3af4b1e 100644 --- a/app/pages/IndexCategory.jsx +++ b/app/pages/IndexCategory.jsx @@ -4,6 +4,7 @@ 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 { useUserStore } from "../store/auth"; const fetcher = async url => { const res = await fetch(url); @@ -19,8 +20,13 @@ const fetcher = async url => { }; export function IndexCategoryPage(props) { + const userStore = useUserStore((state) => state); + const token = userStore.token; const getKey = (pageIndex, previousPageData) => { if (previousPageData && !previousPageData.content.length) return null; + if (token) { + return `/api/home?status=${props.slug}&page=${pageIndex}&token=${token}`; + } return `/api/home?status=${props.slug}&page=${pageIndex}`; };