From cffb96b837989c2768defd27c1251b2ceccf6c11 Mon Sep 17 00:00:00 2001 From: Kentai Radiquum Date: Wed, 1 May 2024 12:41:42 +0500 Subject: [PATCH] feat(frontend/release): add a favorite button to release page --- .../app/components/Release/ReleaseInfo.jsx | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/frontend/app/components/Release/ReleaseInfo.jsx b/frontend/app/components/Release/ReleaseInfo.jsx index 8f643c8..6e87592 100644 --- a/frontend/app/components/Release/ReleaseInfo.jsx +++ b/frontend/app/components/Release/ReleaseInfo.jsx @@ -10,6 +10,7 @@ export const ReleaseInfo = (props) => { const userStore = useUserStore(); const [releaseInfo, setReleaseInfo] = useState(); const [list, setList] = useState(); + const [isFavorite, setIsFavorite] = useState(false); const [timer, seTimer] = useState(); useEffect(() => { @@ -24,6 +25,7 @@ export const ReleaseInfo = (props) => { setReleaseInfo(release); if (userStore.token) { setList(release.release.profile_list_status || 0); + setIsFavorite(release.release.is_favorite); } } @@ -59,6 +61,15 @@ export const ReleaseInfo = (props) => { } }, [userStore.token, list]); + function _setFav() { + async function __updateFavorite() { + const add_url = `${endpoints.user.favorites}/list/${props.id}/add?token=${userStore.token}`; + const delete_url = `${endpoints.user.favorites}/list/${props.id}/delete?token=${userStore.token}`; + await getData(!isFavorite ? add_url : delete_url); + } + __updateFavorite(); + } + const lists = [ { list: 0, name: "Не смотрю" }, { list: 1, name: "Смотрю" }, @@ -86,8 +97,8 @@ export const ReleaseInfo = (props) => { {releaseInfo.release.title_original} -
- {list >= 0 && ( +
+ {userStore.token && list >= 0 && ( )} + {userStore.token && releaseInfo && ( + + )}