diff --git a/frontend/app/api/config.js b/frontend/app/api/config.js index 7520fbd..e594b01 100644 --- a/frontend/app/api/config.js +++ b/frontend/app/api/config.js @@ -11,5 +11,13 @@ export const endpoints = { user: { profile: `${API_URL}/profile`, auth: `${API_URL}/auth`, + history: `${API_URL}/favorites/history`, + bookmarks: { + watching: `${API_URL}/favorites/watching`, + planned: `${API_URL}/favorites/planned`, + watched: `${API_URL}/favorites/watched`, + delayed: `${API_URL}/favorites/delayed`, + abandoned: `${API_URL}/favorites/abandoned`, + }, }, }; diff --git a/frontend/app/components/ReleasesOverview/ReleasesOverview.jsx b/frontend/app/components/ReleasesOverview/ReleasesOverview.jsx new file mode 100644 index 0000000..37cfb1e --- /dev/null +++ b/frontend/app/components/ReleasesOverview/ReleasesOverview.jsx @@ -0,0 +1,47 @@ +import { CardList } from "@/app/components/CardList/CardList"; + +export default function ReleasesOverview(props) { + return ( + <> + {props.chips && ( +
+ {props.chips.map((item) => { + return ( + + ); + })} +
+ )} + + {props.releases ? ( + <> +
+ +
+ + + + ) : ( + + )} + + ); +} diff --git a/frontend/app/history/page.js b/frontend/app/history/page.js index a57bf2f..845adf8 100644 --- a/frontend/app/history/page.js +++ b/frontend/app/history/page.js @@ -1,10 +1,51 @@ "use client"; import { LogInNeeded } from "@/app/components/LogInNeeded/LogInNeeded"; +import ReleasesOverview from "../components/ReleasesOverview/ReleasesOverview"; import { useUserStore } from "@/app/store/user-store"; +import { endpoints } from "../api/config"; +import { useEffect, useState } from "react"; +import { getData } from "../api/api-utils"; export default function History() { const userStore = useUserStore(); - return <>{!userStore.isAuth ? : ""}; + const [releases, setReleases] = useState(); + const [page, setPage] = useState(0); + + async function fetchData(page = 0) { + if (userStore.token) { + const url = `${endpoints.user.history}?page=${page}&token=${userStore.token}`; + const data = await getData(url); + + // Handle initial load (page 0) or subsequent pagination + if (page === 0) { + setReleases(data.content); + } else { + setReleases([...releases, ...data.content]); + } + } + } + + useEffect(() => { + fetchData(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [userStore]); + + useEffect(() => { + if (releases) { + fetchData(page); // Use fetchData for pagination + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [page]); + + return ( + <> + {!userStore.isAuth ? ( + + ) : ( + + )} + + ); } diff --git a/frontend/app/page.js b/frontend/app/page.js index a9bf1cd..3c2df44 100644 --- a/frontend/app/page.js +++ b/frontend/app/page.js @@ -4,8 +4,8 @@ import { getData } from "./api/api-utils"; import { endpoints } from "./api/config"; import { useEffect, useState, useCallback } from "react"; import { usePathname, useRouter } from "next/navigation"; -import { CardList } from "./components/CardList/CardList"; import { useSearchParams } from "next/navigation"; +import ReleasesOverview from "./components/ReleasesOverview/ReleasesOverview"; export default function Home() { const router = useRouter(); @@ -86,44 +86,13 @@ export default function Home() { ]; return ( - <> -
- {chips.map((item) => { - return ( - - ); - })} -
- - {releases ? ( - <> -
- -
- - - - ) : ( - - )} - + ); }