From 4fc4a8d9b3e0e7ff599439bd1e7b509dc5558e44 Mon Sep 17 00:00:00 2001
From: schroda <50052685+schroda@users.noreply.github.com>
Date: Mon, 30 Dec 2024 03:49:39 +0100
Subject: [PATCH] Move library display options to global metadata
- showContinueReadingButton
- showDownloadBadge
- showUnreadBadge
---
src/modules/category/services/CategoryMetadata.ts | 3 ---
src/modules/library/Library.types.ts | 6 +++---
.../library/components/LibraryOptionsPanel.tsx | 14 +++++++-------
src/modules/manga/components/MangaBadges.tsx | 6 +++---
src/modules/manga/components/cards/MangaCard.tsx | 6 +++---
src/modules/settings/Settings.constants.ts | 3 +++
6 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/src/modules/category/services/CategoryMetadata.ts b/src/modules/category/services/CategoryMetadata.ts
index 94861324..ea49f04e 100644
--- a/src/modules/category/services/CategoryMetadata.ts
+++ b/src/modules/category/services/CategoryMetadata.ts
@@ -25,9 +25,6 @@ import { GridLayout } from '@/modules/core/Core.types.ts';
export const DEFAULT_CATEGORY_METADATA: ICategoryMetadata = {
// display options
- showContinueReadingButton: false,
- showDownloadBadge: false,
- showUnreadBadge: false,
gridLayout: GridLayout.Compact,
// sort options
diff --git a/src/modules/library/Library.types.ts b/src/modules/library/Library.types.ts
index 8159f2e6..fd569f91 100644
--- a/src/modules/library/Library.types.ts
+++ b/src/modules/library/Library.types.ts
@@ -15,6 +15,9 @@ export type MetadataLibrarySettings = {
ignoreFilters: boolean;
removeMangaFromCategories: boolean;
showTabSize: boolean;
+ showContinueReadingButton: boolean;
+ showDownloadBadge: boolean;
+ showUnreadBadge: boolean;
};
export type LibrarySortMode =
| 'unreadChapters'
@@ -27,9 +30,6 @@ export type LibrarySortMode =
export interface LibraryOptions {
// display options
- showContinueReadingButton: boolean;
- showDownloadBadge: boolean;
- showUnreadBadge: boolean;
gridLayout: GridLayout;
// sort options
diff --git a/src/modules/library/components/LibraryOptionsPanel.tsx b/src/modules/library/components/LibraryOptionsPanel.tsx
index 86f57012..f8ee03bf 100644
--- a/src/modules/library/components/LibraryOptionsPanel.tsx
+++ b/src/modules/library/components/LibraryOptionsPanel.tsx
@@ -22,6 +22,7 @@ import { createUpdateCategoryMetadata, useGetCategoryMetadata } from '@/modules/
import { makeToast } from '@/modules/core/utils/Toast.ts';
import {
createUpdateMetadataServerSettings,
+ updateMetadataServerSettings,
useMetadataServerSettings,
} from '@/modules/settings/services/ServerSettingsMetadata.ts';
import { TranslationKey } from '@/Base.types.ts';
@@ -67,9 +68,9 @@ export const LibraryOptionsPanel = ({
);
const {
- settings: { showTabSize },
+ settings: { showTabSize, showContinueReadingButton, showDownloadBadge, showUnreadBadge },
} = useMetadataServerSettings();
- const setSettingValue = createUpdateMetadataServerSettings<'showTabSize'>((e) =>
+ const setSettingValue = createUpdateMetadataServerSettings((e) =>
makeToast(t('search.error.label.failed_to_save_settings'), 'error', getErrorMessage(e)),
);
@@ -155,8 +156,7 @@ export const LibraryOptionsPanel = ({
));
}
if (key === 'display') {
- const { gridLayout, showContinueReadingButton, showDownloadBadge, showUnreadBadge } =
- categoryLibraryOptions;
+ const { gridLayout } = categoryLibraryOptions;
return (
<>
{t('global.grid_layout.title')}
@@ -185,12 +185,12 @@ export const LibraryOptionsPanel = ({
updateCategoryLibraryOptions('showUnreadBadge', !showUnreadBadge)}
+ onChange={() => updateMetadataServerSettings('showUnreadBadge', !showUnreadBadge)}
/>
updateCategoryLibraryOptions('showDownloadBadge', !showDownloadBadge)}
+ onChange={() => updateMetadataServerSettings('showDownloadBadge', !showDownloadBadge)}
/>
{t('library.option.display.tab.title')}
@@ -205,7 +205,7 @@ export const LibraryOptionsPanel = ({
label={t('library.option.display.other.label.show_continue_reading_button')}
checked={showContinueReadingButton}
onChange={() =>
- updateCategoryLibraryOptions(
+ updateMetadataServerSettings(
'showContinueReadingButton',
!showContinueReadingButton,
)
diff --git a/src/modules/manga/components/MangaBadges.tsx b/src/modules/manga/components/MangaBadges.tsx
index 0ec96579..8b06b015 100644
--- a/src/modules/manga/components/MangaBadges.tsx
+++ b/src/modules/manga/components/MangaBadges.tsx
@@ -12,7 +12,7 @@ import Button from '@mui/material/Button';
import Typography from '@mui/material/Typography';
import { MangaCardMode } from '@/modules/manga/Manga.types.ts';
import { MediaQuery } from '@/modules/core/utils/MediaQuery.tsx';
-import { useLibraryOptionsContext } from '@/modules/library/contexts/LibraryOptionsContext.tsx';
+import { useMetadataServerSettings } from '@/modules/settings/services/ServerSettingsMetadata.ts';
const BadgeContainer = styled('div')(({ theme }) => ({
display: 'flex',
@@ -46,8 +46,8 @@ export const MangaBadges = ({
const isTouchDevice = MediaQuery.useIsTouchDevice();
const {
- options: { showUnreadBadge, showDownloadBadge },
- } = useLibraryOptionsContext();
+ settings: { showUnreadBadge, showDownloadBadge },
+ } = useMetadataServerSettings();
return (
diff --git a/src/modules/manga/components/cards/MangaCard.tsx b/src/modules/manga/components/cards/MangaCard.tsx
index 281885a8..bec88d9b 100644
--- a/src/modules/manga/components/cards/MangaCard.tsx
+++ b/src/modules/manga/components/cards/MangaCard.tsx
@@ -9,7 +9,6 @@
import PopupState, { bindMenu } from 'material-ui-popup-state';
import { useMemo, useState } from 'react';
import { useLongPress } from 'use-long-press';
-import { useLibraryOptionsContext } from '@/modules/library/contexts/LibraryOptionsContext.tsx';
import { MangaActionMenuItems, SingleModeProps } from '@/modules/manga/components/MangaActionMenuItems.tsx';
import { Menu } from '@/modules/core/components/menu/Menu.tsx';
import { MigrateDialog } from '@/modules/migration/components/MigrateDialog.tsx';
@@ -21,6 +20,7 @@ import { ContinueReadingButton } from '@/modules/manga/components/ContinueReadin
import { MangaBadges } from '@/modules/manga/components/MangaBadges.tsx';
import { GridLayout } from '@/modules/core/Core.types.ts';
import { AppRoutes } from '@/modules/core/AppRoute.constants.ts';
+import { useMetadataServerSettings } from '@/modules/settings/services/ServerSettingsMetadata.ts';
const getMangaLinkTo = (
mode: MangaCardMode,
@@ -46,8 +46,8 @@ export const MangaCard = (props: MangaCardProps) => {
const { manga, gridLayout, inLibraryIndicator, selected, handleSelection, mode = 'default' } = props;
const { id, firstUnreadChapter, downloadCount, unreadCount } = manga;
const {
- options: { showContinueReadingButton },
- } = useLibraryOptionsContext();
+ settings: { showContinueReadingButton },
+ } = useMetadataServerSettings();
const { CategorySelectComponent, updateLibraryState, isInLibrary } = useManageMangaLibraryState(
manga,
diff --git a/src/modules/settings/Settings.constants.ts b/src/modules/settings/Settings.constants.ts
index 3c601c6c..b8052311 100644
--- a/src/modules/settings/Settings.constants.ts
+++ b/src/modules/settings/Settings.constants.ts
@@ -22,6 +22,9 @@ export const SERVER_SETTINGS_METADATA_DEFAULT: MetadataServerSettings = {
ignoreFilters: false,
removeMangaFromCategories: false,
showTabSize: false,
+ showContinueReadingButton: false,
+ showDownloadBadge: false,
+ showUnreadBadge: false,
// client
devices: [DEFAULT_DEVICE],