feat: add button to show collections containing the release on release page

feat: add release in list widget to release page
fix: redirecting if viewing not favorites collection for unauthorized user
This commit is contained in:
Kentai Radiquum 2024-08-18 14:40:59 +05:00
parent 723b620749
commit 501d3a1705
Signed by: Radiquum
GPG key ID: 858E8EE696525EED
5 changed files with 117 additions and 61 deletions

View file

@ -35,15 +35,22 @@ export function CollectionsFullPage(props: {
const getKey = (pageIndex: number, previousPageData: any) => {
if (previousPageData && !previousPageData.content.length) return null;
if (userStore.token) {
if (props.type == "favorites") {
return `${ENDPOINTS.collection.favoriteCollections}/all/${pageIndex}?token=${userStore.token}`;
} else if (props.type == "profile") {
return `${ENDPOINTS.collection.userCollections}/${props.profile_id}/${pageIndex}?token=${userStore.token}`;
} else if (props.type == "release") {
return `${ENDPOINTS.collection.releaseInCollections}/${props.release_id}/${pageIndex}?token=${userStore.token}`;
}
let url;
if (props.type == "favorites") {
url = `${ENDPOINTS.collection.favoriteCollections}/all/${pageIndex}`;
} else if (props.type == "profile") {
url = `${ENDPOINTS.collection.userCollections}/${props.profile_id}/${pageIndex}`;
} else if (props.type == "release") {
url = `${ENDPOINTS.collection.releaseInCollections}/${props.release_id}/${pageIndex}`;
}
if (userStore.token) {
url += `?token=${userStore.token}`;
}
return url;
};
const { data, error, isLoading, size, setSize } = useSWRInfinite(
@ -72,7 +79,11 @@ export function CollectionsFullPage(props: {
}, [scrollPosition]);
useEffect(() => {
if (userStore.state === "finished" && !userStore.token) {
if (
userStore.state === "finished" &&
!userStore.token &&
props.type == "favorites"
) {
router.push(`/login?redirect=/collections/favorites`);
}
}, [userStore.state, userStore.token]);