mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
Co-authored-by: openhands <openhands@all-hands.dev> Co-authored-by: Graham Neubig <neubig@gmail.com> Co-authored-by: sp.wack <83104063+amanape@users.noreply.github.com>
41 lines
1021 B
TypeScript
41 lines
1021 B
TypeScript
import React from "react";
|
|
import { settingsAreUpToDate } from "#/services/settings";
|
|
|
|
interface SettingsUpToDateContextType {
|
|
isUpToDate: boolean;
|
|
setIsUpToDate: (value: boolean) => void;
|
|
}
|
|
|
|
const SettingsUpToDateContext = React.createContext<
|
|
SettingsUpToDateContextType | undefined
|
|
>(undefined);
|
|
|
|
interface SettingsUpToDateProviderProps {
|
|
children: React.ReactNode;
|
|
}
|
|
|
|
export function SettingsUpToDateProvider({
|
|
children,
|
|
}: SettingsUpToDateProviderProps) {
|
|
const [isUpToDate, setIsUpToDate] = React.useState(settingsAreUpToDate());
|
|
|
|
const value = React.useMemo(
|
|
() => ({ isUpToDate, setIsUpToDate }),
|
|
[isUpToDate, setIsUpToDate],
|
|
);
|
|
|
|
return (
|
|
<SettingsUpToDateContext value={value}>{children}</SettingsUpToDateContext>
|
|
);
|
|
}
|
|
|
|
export function useSettingsUpToDate() {
|
|
const context = React.useContext(SettingsUpToDateContext);
|
|
if (context === undefined) {
|
|
throw new Error(
|
|
"useSettingsUpToDate must be used within a SettingsUpToDateProvider",
|
|
);
|
|
}
|
|
return context;
|
|
}
|