|
const itemKey = "settings";
|
|
|
|
export type Settings = {
|
|
apiURL: string;
|
|
temperature: number;
|
|
postCount: number;
|
|
}
|
|
|
|
const defaultSettings: Settings = {
|
|
apiURL: "http://localhost:8000",
|
|
temperature: 0.75,
|
|
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));
|
|
} |