2022-11-24 09:41:03 +01:00
|
|
|
/*
|
|
|
|
|
* 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
|
2023-05-18 13:17:41 +02:00
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
2022-11-24 09:41:03 +01:00
|
|
|
|
2026-03-11 00:11:29 +01:00
|
|
|
import type { MessageDescriptor } from '@lingui/core';
|
2024-04-14 15:50:12 +02:00
|
|
|
import FormLabel from '@mui/material/FormLabel';
|
|
|
|
|
import RadioGroup from '@mui/material/RadioGroup';
|
2026-01-10 19:45:02 +01:00
|
|
|
import { useLingui } from '@lingui/react/macro';
|
|
|
|
|
import { msg } from '@lingui/core/macro';
|
2026-07-21 00:51:14 +02:00
|
|
|
import type { ReactNode } from 'react';
|
2026-07-20 15:09:06 -07:00
|
|
|
import { useMemo } from 'react';
|
|
|
|
|
import uniqBy from 'lodash/fp/uniqBy';
|
2025-08-16 02:48:46 +02:00
|
|
|
import { CheckboxInput } from '@/base/components/inputs/CheckboxInput.tsx';
|
|
|
|
|
import { RadioInput } from '@/base/components/inputs/RadioInput.tsx';
|
2026-07-20 19:01:28 -04:00
|
|
|
import { SortRadioInput, SortRadioInputRandom } from '@/base/components/inputs/SortRadioInput.tsx';
|
2025-08-16 02:48:46 +02:00
|
|
|
import { ThreeStateCheckboxInput } from '@/base/components/inputs/ThreeStateCheckboxInput.tsx';
|
|
|
|
|
import { OptionsTabs } from '@/base/components/modals/OptionsTabs.tsx';
|
2024-10-06 01:27:51 +02:00
|
|
|
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
2025-08-15 22:02:58 +02:00
|
|
|
import { Trackers } from '@/features/tracker/services/Trackers.ts';
|
2026-03-11 00:11:29 +01:00
|
|
|
import type { GetTrackersSettingsQuery } from '@/lib/graphql/generated/graphql.ts';
|
2026-05-15 20:40:31 +02:00
|
|
|
import { MangaStatus } from '@/lib/graphql/generated/graphql-base.types.ts';
|
2025-12-22 14:00:44 +01:00
|
|
|
import { GET_TRACKERS_SETTINGS } from '@/lib/graphql/tracker/TrackerQuery.ts';
|
2026-03-20 03:29:45 +01:00
|
|
|
import { STABLE_EMPTY_ARRAY } from '@/base/Base.constants.ts';
|
2025-08-15 22:02:58 +02:00
|
|
|
import { createUpdateCategoryMetadata, useGetCategoryMetadata } from '@/features/category/services/CategoryMetadata.ts';
|
2025-08-16 02:48:46 +02:00
|
|
|
import { makeToast } from '@/base/utils/Toast.ts';
|
2024-09-17 03:40:55 +02:00
|
|
|
import {
|
|
|
|
|
createUpdateMetadataServerSettings,
|
2024-12-30 03:49:39 +01:00
|
|
|
updateMetadataServerSettings,
|
2024-09-17 03:40:55 +02:00
|
|
|
useMetadataServerSettings,
|
2025-08-15 22:02:58 +02:00
|
|
|
} from '@/features/settings/services/ServerSettingsMetadata.ts';
|
2026-03-11 00:11:29 +01:00
|
|
|
import type { LibrarySortMode } from '@/features/library/Library.types.ts';
|
|
|
|
|
import type { CategoryMetadataInfo } from '@/features/category/Category.types.ts';
|
2025-08-15 22:02:58 +02:00
|
|
|
import { MANGA_STATUS_TO_TRANSLATION } from '@/features/manga/Manga.constants.ts';
|
2026-01-10 19:45:02 +01:00
|
|
|
import { GridLayout } from '@/base/Base.types';
|
2024-12-20 17:24:40 +01:00
|
|
|
import { getErrorMessage } from '@/lib/HelperFunctions.ts';
|
2026-07-21 00:51:14 +02:00
|
|
|
import { Collapsable } from '@/base/components/Collapsable.tsx';
|
2022-11-24 09:41:03 +01:00
|
|
|
|
2026-01-10 19:45:02 +01:00
|
|
|
const TITLES: { [key in 'filter' | 'sort' | 'display']: MessageDescriptor } = {
|
|
|
|
|
filter: msg`Filter`,
|
|
|
|
|
sort: msg`Sort`,
|
|
|
|
|
display: msg`Display`,
|
2022-11-24 09:41:03 +01:00
|
|
|
};
|
|
|
|
|
|
2026-01-10 19:45:02 +01:00
|
|
|
const SORT_OPTIONS: [LibrarySortMode, MessageDescriptor][] = [
|
|
|
|
|
['unreadChapters', msg`Unread chapters`],
|
|
|
|
|
['totalChapters', msg`Total chapters`],
|
|
|
|
|
['alphabetically', msg`A-Z`],
|
|
|
|
|
['dateAdded', msg`Recently added`],
|
|
|
|
|
['lastRead', msg`Recently read`],
|
|
|
|
|
['latestFetchedChapter', msg`Latest fetched chapter`],
|
|
|
|
|
['latestUploadedChapter', msg`Latest uploaded chapter`],
|
2026-07-20 19:01:28 -04:00
|
|
|
['random', msg`Random`],
|
2022-11-24 09:41:03 +01:00
|
|
|
];
|
|
|
|
|
|
2026-07-21 00:51:14 +02:00
|
|
|
const CollapsableFilter = ({ title, items, isActive }: { title: string; items: ReactNode[]; isActive: boolean }) => (
|
|
|
|
|
<Collapsable
|
|
|
|
|
header={title}
|
|
|
|
|
collapse={items}
|
|
|
|
|
initialState={isActive}
|
|
|
|
|
slots={{
|
|
|
|
|
headerWrapper: {
|
|
|
|
|
component: FormLabel,
|
|
|
|
|
sx: {
|
|
|
|
|
mt: 2,
|
|
|
|
|
color: isActive ? 'warning.main' : undefined,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
2024-09-17 03:40:55 +02:00
|
|
|
export const LibraryOptionsPanel = ({
|
|
|
|
|
category,
|
|
|
|
|
open,
|
|
|
|
|
onClose,
|
|
|
|
|
}: {
|
|
|
|
|
category: CategoryMetadataInfo;
|
2023-02-06 10:06:33 +01:00
|
|
|
open: boolean;
|
|
|
|
|
onClose: () => void;
|
2024-09-17 03:40:55 +02:00
|
|
|
}) => {
|
2026-01-10 19:45:02 +01:00
|
|
|
const { t } = useLingui();
|
2022-11-24 09:41:03 +01:00
|
|
|
|
2024-07-04 22:00:39 +02:00
|
|
|
const trackerList = requestManager.useGetTrackerList<GetTrackersSettingsQuery>(GET_TRACKERS_SETTINGS);
|
2026-03-20 03:29:45 +01:00
|
|
|
const loggedInTrackers = Trackers.getLoggedIn(trackerList.data?.trackers.nodes ?? STABLE_EMPTY_ARRAY);
|
2024-03-28 20:00:46 +01:00
|
|
|
|
2026-07-20 15:09:06 -07:00
|
|
|
const migratableSourcesResult = requestManager.useGetMigratableSources();
|
|
|
|
|
const librarySources = useMemo(() => {
|
|
|
|
|
const sources = migratableSourcesResult.data?.mangas.nodes
|
|
|
|
|
.map(({ source }) => source)
|
|
|
|
|
.filter((source) => source != null);
|
|
|
|
|
const uniqueSources = uniqBy('id', sources);
|
|
|
|
|
|
|
|
|
|
return uniqueSources.toSorted((a, b) => a.displayName.localeCompare(b.displayName));
|
|
|
|
|
}, [migratableSourcesResult.data?.mangas.nodes]);
|
|
|
|
|
|
2024-10-26 17:25:04 +02:00
|
|
|
const categoryLibraryOptions = useGetCategoryMetadata(category);
|
2024-12-20 17:24:40 +01:00
|
|
|
const updateCategoryLibraryOptions = createUpdateCategoryMetadata(category, (e) =>
|
2026-01-10 19:45:02 +01:00
|
|
|
makeToast(t`Failed to save changes`, 'error', getErrorMessage(e)),
|
2024-09-17 03:40:55 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const {
|
2025-01-25 00:12:56 +01:00
|
|
|
settings: { showTabSize, showContinueReadingButton, showDownloadBadge, showUnreadBadge, gridLayout },
|
2024-09-17 03:40:55 +02:00
|
|
|
} = useMetadataServerSettings();
|
2024-12-30 03:49:39 +01:00
|
|
|
const setSettingValue = createUpdateMetadataServerSettings((e) =>
|
2026-01-10 19:45:02 +01:00
|
|
|
makeToast(t`Could not save the default search settings to the server`, 'error', getErrorMessage(e)),
|
2024-09-17 03:40:55 +02:00
|
|
|
);
|
2022-11-24 09:41:03 +01:00
|
|
|
|
2026-07-21 00:51:14 +02:00
|
|
|
const isStatusFilterActive = Object.values(MangaStatus).some(
|
|
|
|
|
(status) => categoryLibraryOptions.hasStatus[status] != null,
|
|
|
|
|
);
|
|
|
|
|
const isTrackerFilterActive = loggedInTrackers.some(
|
|
|
|
|
(tracker) => categoryLibraryOptions.hasTrackerBinding[tracker.id] != null,
|
|
|
|
|
);
|
|
|
|
|
const isSourceFilterActive = librarySources.some((source) => categoryLibraryOptions.hasSource[source.id] != null);
|
|
|
|
|
|
2022-11-24 09:41:03 +01:00
|
|
|
return (
|
|
|
|
|
<OptionsTabs<'filter' | 'sort' | 'display'>
|
|
|
|
|
open={open}
|
|
|
|
|
onClose={onClose}
|
|
|
|
|
tabs={['filter', 'sort', 'display']}
|
2023-07-04 21:53:25 +02:00
|
|
|
tabTitle={(key) => t(TITLES[key])}
|
2022-11-24 09:41:03 +01:00
|
|
|
tabContent={(key) => {
|
|
|
|
|
if (key === 'filter') {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2023-02-06 10:06:33 +01:00
|
|
|
<ThreeStateCheckboxInput
|
2026-01-10 19:45:02 +01:00
|
|
|
label={t`Unread`}
|
2024-09-17 03:40:55 +02:00
|
|
|
checked={categoryLibraryOptions.hasUnreadChapters}
|
|
|
|
|
onChange={(c) => updateCategoryLibraryOptions('hasUnreadChapters', c)}
|
2023-02-06 10:06:33 +01:00
|
|
|
/>
|
2024-12-27 03:32:30 +01:00
|
|
|
<ThreeStateCheckboxInput
|
2026-01-10 19:45:02 +01:00
|
|
|
label={t`Started`}
|
2024-12-27 03:32:30 +01:00
|
|
|
checked={categoryLibraryOptions.hasReadChapters}
|
|
|
|
|
onChange={(c) => updateCategoryLibraryOptions('hasReadChapters', c)}
|
|
|
|
|
/>
|
2023-02-06 10:06:33 +01:00
|
|
|
<ThreeStateCheckboxInput
|
2026-01-10 19:45:02 +01:00
|
|
|
label={t`Downloaded`}
|
2024-09-17 03:40:55 +02:00
|
|
|
checked={categoryLibraryOptions.hasDownloadedChapters}
|
|
|
|
|
onChange={(c) => updateCategoryLibraryOptions('hasDownloadedChapters', c)}
|
2023-02-06 10:06:33 +01:00
|
|
|
/>
|
2024-04-01 01:12:26 +02:00
|
|
|
<ThreeStateCheckboxInput
|
2026-01-10 19:45:02 +01:00
|
|
|
label={t`Bookmarked`}
|
2024-09-17 03:40:55 +02:00
|
|
|
checked={categoryLibraryOptions.hasBookmarkedChapters}
|
|
|
|
|
onChange={(c) => updateCategoryLibraryOptions('hasBookmarkedChapters', c)}
|
2024-04-01 01:12:26 +02:00
|
|
|
/>
|
2024-07-28 23:14:42 +02:00
|
|
|
<ThreeStateCheckboxInput
|
2026-01-10 19:45:02 +01:00
|
|
|
label={t`Duplicate chapters`}
|
2024-09-17 03:40:55 +02:00
|
|
|
checked={categoryLibraryOptions.hasDuplicateChapters}
|
|
|
|
|
onChange={(c) => updateCategoryLibraryOptions('hasDuplicateChapters', c)}
|
2024-07-28 23:14:42 +02:00
|
|
|
/>
|
2026-07-21 00:51:14 +02:00
|
|
|
<CollapsableFilter
|
|
|
|
|
title={t`Status`}
|
|
|
|
|
items={Object.values(MangaStatus).map((status) => (
|
|
|
|
|
<ThreeStateCheckboxInput
|
|
|
|
|
key={status}
|
|
|
|
|
label={t(MANGA_STATUS_TO_TRANSLATION[status])}
|
|
|
|
|
checked={categoryLibraryOptions.hasStatus[status]}
|
|
|
|
|
onChange={(checked) =>
|
|
|
|
|
updateCategoryLibraryOptions('hasStatus', {
|
|
|
|
|
...categoryLibraryOptions.hasStatus,
|
|
|
|
|
[status]: checked,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
isActive={isStatusFilterActive}
|
|
|
|
|
/>
|
|
|
|
|
{!!loggedInTrackers.length && (
|
|
|
|
|
<CollapsableFilter
|
|
|
|
|
title={t`Tracked`}
|
|
|
|
|
items={loggedInTrackers.map((tracker) => (
|
|
|
|
|
<ThreeStateCheckboxInput
|
|
|
|
|
key={tracker.id}
|
|
|
|
|
label={tracker.name}
|
|
|
|
|
checked={categoryLibraryOptions.hasTrackerBinding[tracker.id]}
|
|
|
|
|
onChange={(checked) =>
|
|
|
|
|
updateCategoryLibraryOptions('hasTrackerBinding', {
|
|
|
|
|
...categoryLibraryOptions.hasTrackerBinding,
|
|
|
|
|
[tracker.id]: checked,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
isActive={isTrackerFilterActive}
|
2024-03-28 20:00:46 +01:00
|
|
|
/>
|
2026-07-21 00:51:14 +02:00
|
|
|
)}
|
|
|
|
|
{!!librarySources.length && (
|
|
|
|
|
<CollapsableFilter
|
|
|
|
|
title={t`Source`}
|
|
|
|
|
items={librarySources.map((source) => (
|
2026-07-20 15:09:06 -07:00
|
|
|
<ThreeStateCheckboxInput
|
|
|
|
|
key={source.id}
|
|
|
|
|
label={source.displayName}
|
|
|
|
|
checked={categoryLibraryOptions.hasSource[source.id]}
|
|
|
|
|
onChange={(checked) =>
|
|
|
|
|
updateCategoryLibraryOptions('hasSource', {
|
|
|
|
|
...categoryLibraryOptions.hasSource,
|
|
|
|
|
[source.id]: checked,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
2026-07-21 00:51:14 +02:00
|
|
|
isActive={isSourceFilterActive}
|
|
|
|
|
/>
|
2026-07-20 15:09:06 -07:00
|
|
|
)}
|
2022-11-24 09:41:03 +01:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (key === 'sort') {
|
2026-07-20 19:01:28 -04:00
|
|
|
return SORT_OPTIONS.map(([mode, label]) =>
|
|
|
|
|
mode === 'random' ? (
|
|
|
|
|
<SortRadioInputRandom
|
|
|
|
|
key={mode}
|
|
|
|
|
label={t(label)}
|
|
|
|
|
checked={categoryLibraryOptions.sortBy === mode}
|
|
|
|
|
sortDescending={categoryLibraryOptions.sortDesc}
|
|
|
|
|
onClick={() =>
|
|
|
|
|
mode !== categoryLibraryOptions.sortBy
|
|
|
|
|
? updateCategoryLibraryOptions('sortBy', mode)
|
|
|
|
|
: updateCategoryLibraryOptions('sortDesc', !categoryLibraryOptions.sortDesc)
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<SortRadioInput
|
|
|
|
|
key={mode}
|
|
|
|
|
label={t(label)}
|
|
|
|
|
checked={categoryLibraryOptions.sortBy === mode}
|
|
|
|
|
sortDescending={categoryLibraryOptions.sortDesc}
|
|
|
|
|
onClick={() =>
|
|
|
|
|
mode !== categoryLibraryOptions.sortBy
|
|
|
|
|
? updateCategoryLibraryOptions('sortBy', mode)
|
|
|
|
|
: updateCategoryLibraryOptions('sortDesc', !categoryLibraryOptions.sortDesc)
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
);
|
2022-11-24 09:41:03 +01:00
|
|
|
}
|
|
|
|
|
if (key === 'display') {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2026-01-10 19:45:02 +01:00
|
|
|
<FormLabel>{t`Display mode`}</FormLabel>
|
2022-11-24 09:41:03 +01:00
|
|
|
<RadioGroup
|
2025-01-25 00:12:56 +01:00
|
|
|
onChange={(e) => updateMetadataServerSettings('gridLayout', Number(e.target.value))}
|
2022-11-24 09:41:03 +01:00
|
|
|
value={gridLayout}
|
|
|
|
|
>
|
2023-02-06 10:06:33 +01:00
|
|
|
<RadioInput
|
2026-01-10 19:45:02 +01:00
|
|
|
label={t`Compact grid`}
|
2023-02-06 10:06:33 +01:00
|
|
|
value={GridLayout.Compact}
|
2023-02-08 18:19:26 +01:00
|
|
|
checked={gridLayout == null || gridLayout === GridLayout.Compact}
|
2023-02-06 10:06:33 +01:00
|
|
|
/>
|
|
|
|
|
<RadioInput
|
2026-01-10 19:45:02 +01:00
|
|
|
label={t`Comfortable grid`}
|
2023-02-06 10:06:33 +01:00
|
|
|
value={GridLayout.Comfortable}
|
|
|
|
|
checked={gridLayout === GridLayout.Comfortable}
|
|
|
|
|
/>
|
|
|
|
|
<RadioInput
|
2026-01-10 19:45:02 +01:00
|
|
|
label={t`List`}
|
2023-02-06 10:06:33 +01:00
|
|
|
value={GridLayout.List}
|
|
|
|
|
checked={gridLayout === GridLayout.List}
|
|
|
|
|
/>
|
2022-11-24 09:41:03 +01:00
|
|
|
</RadioGroup>
|
2026-01-10 19:45:02 +01:00
|
|
|
<FormLabel sx={{ mt: 2 }}>{t`Badges`}</FormLabel>
|
2022-11-24 09:41:03 +01:00
|
|
|
<CheckboxInput
|
2026-01-10 19:45:02 +01:00
|
|
|
label={t`Unread badges`}
|
2023-12-19 15:17:00 +01:00
|
|
|
checked={showUnreadBadge}
|
2024-12-30 03:49:39 +01:00
|
|
|
onChange={() => updateMetadataServerSettings('showUnreadBadge', !showUnreadBadge)}
|
2022-11-24 09:41:03 +01:00
|
|
|
/>
|
|
|
|
|
<CheckboxInput
|
2026-01-10 19:45:02 +01:00
|
|
|
label={t`Download badges`}
|
2023-12-19 15:17:00 +01:00
|
|
|
checked={showDownloadBadge}
|
2024-12-30 03:49:39 +01:00
|
|
|
onChange={() => updateMetadataServerSettings('showDownloadBadge', !showDownloadBadge)}
|
2022-11-24 09:41:03 +01:00
|
|
|
/>
|
2026-01-10 19:45:02 +01:00
|
|
|
<FormLabel sx={{ mt: 2 }}>{t`Tabs`}</FormLabel>
|
2023-04-22 11:39:59 +02:00
|
|
|
<CheckboxInput
|
2026-01-10 19:45:02 +01:00
|
|
|
label={t`Show number of items`}
|
2023-04-22 11:39:59 +02:00
|
|
|
checked={showTabSize}
|
2024-09-17 03:40:55 +02:00
|
|
|
onChange={() => setSettingValue('showTabSize', !showTabSize)}
|
2023-04-22 11:39:59 +02:00
|
|
|
/>
|
2026-01-10 19:45:02 +01:00
|
|
|
<FormLabel sx={{ mt: 2 }}>{t`Other`}</FormLabel>
|
2023-12-19 15:17:00 +01:00
|
|
|
<CheckboxInput
|
2026-01-10 19:45:02 +01:00
|
|
|
label={t`Show continue reading button`}
|
2023-12-19 15:17:00 +01:00
|
|
|
checked={showContinueReadingButton}
|
|
|
|
|
onChange={() =>
|
2024-12-30 03:49:39 +01:00
|
|
|
updateMetadataServerSettings(
|
2024-09-17 03:40:55 +02:00
|
|
|
'showContinueReadingButton',
|
|
|
|
|
!showContinueReadingButton,
|
|
|
|
|
)
|
2023-12-19 15:17:00 +01:00
|
|
|
}
|
|
|
|
|
/>
|
2022-11-24 09:41:03 +01:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
};
|