memory settings implementation
This commit is contained in:
25
packages/chat-client/src/hooks/useSettings.js
Normal file
25
packages/chat-client/src/hooks/useSettings.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { getSettings, updateSettings } from '../api/orchestration';
|
||||
|
||||
export function useSettings() {
|
||||
const [settings, setSettings] = useState(null);
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
getSettings().then(setSettings).catch(console.error);
|
||||
}, []);
|
||||
|
||||
async function saveSetting(key, value) {
|
||||
setSaving(true);
|
||||
try {
|
||||
const updated = await updateSettings({ [key]: value });
|
||||
setSettings(updated);
|
||||
} catch (err) {
|
||||
console.error('[useSettings] Save failed:', err.message);
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
}
|
||||
|
||||
return { settings, saveSetting, saving };
|
||||
}
|
||||
Reference in New Issue
Block a user