2023-03-04 22:21:24 +05:30
|
|
|
import { useQuery } from 'util/client';
|
|
|
|
|
import { getMetadataFrom } from 'util/metadata';
|
2023-04-22 11:34:19 +02:00
|
|
|
import { Metadata, ISearchSettings } from 'typings';
|
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-05-15 11:56:55 +02:00
|
|
|
const { data: meta, isLoading } = useQuery<Metadata>('/api/v1/meta');
|
2023-03-04 22:21:24 +05:30
|
|
|
const settings = getSearchSettingsWithDefaultValueFallback(meta);
|
|
|
|
|
|
2023-05-15 11:56:55 +02:00
|
|
|
return { metadata: meta, settings, loading: isLoading };
|
2023-03-04 22:21:24 +05:30
|
|
|
};
|