From e985b65252256ed1718e08c0ecde5e3832899e46 Mon Sep 17 00:00:00 2001 From: Kentai Radiquum Date: Thu, 21 Nov 2024 18:33:19 +0500 Subject: [PATCH] feat: add skip to the category page setting for home and bookmark pages --- .../SettingsModal/SettingsModal.tsx | 124 +++++++++++++++++- app/pages/Bookmarks.tsx | 54 +++++--- app/pages/BookmarksCategory.tsx | 10 +- app/pages/Index.tsx | 15 ++- app/store/preferences.ts | 10 ++ 5 files changed, 184 insertions(+), 29 deletions(-) diff --git a/app/components/SettingsModal/SettingsModal.tsx b/app/components/SettingsModal/SettingsModal.tsx index c0d1e88..4509ba6 100644 --- a/app/components/SettingsModal/SettingsModal.tsx +++ b/app/components/SettingsModal/SettingsModal.tsx @@ -1,9 +1,32 @@ "use client"; import { usePreferencesStore } from "#/store/preferences"; -import { Modal, Button, useThemeMode, ToggleSwitch, HR } from "flowbite-react"; +import { + Modal, + Button, + useThemeMode, + ToggleSwitch, + HR, + Dropdown, +} from "flowbite-react"; import Link from "next/link"; +const HomeCategory = { + last: "Последние релизы", + finished: "Завершенные релизы", + ongoing: "Выходит", + announce: "Анонсированные релизы", + films: "Фильмы", +}; + +const BookmarksCategory = { + watching: "Смотрю", + planned: "В планах", + watched: "Просмотрено", + delayed: "Отложено", + abandoned: "Заброшено", +}; + export const SettingsModal = (props: { isOpen: boolean; setIsOpen: any }) => { const preferenceStore = usePreferencesStore(); @@ -58,6 +81,87 @@ export const SettingsModal = (props: { isOpen: boolean; setIsOpen: any }) => { checked={preferenceStore.flags.showChangelog} /> +
+

+ Пропускать страницу выбора категорий на страницах Домашняя и + Закладки +

+ + preferenceStore.setParams({ + skipToCategory: { + ...preferenceStore.params.skipToCategory, + enabled: !preferenceStore.params.skipToCategory.enabled, + }, + }) + } + checked={preferenceStore.params.skipToCategory.enabled} + /> +
+ {preferenceStore.params.skipToCategory.enabled ? ( + <> +
+

+ Категория домашней страницы +

+ + {Object.keys(HomeCategory).map((key) => { + return ( + + preferenceStore.setParams({ + skipToCategory: { + ...preferenceStore.params.skipToCategory, + homeCategory: key, + }, + }) + } + > + {HomeCategory[key]} + + ); + })} + +
+
+

+ Категория страницы закладок +

+ + {Object.keys(BookmarksCategory).map((key) => { + return ( + + preferenceStore.setParams({ + skipToCategory: { + ...preferenceStore.params.skipToCategory, + bookmarksCategory: key, + }, + }) + } + > + {BookmarksCategory[key]} + + ); + })} + +
+ + ) : ( + "" + )}

Отправка аналитики

@@ -87,18 +191,28 @@ export const SettingsModal = (props: { isOpen: boolean; setIsOpen: any }) => {

- +

Телеграм канал

-

@anix_web

+

+ @anix_web +

- +

Разработчик

-

Radiquum

+

+ Radiquum +

diff --git a/app/pages/Bookmarks.tsx b/app/pages/Bookmarks.tsx index 6193cb8..d92bb50 100644 --- a/app/pages/Bookmarks.tsx +++ b/app/pages/Bookmarks.tsx @@ -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" && diff --git a/app/pages/BookmarksCategory.tsx b/app/pages/BookmarksCategory.tsx index bda39cd..91bcf9b 100644 --- a/app/pages/BookmarksCategory.tsx +++ b/app/pages/BookmarksCategory.tsx @@ -144,11 +144,11 @@ export function BookmarksCategoryPage(props: any) {
- - - - - + + + + +
diff --git a/app/pages/Index.tsx b/app/pages/Index.tsx index 0051e38..efd5073 100644 --- a/app/pages/Index.tsx +++ b/app/pages/Index.tsx @@ -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 ( diff --git a/app/store/preferences.ts b/app/store/preferences.ts index 4b952c5..f621a6e 100644 --- a/app/store/preferences.ts +++ b/app/store/preferences.ts @@ -14,6 +14,11 @@ interface preferencesState { params: { isFirstLaunch?: boolean; version?: string; + skipToCategory?: { + enabled: boolean; + homeCategory: string; + bookmarksCategory: string; + } // color: { // primary: string; // secondary: string; @@ -38,6 +43,11 @@ export const usePreferencesStore = create()( params: { isFirstLaunch: true, version: "3.0.0", + skipToCategory: { + enabled: false, + homeCategory: "last", + bookmarksCategory: "watching", + } }, setHasHydrated: (state) => { set({