feat: add skip to the category page setting for home and bookmark pages

This commit is contained in:
Kentai Radiquum 2024-11-21 18:33:19 +05:00
parent 487ae9a1e4
commit e985b65252
Signed by: Radiquum
GPG key ID: 858E8EE696525EED
5 changed files with 184 additions and 29 deletions

View file

@ -5,6 +5,7 @@ import { Spinner } from "#/components/Spinner/Spinner";
const fetcher = (...args: any) =>
fetch([...args] as any).then((res) => res.json());
import { useUserStore } from "#/store/auth";
import { usePreferencesStore } from "#/store/preferences";
import { BookmarksList } from "#/api/utils";
import { ENDPOINTS } from "#/api/config";
import { useRouter } from "next/navigation";
@ -14,31 +15,42 @@ export function BookmarksPage(props: { profile_id?: number }) {
const token = useUserStore((state) => state.token);
const authState = useUserStore((state) => state.state);
const router = useRouter();
const preferenceStore = usePreferencesStore();
useEffect(() => {
if (preferenceStore.params.skipToCategory.enabled) {
if (props.profile_id) {
router.push(
`/profile/${props.profile_id}/bookmarks/${preferenceStore.params.skipToCategory.bookmarksCategory}`
);
} else {
router.push(
`/bookmarks/${preferenceStore.params.skipToCategory.bookmarksCategory}`
);
}
}
}, []);
function useFetchReleases(listName: string) {
let url: string;
if (!preferenceStore.params.skipToCategory.enabled) {
if (props.profile_id) {
url = `${ENDPOINTS.user.bookmark}/all/${props.profile_id}/${BookmarksList[listName]}/0?sort=1`;
if (token) {
url += `&token=${token}`;
}
} else {
if (token) {
url = `${ENDPOINTS.user.bookmark}/all/${BookmarksList[listName]}/0?sort=1&token=${token}`;
}
}
if (props.profile_id) {
url = `${ENDPOINTS.user.bookmark}/all/${props.profile_id}/${BookmarksList[listName]}/0?sort=1`;
if (token) {
url += `&token=${token}`;
}
} else {
if (token) {
url = `${ENDPOINTS.user.bookmark}/all/${BookmarksList[listName]}/0?sort=1&token=${token}`;
}
const { data } = useSWR(url, fetcher);
return [data];
}
const { data } = useSWR(url, fetcher);
return [data];
return [null];
}
const [watchingData] = useFetchReleases("watching");
const [plannedData] = useFetchReleases("planned");
const [watchedData] = useFetchReleases("watched");
const [delayedData] = useFetchReleases("delayed");
const [abandonedData] = useFetchReleases("abandoned");
useEffect(() => {
if (authState === "finished" && !token && !props.profile_id) {
router.push("/login?redirect=/bookmarks");
@ -46,6 +58,12 @@ export function BookmarksPage(props: { profile_id?: number }) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [authState, token]);
const [watchingData] = useFetchReleases("watching");
const [plannedData] = useFetchReleases("planned");
const [watchedData] = useFetchReleases("watched");
const [delayedData] = useFetchReleases("delayed");
const [abandonedData] = useFetchReleases("abandoned");
return (
<>
{authState === "loading" &&

View file

@ -144,11 +144,11 @@ export function BookmarksCategoryPage(props: any) {
</form>
<div className="m-4 overflow-auto">
<Button.Group>
<Button className="whitespace-nowrap" disabled={props.slug == "watching"} color="light" onClick={() => router.push("/bookmarks/watching")}>{props.SectionTitleMapping["watching"]}</Button>
<Button className="whitespace-nowrap" disabled={props.slug == "planned"} color="light" onClick={() => router.push("/bookmarks/planned")}>{props.SectionTitleMapping["planned"]}</Button>
<Button className="whitespace-nowrap" disabled={props.slug == "watched"} color="light" onClick={() => router.push("/bookmarks/watched")}>{props.SectionTitleMapping["watched"]}</Button>
<Button className="whitespace-nowrap" disabled={props.slug == "delayed"} color="light" onClick={() => router.push("/bookmarks/delayed")}>{props.SectionTitleMapping["delayed"]}</Button>
<Button className="whitespace-nowrap" disabled={props.slug == "abandoned"} color="light" onClick={() => router.push("/bookmarks/abandoned")}>{props.SectionTitleMapping["abandoned"]}</Button>
<Button className="whitespace-nowrap" disabled={props.slug == "watching"} color="light" onClick={() => router.push(props.profile_id ? `/profile/${props.profile_id}/bookmarks/watching` : "/bookmarks/watching")}>{props.SectionTitleMapping["watching"]}</Button>
<Button className="whitespace-nowrap" disabled={props.slug == "planned"} color="light" onClick={() => router.push(props.profile_id ? `/profile/${props.profile_id}/bookmarks/planned` : "/bookmarks/planned")}>{props.SectionTitleMapping["planned"]}</Button>
<Button className="whitespace-nowrap" disabled={props.slug == "watched"} color="light" onClick={() => router.push(props.profile_id ? `/profile/${props.profile_id}/bookmarks/watched` : "/bookmarks/watched")}>{props.SectionTitleMapping["watched"]}</Button>
<Button className="whitespace-nowrap" disabled={props.slug == "delayed"} color="light" onClick={() => router.push(props.profile_id ? `/profile/${props.profile_id}/bookmarks/delayed` : "/bookmarks/delayed")}>{props.SectionTitleMapping["delayed"]}</Button>
<Button className="whitespace-nowrap" disabled={props.slug == "abandoned"} color="light" onClick={() => router.push(props.profile_id ? `/profile/${props.profile_id}/bookmarks/abandoned` : "/bookmarks/abandoned")}>{props.SectionTitleMapping["abandoned"]}</Button>
</Button.Group>
</div>
<div className="flex items-center justify-between px-4 py-2 border-b-2 border-black dark:border-white">

View file

@ -5,8 +5,13 @@ import { useUserStore } from "#/store/auth";
import { useState, useEffect } from "react";
import { _FetchHomePageReleases } from "#/api/utils";
import { usePreferencesStore } from "#/store/preferences";
import { useRouter } from "next/navigation";
export function IndexPage() {
const token = useUserStore((state) => state.token);
const preferenceStore = usePreferencesStore();
const router = useRouter()
const [isLoading, setIsLoading] = useState(true);
const [lastReleasesData, setLastReleasesData] = useState(null);
const [ongoingReleasesData, setOngoingReleasesData] = useState(null);
@ -14,6 +19,12 @@ export function IndexPage() {
const [announceReleasesData, setAnnounceReleasesData] = useState(null);
const [filmsReleasesData, setFilmsReleasesData] = useState(null);
useEffect(() => {
if (preferenceStore.params.skipToCategory.enabled) {
router.push(`/home/${preferenceStore.params.skipToCategory.homeCategory}`);
}
}, []);
useEffect(() => {
async function _loadReleases() {
setIsLoading(true);
@ -36,7 +47,9 @@ export function IndexPage() {
setFilmsReleasesData(filmsReleases);
setIsLoading(false);
}
_loadReleases();
if (!preferenceStore.params.skipToCategory.enabled) {
_loadReleases();
}
}, [token]);
return (