mirror of
https://github.com/sct/overseerr.git
synced 2025-12-26 16:27:17 +01:00
54 lines
1.2 KiB
TypeScript
54 lines
1.2 KiB
TypeScript
import React from 'react';
|
|
import useSWR from 'swr';
|
|
import type { PublicSettingsResponse } from '../../server/interfaces/api/settingsInterfaces';
|
|
|
|
export interface SettingsContextProps {
|
|
currentSettings: PublicSettingsResponse;
|
|
children?: React.ReactNode;
|
|
}
|
|
|
|
const defaultSettings = {
|
|
initialized: false,
|
|
applicationTitle: 'Overseerr',
|
|
applicationUrl: '',
|
|
hideAvailable: false,
|
|
localLogin: true,
|
|
movie4kEnabled: false,
|
|
series4kEnabled: false,
|
|
region: '',
|
|
originalLanguage: '',
|
|
partialRequestsEnabled: true,
|
|
cacheImages: false,
|
|
vapidPublic: '',
|
|
enablePushRegistration: false,
|
|
locale: 'en',
|
|
emailEnabled: false,
|
|
newPlexLogin: true,
|
|
};
|
|
|
|
export const SettingsContext = React.createContext<SettingsContextProps>({
|
|
currentSettings: defaultSettings,
|
|
});
|
|
|
|
export const SettingsProvider = ({
|
|
children,
|
|
currentSettings,
|
|
}: SettingsContextProps) => {
|
|
const { data, error } = useSWR<PublicSettingsResponse>(
|
|
'/api/v1/settings/public',
|
|
{ fallbackData: currentSettings }
|
|
);
|
|
|
|
let newSettings = defaultSettings;
|
|
|
|
if (data && !error) {
|
|
newSettings = data;
|
|
}
|
|
|
|
return (
|
|
<SettingsContext.Provider value={{ currentSettings: newSettings }}>
|
|
{children}
|
|
</SettingsContext.Provider>
|
|
);
|
|
};
|