This repository has been archived on 2026-04-03. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
core/src/js/sw/surfaces/settings/general.js
Jeffrey Smith 786bc92768
All checks were successful
CI/CD / detect-changes (push) Successful in 3s
CI/CD / test-frontend (push) Successful in 5s
CI/CD / test-go-pg (push) Successful in 2m44s
CI/CD / test-sqlite (push) Successful in 2m54s
CI/CD / build-and-deploy (push) Successful in 1m17s
Feat v0.6.11 css dedup (#46)
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com>
Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
2026-04-01 11:18:28 +00:00

63 lines
2.3 KiB
JavaScript

/**
* GeneralSection — user preferences (default surface)
*/
const { html } = window;
const { useState, useEffect, useCallback } = hooks;
export function GeneralSection() {
const [surfaces, setSurfaces] = useState([]);
const [defaultSurface, setDefaultSurface] = useState('');
const [saving, setSaving] = useState(false);
useEffect(() => {
(async () => {
try {
const [s, surfList] = await Promise.all([
sw.api.profile.settings(),
sw.api.get('/api/v1/surfaces').catch(() => []),
]);
const sObj = s || {};
setDefaultSurface(sObj.default_surface || '');
setSurfaces((surfList || []).filter(s => s.route?.startsWith('/s/')));
} catch (e) {
console.warn('[settings/general] Load failed:', e.message);
}
})();
}, []);
const save = useCallback(async () => {
setSaving(true);
try {
await sw.api.profile.updateSettings({
default_surface: defaultSurface,
});
sw.emit('toast', { message: 'Settings saved', variant: 'success' });
} catch (e) {
sw.emit('toast', { message: e.message, variant: 'error' });
} finally {
setSaving(false);
}
}, [defaultSurface]);
return html`
<div class="settings-section">
<h3>Default Surface</h3>
<div class="form-group">
<label>Landing page after login</label>
<select value=${defaultSurface} onChange=${e => setDefaultSurface(e.target.value)}>
<option value="">-- Use global default --</option>
${surfaces.map(s => html`<option key=${s.id} value=${s.id}>${s.icon ? s.icon + ' ' : ''}${s.title || s.id}</option>`)}
</select>
</div>
<span style="font-size:12px;color:var(--text-3);">
Override the global default set by your administrator.
If your chosen surface is uninstalled, the global default is used.
</span>
</div>
<button class="sw-btn sw-btn--primary sw-btn--md" style="margin-top:12px;"
disabled=${saving} onClick=${save}>
${saving ? 'Saving\u2026' : 'Save'}
</button>
`;
}