feat(frontend/release): add a favorite button to release page

This commit is contained in:
Kentai Radiquum 2024-05-01 12:41:42 +05:00
parent 403e314ab3
commit cffb96b837
Signed by: Radiquum
GPG key ID: 858E8EE696525EED

View file

@ -10,6 +10,7 @@ export const ReleaseInfo = (props) => {
const userStore = useUserStore(); const userStore = useUserStore();
const [releaseInfo, setReleaseInfo] = useState(); const [releaseInfo, setReleaseInfo] = useState();
const [list, setList] = useState(); const [list, setList] = useState();
const [isFavorite, setIsFavorite] = useState(false);
const [timer, seTimer] = useState(); const [timer, seTimer] = useState();
useEffect(() => { useEffect(() => {
@ -24,6 +25,7 @@ export const ReleaseInfo = (props) => {
setReleaseInfo(release); setReleaseInfo(release);
if (userStore.token) { if (userStore.token) {
setList(release.release.profile_list_status || 0); setList(release.release.profile_list_status || 0);
setIsFavorite(release.release.is_favorite);
} }
} }
@ -59,6 +61,15 @@ export const ReleaseInfo = (props) => {
} }
}, [userStore.token, list]); }, [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 = [ const lists = [
{ list: 0, name: "Не смотрю" }, { list: 0, name: "Не смотрю" },
{ list: 1, name: "Смотрю" }, { list: 1, name: "Смотрю" },
@ -86,8 +97,8 @@ export const ReleaseInfo = (props) => {
{releaseInfo.release.title_original} {releaseInfo.release.title_original}
</h6> </h6>
</div> </div>
<div className="s3 right-align"> <div className="s3 row right-align">
{list >= 0 && ( {userStore.token && list >= 0 && (
<button className="responsive"> <button className="responsive">
<span>{lists[list].name}</span> <span>{lists[list].name}</span>
<i>arrow_drop_down</i> <i>arrow_drop_down</i>
@ -107,6 +118,17 @@ export const ReleaseInfo = (props) => {
</menu> </menu>
</button> </button>
)} )}
{userStore.token && releaseInfo && (
<button
className="circle"
onClick={() => {
setIsFavorite(!isFavorite);
_setFav();
}}
>
<i className={isFavorite ? "fill" : ""}>favorite</i>
</button>
)}
</div> </div>
</div> </div>
<p className="small no-margin"> <p className="small no-margin">