Move device files into new folder

This commit is contained in:
schroda
2024-10-05 22:27:19 +02:00
parent c0eabf8865
commit 3244a6e3df
9 changed files with 52 additions and 27 deletions

View File

@@ -0,0 +1,31 @@
/*
* 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/.
*/
import React, { ReactNode, useMemo } from 'react';
import { DEFAULT_DEVICE, setActiveDevice } from '@/modules/device/services/Device.ts';
import { useLocalStorage } from '@/modules/core/hooks/useStorage.tsx';
export const DeviceContext = React.createContext<{
activeDevice: string;
setActiveDevice: (device: string) => void;
}>({
activeDevice: DEFAULT_DEVICE,
setActiveDevice: () => {},
});
export const ActiveDeviceContextProvider = ({ children }: { children?: ReactNode }) => {
const [activeDevice, setActiveDeviceContext] = useLocalStorage('activeDevice', DEFAULT_DEVICE);
const activeDeviceContext = useMemo(
() => ({ activeDevice, setActiveDevice: setActiveDeviceContext }),
[activeDevice],
);
setActiveDevice(activeDevice);
return <DeviceContext.Provider value={activeDeviceContext}>{children}</DeviceContext.Provider>;
};