mirror of
https://github.com/Radiquum/AniX.git
synced 2025-04-06 16:24:40 +00:00
feat(frontend/release): add ability to change boormarks list on releases page for authorized users
This commit is contained in:
parent
632684cde8
commit
0f937f09d0
3 changed files with 134 additions and 33 deletions
|
@ -9,8 +9,10 @@ router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{release_id}", summary="Get release info")
|
@router.get("/{release_id}", summary="Get release info")
|
||||||
async def GetReleaseById(request: Request, release_id: str):
|
async def GetReleaseById(request: Request, release_id: str, token: str = ""):
|
||||||
return await apiRequest(request, ENDPOINTS["release"]["info"], release_id)
|
return await apiRequest(
|
||||||
|
request, ENDPOINTS["release"]["info"], release_id, query=f"?token={token}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{release_id}/voiceover", summary="Get release voiceover info")
|
@router.get("/{release_id}/voiceover", summary="Get release voiceover info")
|
||||||
|
|
|
@ -28,3 +28,25 @@ async def getUserById(
|
||||||
},
|
},
|
||||||
"is_my_profile": res["is_my_profile"],
|
"is_my_profile": res["is_my_profile"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/{release_id}/{list}/add", summary="Add release to bookmarks list")
|
||||||
|
async def addReleaseToBookmarks(
|
||||||
|
request: Request, release_id: int, list: int, token: str
|
||||||
|
):
|
||||||
|
return await apiRequest(
|
||||||
|
request,
|
||||||
|
f"{ENDPOINTS['profile']}/list/add/{list}/{release_id}",
|
||||||
|
query=f"?token={token}",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/{release_id}/{list}/delete", summary="Remove release from bookmarks list")
|
||||||
|
async def deleteReleaseFromBookmarks(
|
||||||
|
request: Request, release_id: int, list: int, token: str
|
||||||
|
):
|
||||||
|
return await apiRequest(
|
||||||
|
request,
|
||||||
|
f"{ENDPOINTS['profile']}/list/delete/{list}/{release_id}",
|
||||||
|
query=f"?token={token}",
|
||||||
|
)
|
||||||
|
|
|
@ -4,20 +4,69 @@ import { useEffect, useState } from "react";
|
||||||
import { getData } from "@/app/api/api-utils";
|
import { getData } from "@/app/api/api-utils";
|
||||||
import { endpoints } from "@/app/api/config";
|
import { endpoints } from "@/app/api/config";
|
||||||
import { ReleaseCard } from "../ReleaseCard/ReleaseCard";
|
import { ReleaseCard } from "../ReleaseCard/ReleaseCard";
|
||||||
|
import { useUserStore } from "@/app/store/user-store";
|
||||||
|
|
||||||
export const ReleaseInfo = (props) => {
|
export const ReleaseInfo = (props) => {
|
||||||
|
const userStore = useUserStore();
|
||||||
const [releaseInfo, setReleaseInfo] = useState();
|
const [releaseInfo, setReleaseInfo] = useState();
|
||||||
|
const [list, setList] = useState();
|
||||||
|
const [timer, seTimer] = useState();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function _fetchInfo() {
|
async function _fetchInfo() {
|
||||||
const release = await getData(`${endpoints.release}/${props.id}`);
|
let url = `${endpoints.release}/${props.id}`;
|
||||||
|
|
||||||
|
if (userStore.token) {
|
||||||
|
url = `${endpoints.release}/${props.id}?token=${userStore.token}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const release = await getData(url);
|
||||||
setReleaseInfo(release);
|
setReleaseInfo(release);
|
||||||
|
if (userStore.token) {
|
||||||
|
setList(release.release.profile_list_status || 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// I really think it's not the way it is should be done
|
||||||
|
// but it works
|
||||||
|
// FIX: double requests, 1st without token, and second with it.
|
||||||
|
// now it's only 1 request with or w/o token, if page is reloaded.
|
||||||
|
if (userStore.token) {
|
||||||
|
clearTimeout(timer);
|
||||||
}
|
}
|
||||||
if (props.id) {
|
if (props.id) {
|
||||||
_fetchInfo();
|
seTimer(
|
||||||
|
setTimeout(() => {
|
||||||
|
_fetchInfo();
|
||||||
|
}, 1000),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, []);
|
}, [userStore.token]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
async function _setList() {
|
||||||
|
const url = `${endpoints.user.profile}/${props.id}/${list}/add?token=${userStore.token}`;
|
||||||
|
await getData(url);
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
userStore.token &&
|
||||||
|
releaseInfo &&
|
||||||
|
list != releaseInfo.release.profile_list_status
|
||||||
|
) {
|
||||||
|
_setList();
|
||||||
|
releaseInfo.release.profile_list_status = list;
|
||||||
|
}
|
||||||
|
}, [userStore.token, list]);
|
||||||
|
|
||||||
|
const lists = [
|
||||||
|
{ list: 0, name: "Не смотрю" },
|
||||||
|
{ list: 1, name: "Смотрю" },
|
||||||
|
{ list: 2, name: "В планах" },
|
||||||
|
{ list: 3, name: "Просмотрено" },
|
||||||
|
{ list: 4, name: "Отложено" },
|
||||||
|
{ list: 5, name: "Брошено" },
|
||||||
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -30,10 +79,36 @@ export const ReleaseInfo = (props) => {
|
||||||
</div>
|
</div>
|
||||||
<div className="s9">
|
<div className="s9">
|
||||||
<div className="padding">
|
<div className="padding">
|
||||||
<h5>{releaseInfo.release.title_ru}</h5>
|
<div className="grid">
|
||||||
<h6 className="small no-margin">
|
<div className="s9">
|
||||||
{releaseInfo.release.title_original}
|
<h5>{releaseInfo.release.title_ru}</h5>
|
||||||
</h6>
|
<h6 className="small no-margin">
|
||||||
|
{releaseInfo.release.title_original}
|
||||||
|
</h6>
|
||||||
|
</div>
|
||||||
|
<div className="s3 right-align">
|
||||||
|
{list >= 0 && (
|
||||||
|
<button className="responsive">
|
||||||
|
<span>{lists[list].name}</span>
|
||||||
|
<i>arrow_drop_down</i>
|
||||||
|
<menu>
|
||||||
|
{lists.map((item) => {
|
||||||
|
return (
|
||||||
|
<a
|
||||||
|
key={item.list}
|
||||||
|
onClick={() => {
|
||||||
|
setList(item.list);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{item.name}
|
||||||
|
</a>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</menu>
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<p className="small no-margin">
|
<p className="small no-margin">
|
||||||
{releaseInfo.release.country} •{" "}
|
{releaseInfo.release.country} •{" "}
|
||||||
{releaseInfo.release.status.name} •{" "}
|
{releaseInfo.release.status.name} •{" "}
|
||||||
|
@ -47,30 +122,32 @@ export const ReleaseInfo = (props) => {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
<article className="grid">
|
{releaseInfo.release.related_releases.length > 0 && (
|
||||||
<div className="row s12">
|
<article className="grid">
|
||||||
<i>hub</i>
|
<div className="row s12">
|
||||||
<h5>Связанные релизы</h5>
|
<i>hub</i>
|
||||||
</div>
|
<h5>Связанные релизы</h5>
|
||||||
<nav className="s12 scroll">
|
</div>
|
||||||
{releaseInfo.release.related_releases.map((item) => {
|
<nav className="s12 scroll">
|
||||||
if (item.id == props.id) {
|
{releaseInfo.release.related_releases.map((item) => {
|
||||||
return "";
|
if (item.id == props.id) {
|
||||||
}
|
return "";
|
||||||
return (
|
}
|
||||||
<ReleaseCard
|
return (
|
||||||
className={"s1"}
|
<ReleaseCard
|
||||||
key={item.id}
|
className={"s1"}
|
||||||
id={item.id}
|
key={item.id}
|
||||||
title={item.title_ru}
|
id={item.id}
|
||||||
poster={item.image}
|
title={item.title_ru}
|
||||||
description={""}
|
poster={item.image}
|
||||||
height={400}
|
description={""}
|
||||||
/>
|
height={400}
|
||||||
);
|
/>
|
||||||
})}
|
);
|
||||||
</nav>
|
})}
|
||||||
</article>
|
</nav>
|
||||||
|
</article>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<div className="center-align">
|
<div className="center-align">
|
||||||
|
|
Loading…
Add table
Reference in a new issue