const itemKey = "settings"; | |
export type Settings = { | |
apiURL: string; | |
temperature: number; | |
postCount: number; | |
} | |
const defaultSettings: Settings = { | |
apiURL: "http://localhost:5000", | |
temperature: 0.9, | |
postCount: 3, | |
} | |
export function fetchSettings(): Settings { | |
const storedSettings = localStorage.getItem(itemKey); | |
if (storedSettings) { | |
return {...defaultSettings, ...JSON.parse(storedSettings)} as Settings; | |
} else { | |
return defaultSettings; | |
} | |
} | |
export function saveSettings(settings: Settings) { | |
localStorage.setItem(itemKey, JSON.stringify(settings)); | |
} | |
export function resetSettings() { | |
localStorage.removeItem(itemKey); | |
} |