Files
suwayomi-material-you-webui/src/util/searchSettings.ts

33 lines
1.2 KiB
TypeScript
Raw Normal View History

/*
* 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 { Metadata, ISearchSettings } from '@/typings';
2023-08-15 13:54:29 +02:00
import requestManager from '@/lib/requests/RequestManager.ts';
2023-09-01 20:24:40 +02:00
import { convertGqlMetadata, getMetadataFrom } from '@/util/metadata';
export const getDefaultSettings = (): ISearchSettings => ({
ignoreFilters: false,
});
const getSearchSettingsWithDefaultValueFallback = (
meta?: Metadata,
defaultSettings: ISearchSettings = getDefaultSettings(),
applyMetadataMigration: boolean = true,
): ISearchSettings => getMetadataFrom({ meta }, defaultSettings, applyMetadataMigration);
export const useSearchSettings = (): {
metadata?: Metadata;
settings: ISearchSettings;
loading: boolean;
} => {
2023-09-01 20:24:40 +02:00
const { data, loading } = requestManager.useGetGlobalMeta();
const metadata = convertGqlMetadata(data?.metas.nodes);
const settings = getSearchSettingsWithDefaultValueFallback(metadata);
2023-09-01 20:24:40 +02:00
return { metadata, settings, loading };
};