mirror of
https://github.com/stashapp/stash.git
synced 2025-12-27 18:56:06 +01:00
Fix UI crash during setup (#4527)
This commit is contained in:
parent
892d74c98b
commit
330581283a
2 changed files with 42 additions and 2 deletions
|
|
@ -5,7 +5,7 @@ import { FormattedMessage, useIntl } from "react-intl";
|
|||
import { Icon } from "../Shared/Icon";
|
||||
import { StringListInput } from "../Shared/StringListInput";
|
||||
import { PatchComponent } from "src/pluginApi";
|
||||
import { useSettings } from "./context";
|
||||
import { useSettings, useSettingsOptional } from "./context";
|
||||
|
||||
interface ISetting {
|
||||
id?: string;
|
||||
|
|
@ -37,7 +37,8 @@ export const Setting: React.FC<PropsWithChildren<ISetting>> = PatchComponent(
|
|||
advanced,
|
||||
} = props;
|
||||
|
||||
const { advancedMode } = useSettings();
|
||||
// these components can be used in the setup wizard, where advanced mode is not available
|
||||
const { advancedMode } = useSettingsOptional();
|
||||
|
||||
const intl = useIntl();
|
||||
|
||||
|
|
|
|||
|
|
@ -51,6 +51,35 @@ export interface ISettingsContextState {
|
|||
refetch: () => void;
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
|
||||
const emptyState: ISettingsContextState = {
|
||||
loading: false,
|
||||
error: undefined,
|
||||
general: {},
|
||||
interface: {},
|
||||
defaults: {},
|
||||
scraping: {},
|
||||
dlna: {},
|
||||
ui: {},
|
||||
plugins: {},
|
||||
|
||||
advancedMode: false,
|
||||
|
||||
apiKey: "",
|
||||
|
||||
saveGeneral: noop,
|
||||
saveInterface: noop,
|
||||
saveDefaults: noop,
|
||||
saveScraping: noop,
|
||||
saveDLNA: noop,
|
||||
saveUI: noop,
|
||||
savePluginSettings: noop,
|
||||
setAdvancedMode: noop,
|
||||
|
||||
refetch: noop,
|
||||
};
|
||||
|
||||
export const SettingStateContext =
|
||||
React.createContext<ISettingsContextState | null>(null);
|
||||
|
||||
|
|
@ -64,6 +93,16 @@ export const useSettings = () => {
|
|||
return context;
|
||||
};
|
||||
|
||||
export function useSettingsOptional(): ISettingsContextState {
|
||||
const context = React.useContext(SettingStateContext);
|
||||
|
||||
if (context === null) {
|
||||
return emptyState;
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
export const SettingsContext: React.FC = ({ children }) => {
|
||||
const Toast = useToast();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue