| import {createContext} from "@/utils/context" | |
| export type Settings = { | |
| apiType: "ooba"|"beam"; | |
| apiURL: string; | |
| apiKey: string; | |
| temperature: number; | |
| postCount: number; | |
| }; | |
| const defaultSettings: Settings = { | |
| apiType: "beam", | |
| apiURL: "", | |
| apiKey: "", | |
| temperature: 0.9, | |
| postCount: 3, | |
| } | |
| const itemKey = "settings"; | |
| export const settingsCtx = createContext({ | |
| initialValue: () => { | |
| const storedSettings = localStorage.getItem(itemKey); | |
| if (storedSettings) { | |
| return {...defaultSettings, ...JSON.parse(storedSettings)} as Settings; | |
| } | |
| return defaultSettings; | |
| }, | |
| controllers: (settings: Settings, setSettings) => ({ | |
| effect: () => { | |
| localStorage.setItem(itemKey, JSON.stringify(settings)); | |
| }, | |
| actions: { | |
| reset: () => { | |
| // localStorage.removeItem(itemKey); | |
| setSettings(defaultSettings); | |
| }, | |
| }, | |
| }) | |
| }) |