mirror of
https://github.com/Radiquum/AniX.git
synced 2025-04-06 16:24:40 +00:00
feat(frontend): add user favorites page
This commit is contained in:
parent
332e1d1918
commit
90f2ba54e5
4 changed files with 81 additions and 10 deletions
|
@ -9,7 +9,7 @@ router = APIRouter()
|
||||||
@router.get("", summary="Get user favorites list")
|
@router.get("", summary="Get user favorites list")
|
||||||
async def GetUserFavorites(request: Request, token: str, page: int = 0):
|
async def GetUserFavorites(request: Request, token: str, page: int = 0):
|
||||||
return await apiRequest(
|
return await apiRequest(
|
||||||
request, ENDPOINTS["user"]["favorite"], f"/all/{page}", query=f"?token={token}"
|
request, ENDPOINTS["user"]["favorite"], f"all/{page}", query=f"?token={token}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ async def addReleaseToFavorites(request: Request, release_id: int, token: str):
|
||||||
return await apiRequest(
|
return await apiRequest(
|
||||||
request,
|
request,
|
||||||
ENDPOINTS["user"]["favorite"],
|
ENDPOINTS["user"]["favorite"],
|
||||||
f"/add/{release_id}",
|
f"add/{release_id}",
|
||||||
query=f"?token={token}",
|
query=f"?token={token}",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -28,6 +28,6 @@ async def deleteReleaseFromFavorites(request: Request, release_id: int, token: s
|
||||||
return await apiRequest(
|
return await apiRequest(
|
||||||
request,
|
request,
|
||||||
ENDPOINTS["user"]["favorite"],
|
ENDPOINTS["user"]["favorite"],
|
||||||
f"/delete/{release_id}",
|
f"delete/{release_id}",
|
||||||
query=f"?token={token}",
|
query=f"?token={token}",
|
||||||
)
|
)
|
||||||
|
|
|
@ -20,6 +20,7 @@ export const endpoints = {
|
||||||
delayed: `${API_URL}/bookmarks/delayed`,
|
delayed: `${API_URL}/bookmarks/delayed`,
|
||||||
abandoned: `${API_URL}/bookmarks/abandoned`,
|
abandoned: `${API_URL}/bookmarks/abandoned`,
|
||||||
},
|
},
|
||||||
|
favorites: `${API_URL}/favorites`,
|
||||||
},
|
},
|
||||||
release: `${API_URL}/release`,
|
release: `${API_URL}/release`,
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,13 +27,13 @@ export const NavigationRail = (props) => {
|
||||||
icon: "bookmark",
|
icon: "bookmark",
|
||||||
path: "/bookmarks",
|
path: "/bookmarks",
|
||||||
},
|
},
|
||||||
//
|
|
||||||
// {
|
{
|
||||||
// title: "Избранное",
|
title: "Избранное",
|
||||||
// icon: "favorite",
|
icon: "favorite",
|
||||||
// path: "/favorites",
|
path: "/favorites",
|
||||||
// },
|
},
|
||||||
//
|
|
||||||
{
|
{
|
||||||
title: "История",
|
title: "История",
|
||||||
icon: "history",
|
icon: "history",
|
||||||
|
|
70
frontend/app/favorites/page.js
Normal file
70
frontend/app/favorites/page.js
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
"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();
|
||||||
|
|
||||||
|
const [releases, setReleases] = useState();
|
||||||
|
const [page, setPage] = useState(0);
|
||||||
|
|
||||||
|
const [isNextPage, setIsNextPage] = useState(true);
|
||||||
|
|
||||||
|
async function fetchData(page = 0) {
|
||||||
|
if (userStore.token) {
|
||||||
|
const url = `${endpoints.user.favorites}?page=${page}&token=${userStore.token}`;
|
||||||
|
const data = await getData(url);
|
||||||
|
|
||||||
|
if (data.content.length < 25) {
|
||||||
|
setIsNextPage(false);
|
||||||
|
} else {
|
||||||
|
setIsNextPage(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 ? (
|
||||||
|
<LogInNeeded />
|
||||||
|
) : releases > 0 ? (
|
||||||
|
<ReleasesOverview
|
||||||
|
page={page}
|
||||||
|
setPage={setPage}
|
||||||
|
releases={releases}
|
||||||
|
isNextPage={isNextPage}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div className="absolute padding primary center middle small-round">
|
||||||
|
<i className="extra">sentiment_dissatisfied</i>
|
||||||
|
<h5>Здесь пока ничего нет.</h5>
|
||||||
|
<p>Добавьте любимое аниме, что бы его не потерять.</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue