From c82110b29d281e8ecc96bb23127e7de13abc4c65 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Sat, 3 May 2025 13:59:21 +0200 Subject: [PATCH] Remove "LibraryOptionsContext" These options are saved in the category metadata which made the context unnecessary --- src/modules/core/contexts/AppContext.tsx | 41 +++++++++---------- .../library/components/LibraryToolbarMenu.tsx | 4 +- .../contexts/LibraryOptionsContext.tsx | 20 --------- .../contexts/LibraryOptionsProvider.tsx | 28 ------------- src/modules/library/screens/Library.tsx | 9 +--- 5 files changed, 22 insertions(+), 80 deletions(-) delete mode 100644 src/modules/library/contexts/LibraryOptionsContext.tsx delete mode 100644 src/modules/library/contexts/LibraryOptionsProvider.tsx diff --git a/src/modules/core/contexts/AppContext.tsx b/src/modules/core/contexts/AppContext.tsx index e2fb0c7e..d677ca84 100644 --- a/src/modules/core/contexts/AppContext.tsx +++ b/src/modules/core/contexts/AppContext.tsx @@ -13,7 +13,6 @@ import { QueryParamProvider } from 'use-query-params'; import { ReactRouter6Adapter } from 'use-query-params/adapters/react-router-6'; import { SnackbarProvider } from 'notistack'; import { NavBarContextProvider } from '@/modules/navigation-bar/contexts/NavBarContextProvider.tsx'; -import { LibraryOptionsContextProvider } from '@/modules/library/contexts/LibraryOptionsProvider.tsx'; import { ActiveDeviceContextProvider } from '@/modules/device/contexts/DeviceContext.tsx'; import { ReaderContextProvider } from '@/modules/reader/contexts/ReaderContextProvider.tsx'; import { AppHotkeysProvider } from '@/modules/hotkeys/contexts/AppHotkeysProvider.tsx'; @@ -30,27 +29,25 @@ export const AppContext: React.FC = ({ children }) => ( - - - - - - - {children} - - - - - - + + + + + + {children} + + + + + diff --git a/src/modules/library/components/LibraryToolbarMenu.tsx b/src/modules/library/components/LibraryToolbarMenu.tsx index 73bfe716..a3dc49ea 100644 --- a/src/modules/library/components/LibraryToolbarMenu.tsx +++ b/src/modules/library/components/LibraryToolbarMenu.tsx @@ -12,7 +12,7 @@ import { ComponentProps, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { CustomTooltip } from '@/modules/core/components/CustomTooltip.tsx'; import { LibraryOptionsPanel } from '@/modules/library/components/LibraryOptionsPanel.tsx'; -import { useLibraryOptionsContext } from '@/modules/library/contexts/LibraryOptionsContext.tsx'; +import { getCategoryMetadata } from '@/modules/category/services/CategoryMetadata.ts'; export const LibraryToolbarMenu = ({ category, @@ -22,7 +22,7 @@ export const LibraryToolbarMenu = ({ const { t } = useTranslation(); const [open, setOpen] = useState(false); - const { options } = useLibraryOptionsContext(); + const options = getCategoryMetadata(category); const active = options.hasDownloadedChapters != null || options.hasUnreadChapters != null || diff --git a/src/modules/library/contexts/LibraryOptionsContext.tsx b/src/modules/library/contexts/LibraryOptionsContext.tsx deleted file mode 100644 index f2dbeb9d..00000000 --- a/src/modules/library/contexts/LibraryOptionsContext.tsx +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (C) Contributors to the Suwayomi project - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -import React, { useContext } from 'react'; -import { DEFAULT_CATEGORY_METADATA } from '@/modules/category/services/CategoryMetadata.ts'; -import { LibraryOptionsContextType } from '@/modules/library/Library.types.ts'; - -export const LibraryOptionsContext = React.createContext({ - options: DEFAULT_CATEGORY_METADATA, - setOptions: () => {}, -}); - -export function useLibraryOptionsContext() { - return useContext(LibraryOptionsContext); -} diff --git a/src/modules/library/contexts/LibraryOptionsProvider.tsx b/src/modules/library/contexts/LibraryOptionsProvider.tsx deleted file mode 100644 index 3eaee8d0..00000000 --- a/src/modules/library/contexts/LibraryOptionsProvider.tsx +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) Contributors to the Suwayomi project - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -import React, { useMemo } from 'react'; -import { useLocalStorage } from '@/modules/core/hooks/useStorage.tsx'; -import { LibraryOptionsContext } from '@/modules/library/contexts/LibraryOptionsContext.tsx'; -import { DEFAULT_CATEGORY_METADATA } from '@/modules/category/services/CategoryMetadata.ts'; -import { LibraryOptions } from '@/modules/library/Library.types.ts'; - -interface IProps { - children: React.ReactNode; -} - -export const LibraryOptionsContextProvider: React.FC = ({ children }) => { - const [options, setOptions] = useLocalStorage('libraryOptions', DEFAULT_CATEGORY_METADATA); - - const value = useMemo( - () => ({ options: { ...DEFAULT_CATEGORY_METADATA, ...options }, setOptions }), - [options, setOptions], - ); - - return {children}; -}; diff --git a/src/modules/library/screens/Library.tsx b/src/modules/library/screens/Library.tsx index 96e9ca44..f9c61e5b 100644 --- a/src/modules/library/screens/Library.tsx +++ b/src/modules/library/screens/Library.tsx @@ -9,7 +9,7 @@ import Chip, { ChipProps } from '@mui/material/Chip'; import Tab from '@mui/material/Tab'; import { styled } from '@mui/material/styles'; -import { useCallback, useLayoutEffect, useMemo, useState } from 'react'; +import { useCallback, useMemo, useState } from 'react'; import { useQueryParam, NumberParam } from 'use-query-params'; import { useTranslation } from 'react-i18next'; import { requestManager } from '@/lib/requests/RequestManager.ts'; @@ -39,9 +39,7 @@ import { import { GET_CATEGORIES_LIBRARY } from '@/lib/graphql/queries/CategoryQuery.ts'; import { Mangas } from '@/modules/manga/services/Mangas.ts'; import { MANGA_CHAPTER_STAT_FIELDS } from '@/lib/graphql/fragments/MangaFragments.ts'; -import { useLibraryOptionsContext } from '@/modules/library/contexts/LibraryOptionsContext.tsx'; import { useMetadataServerSettings } from '@/modules/settings/services/ServerSettingsMetadata.ts'; -import { getCategoryMetadata } from '@/modules/category/services/CategoryMetadata.ts'; import { GET_LIBRARY_MANGA_COUNT } from '@/lib/graphql/queries/MangaQuery.ts'; import { useAppTitle } from '@/modules/navigation-bar/hooks/useAppTitle.ts'; import { useAppAction } from '@/modules/navigation-bar/hooks/useAppAction.ts'; @@ -87,13 +85,8 @@ export function Library() { const [tabSearchParam, setTabSearchParam] = useQueryParam('tab', NumberParam); - const { setOptions } = useLibraryOptionsContext(); const activeTab: (typeof tabs)[number] | undefined = tabs.find((tab) => tab.id === tabSearchParam) ?? tabs[0]; - useLayoutEffect(() => { - setOptions(getCategoryMetadata(activeTab ?? { id: -1 })); - }, [activeTab]); - const { data: categoryMangaResponse, error: mangaError,