Files
suwayomi-material-you-webui/src/modules/library/contexts/LibraryOptionsProvider.tsx

29 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-03-03 18:19:01 +05:30
/*
* 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/.
*/
2022-03-03 18:19:01 +05:30
import React, { useMemo } from 'react';
2024-10-05 16:09:34 +02:00
import { useLocalStorage } from '@/modules/core/hooks/useStorage.tsx';
2024-10-05 19:33:09 +02:00
import { LibraryOptionsContext } from '@/modules/library/contexts/LibraryOptionsContext.tsx';
import { DEFAULT_CATEGORY_METADATA } from '@/modules/category/services/CategoryMetadata.ts';
2024-10-05 19:33:09 +02:00
import { LibraryOptions } from '@/modules/library/Library.types.ts';
2022-03-03 18:19:01 +05:30
interface IProps {
children: React.ReactNode;
}
2023-10-28 00:32:02 +02:00
export const LibraryOptionsContextProvider: React.FC<IProps> = ({ children }) => {
const [options, setOptions] = useLocalStorage<LibraryOptions>('libraryOptions', DEFAULT_CATEGORY_METADATA);
2024-03-28 20:00:46 +01:00
const value = useMemo(
() => ({ options: { ...DEFAULT_CATEGORY_METADATA, ...options }, setOptions }),
2024-03-28 20:00:46 +01:00
[options, setOptions],
);
return <LibraryOptionsContext.Provider value={value}>{children}</LibraryOptionsContext.Provider>;
};