2023-05-18 13:17:41 +02: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
|
|
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
2023-06-05 01:42:39 +02:00
|
|
|
import { Metadata, ISearchSettings } from '@/typings';
|
2023-08-15 13:54:29 +02:00
|
|
|
import requestManager from '@/lib/requests/RequestManager.ts';
|
2023-09-08 00:44:01 +02:00
|
|
|
import { convertFromGqlMeta, getMetadataFrom } from '@/util/metadata';
|
2023-03-04 22:21:24 +05:30
|
|
|
|
2023-04-22 11:34:19 +02:00
|
|
|
export const getDefaultSettings = (): ISearchSettings => ({
|
|
|
|
|
ignoreFilters: false,
|
|
|
|
|
});
|
2023-03-04 22:21:24 +05:30
|
|
|
|
|
|
|
|
const getSearchSettingsWithDefaultValueFallback = (
|
2023-04-22 11:34:19 +02:00
|
|
|
meta?: Metadata,
|
|
|
|
|
defaultSettings: ISearchSettings = getDefaultSettings(),
|
2023-03-04 22:21:24 +05:30
|
|
|
applyMetadataMigration: boolean = true,
|
2023-04-22 11:34:19 +02:00
|
|
|
): ISearchSettings => getMetadataFrom({ meta }, defaultSettings, applyMetadataMigration);
|
2023-03-04 22:21:24 +05:30
|
|
|
export const useSearchSettings = (): {
|
2023-04-22 11:34:19 +02:00
|
|
|
metadata?: Metadata;
|
2023-03-04 22:21:24 +05:30
|
|
|
settings: ISearchSettings;
|
|
|
|
|
loading: boolean;
|
|
|
|
|
} => {
|
2023-09-01 20:24:40 +02:00
|
|
|
const { data, loading } = requestManager.useGetGlobalMeta();
|
2023-09-08 00:44:01 +02:00
|
|
|
const metadata = convertFromGqlMeta(data?.metas.nodes);
|
2023-09-01 20:24:40 +02:00
|
|
|
const settings = getSearchSettingsWithDefaultValueFallback(metadata);
|
2023-03-04 22:21:24 +05:30
|
|
|
|
2023-09-01 20:24:40 +02:00
|
|
|
return { metadata, settings, loading };
|
2023-03-04 22:21:24 +05:30
|
|
|
};
|