Files
suwayomi-material-you-webui/src/components/library/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';
import { LibraryOptions } from '@/typings';
import { useLocalStorage } from '@/util/useStorage.tsx';
2024-09-17 03:40:55 +02:00
import { LibraryOptionsContext } from '@/components/context/LibraryOptionsContext';
import { getDefaultCategoryMetadata } from '@/lib/metadata/categoryMetadata.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 }) => {
2024-09-17 03:40:55 +02:00
const [options, setOptions] = useLocalStorage<LibraryOptions>('libraryOptions', getDefaultCategoryMetadata());
2024-03-28 20:00:46 +01:00
const value = useMemo(
2024-09-17 03:40:55 +02:00
() => ({ options: { ...getDefaultCategoryMetadata(), ...options }, setOptions }),
2024-03-28 20:00:46 +01:00
[options, setOptions],
);
return <LibraryOptionsContext.Provider value={value}>{children}</LibraryOptionsContext.Provider>;
};