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
|
2023-05-18 13:17:41 +02:00
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
2022-03-03 18:19:01 +05:30
|
|
|
|
2023-03-11 18:05:58 +01:00
|
|
|
import React, { useMemo } from 'react';
|
2023-06-05 01:42:39 +02:00
|
|
|
import { LibraryOptions } from '@/typings';
|
2024-10-05 16:09:34 +02:00
|
|
|
import { useLocalStorage } from '@/modules/core/hooks/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());
|
2022-04-07 12:53:14 +02:00
|
|
|
|
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],
|
|
|
|
|
);
|
2023-03-11 18:05:58 +01:00
|
|
|
|
|
|
|
|
return <LibraryOptionsContext.Provider value={value}>{children}</LibraryOptionsContext.Provider>;
|
2022-11-24 09:41:03 +01:00
|
|
|
};
|