Move device files into new folder
This commit is contained in:
31
src/modules/device/contexts/DeviceContext.tsx
Normal file
31
src/modules/device/contexts/DeviceContext.tsx
Normal 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>;
|
||||
};
|
||||
Reference in New Issue
Block a user