You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
941 B
41 lines
941 B
import React from 'react';
|
|
import { PublicSettingsResponse } from '../../server/interfaces/api/settingsInterfaces';
|
|
import useSWR from 'swr';
|
|
|
|
export interface SettingsContextProps {
|
|
currentSettings: PublicSettingsResponse;
|
|
}
|
|
|
|
const defaultSettings = {
|
|
initialized: false,
|
|
movie4kEnabled: false,
|
|
series4kEnabled: false,
|
|
hideAvailable: false,
|
|
};
|
|
|
|
export const SettingsContext = React.createContext<SettingsContextProps>({
|
|
currentSettings: defaultSettings,
|
|
});
|
|
|
|
export const SettingsProvider: React.FC<SettingsContextProps> = ({
|
|
children,
|
|
currentSettings,
|
|
}) => {
|
|
const { data, error } = useSWR<PublicSettingsResponse>(
|
|
'/api/v1/settings/public',
|
|
{ initialData: currentSettings }
|
|
);
|
|
|
|
let newSettings = defaultSettings;
|
|
|
|
if (data && !error) {
|
|
newSettings = data;
|
|
}
|
|
|
|
return (
|
|
<SettingsContext.Provider value={{ currentSettings: newSettings }}>
|
|
{children}
|
|
</SettingsContext.Provider>
|
|
);
|
|
};
|