From ce6722d5848cba963f4a8893d56e25fad31f115f Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Sat, 25 Jan 2025 00:12:56 +0100 Subject: [PATCH] Male library "grid layout" setting global --- src/modules/category/services/CategoryMetadata.ts | 4 ---- src/modules/library/Library.types.ts | 4 +--- src/modules/library/components/LibraryMangaGrid.tsx | 10 ++++++---- src/modules/library/components/LibraryOptionsPanel.tsx | 5 ++--- src/modules/settings/Settings.constants.ts | 2 ++ 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/modules/category/services/CategoryMetadata.ts b/src/modules/category/services/CategoryMetadata.ts index 64ce4b3f..13b7eb2b 100644 --- a/src/modules/category/services/CategoryMetadata.ts +++ b/src/modules/category/services/CategoryMetadata.ts @@ -21,12 +21,8 @@ import { Metadata, MetadataHolder, } from '@/modules/metadata/Metadata.types.ts'; -import { GridLayout } from '@/modules/core/Core.types.ts'; export const DEFAULT_CATEGORY_METADATA: ICategoryMetadata = { - // display options - gridLayout: GridLayout.Compact, - // sort options sortDesc: undefined, sortBy: undefined, diff --git a/src/modules/library/Library.types.ts b/src/modules/library/Library.types.ts index fd569f91..4165ec9e 100644 --- a/src/modules/library/Library.types.ts +++ b/src/modules/library/Library.types.ts @@ -18,6 +18,7 @@ export type MetadataLibrarySettings = { showContinueReadingButton: boolean; showDownloadBadge: boolean; showUnreadBadge: boolean; + gridLayout: GridLayout; }; export type LibrarySortMode = | 'unreadChapters' @@ -29,9 +30,6 @@ export type LibrarySortMode = | 'latestUploadedChapter'; export interface LibraryOptions { - // display options - gridLayout: GridLayout; - // sort options sortBy: NullAndUndefined; sortDesc: NullAndUndefined; diff --git a/src/modules/library/components/LibraryMangaGrid.tsx b/src/modules/library/components/LibraryMangaGrid.tsx index ed99805d..28c190b7 100644 --- a/src/modules/library/components/LibraryMangaGrid.tsx +++ b/src/modules/library/components/LibraryMangaGrid.tsx @@ -8,9 +8,9 @@ import React, { useLayoutEffect } from 'react'; import { useTranslation } from 'react-i18next'; -import { useLibraryOptionsContext } from '@/modules/library/contexts/LibraryOptionsContext.tsx'; import { IMangaGridProps, MangaGrid } from '@/modules/manga/components/MangaGrid.tsx'; import { GridLayout } from '@/modules/core/Core.types.ts'; +import { useMetadataServerSettings } from '@/modules/settings/services/ServerSettingsMetadata.ts'; interface LibraryMangaGridProps extends Required>, @@ -29,10 +29,12 @@ export const LibraryMangaGrid: React.FC = ({ }) => { const { t } = useTranslation(); - const { options } = useLibraryOptionsContext(); + const { + settings: { gridLayout }, + } = useMetadataServerSettings(); useLayoutEffect(() => { - document.body.style.overflowY = options.gridLayout === GridLayout.List ? 'auto' : 'scroll'; + document.body.style.overflowY = gridLayout === GridLayout.List ? 'auto' : 'scroll'; return () => { document.body.style.overflowY = 'auto'; }; @@ -46,7 +48,7 @@ export const LibraryMangaGrid: React.FC = ({ loadMore={loadMoreNoop} message={showFilteredOutMessage ? t('library.error.label.no_matches') : message} messageExtra={showFilteredOutMessage ? undefined : messageExtra} - gridLayout={options.gridLayout} + gridLayout={gridLayout} /> ); }; diff --git a/src/modules/library/components/LibraryOptionsPanel.tsx b/src/modules/library/components/LibraryOptionsPanel.tsx index f8ee03bf..767dff49 100644 --- a/src/modules/library/components/LibraryOptionsPanel.tsx +++ b/src/modules/library/components/LibraryOptionsPanel.tsx @@ -68,7 +68,7 @@ export const LibraryOptionsPanel = ({ ); const { - settings: { showTabSize, showContinueReadingButton, showDownloadBadge, showUnreadBadge }, + settings: { showTabSize, showContinueReadingButton, showDownloadBadge, showUnreadBadge, gridLayout }, } = useMetadataServerSettings(); const setSettingValue = createUpdateMetadataServerSettings((e) => makeToast(t('search.error.label.failed_to_save_settings'), 'error', getErrorMessage(e)), @@ -156,12 +156,11 @@ export const LibraryOptionsPanel = ({ )); } if (key === 'display') { - const { gridLayout } = categoryLibraryOptions; return ( <> {t('global.grid_layout.title')} updateCategoryLibraryOptions('gridLayout', Number(e.target.value))} + onChange={(e) => updateMetadataServerSettings('gridLayout', Number(e.target.value))} value={gridLayout} >