SPB Git

Repository Public

Settings.tsx 5.7 KB 113 lines tsx

1/**2 * =============================================================================3 *                  SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : MacLustr Social Engine & Remote Navigator8 * File             : apps/social-web/src/screens/Settings.tsx9 * Module           : screens10 * Repository       : https://git.spboucher.ai/maclustr-social11 * Project Website  : https://social.spboucher.ai12 * Created          : 2026-12-0113 * Last Modified    : 2026-12-0114 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142import { useState } from 'react';43import { logout, passkeyRegister } from '../../../shared/api.ts';44import type { Key } from '../i18n.ts';45import { usePrefs, type Theme } from '../prefs.tsx';46import { useSession } from '../session.tsx';47import { Link, navigate } from '../router.tsx';48import { ActionStatus, Field, PageHead, Panel, useAction } from '../ui/core.tsx';49import { Policy } from './settings/Policy.tsx';50import { AgentRuns, Agents } from './settings/Agents.tsx';51import { Recipes } from './settings/Recipes.tsx';52import { Sources } from './settings/Sources.tsx';53import { Users } from './settings/Users.tsx';5455type Tab = { id: string; key: Key; min?: 'admin' | 'owner' };56const TABS: Tab[] = [57  { id: 'prefs', key: 'se.tab.prefs' }, { id: 'policy', key: 'se.tab.policy', min: 'admin' }, { id: 'agents', key: 'se.tab.agents' }, { id: 'runs', key: 'se.tab.runs' },58  { id: 'recipes', key: 'se.tab.recipes', min: 'admin' }, { id: 'sources', key: 'se.tab.sources' }, { id: 'users', key: 'se.tab.users', min: 'owner' },59];6061export function Settings({ tab }: { tab: string }) {62  const { t } = usePrefs();63  const s = useSession();64  const tabs = TABS.filter((x) => !x.min || s.atLeast(x.min));65  const cur = tabs.find((x) => x.id === tab);66  return (67    <>68      <PageHead title={t('nav.settings')} />69      <nav className="tabs" aria-label={t('nav.settings')}><ul>{tabs.map((x) => <li key={x.id}><Link to={`/settings/${x.id}`} aria-current={x.id === tab ? 'page' : undefined}>{t(x.key)}</Link></li>)}</ul></nav>70      {!cur ? <div className="note note-warn" role="alert"><p>{TABS.some((x) => x.id === tab) ? t('err.role_insufficient') : t('c.notFound')}</p></div>71        : tab === 'prefs' ? <Preferences /> : tab === 'policy' ? <Policy /> : tab === 'agents' ? <Agents /> : tab === 'runs' ? <AgentRuns /> : tab === 'recipes' ? <Recipes /> : tab === 'sources' ? <Sources /> : <Users />}72    </>73  );74}7576function Preferences() {77  const { t, lang, setLang, theme, setTheme } = usePrefs();78  const s = useSession();79  const [label, setLabel] = useState('');80  const pk = useAction(); const out = useAction();81  const add = async () => { if (await pk.run(() => passkeyRegister(undefined, label.trim()), t('se.passkeyAdded'))) { setLabel(''); await s.reloadMe(); } };82  const everywhere = () => out.run(async () => { await logout(true); navigate('/'); await s.reloadMe(); });83  const themes: [Theme, Key][] = [['system', 'se.theme.system'], ['light', 'se.theme.light'], ['dark', 'se.theme.dark']];84  return (85    <>86      <Panel title={t('se.display')}>87        <fieldset><legend>{t('c.language')}</legend>88          <label className="check"><input type="radio" name="lang" checked={lang === 'fr'} onChange={() => setLang('fr')} /><span lang="fr">Français</span></label>89          <label className="check"><input type="radio" name="lang" checked={lang === 'en'} onChange={() => setLang('en')} /><span lang="en">English</span></label>90        </fieldset>91        <fieldset><legend>{t('se.theme')}</legend>92          {themes.map(([v, k]) => <label className="check" key={v}><input type="radio" name="theme" checked={theme === v} onChange={() => setTheme(v)} /><span>{t(k)}</span></label>)}93        </fieldset>94        <p className="small">{t('se.storedLocally')}</p>95      </Panel>96      <Panel title={t('se.passkeys')}>97        <p>{t('se.passkeysHere', { n: s.me.passkeysHere, host: window.location.hostname })}</p>98        <p className="small">{t('se.passkeysNote')}</p>99        <form className="form inline-form" onSubmit={(e) => { e.preventDefault(); void add(); }}>100          <Field label={t('auth.setup.label')}><input value={label} onChange={(e) => setLabel(e.target.value)} maxLength={60} autoComplete="off" /></Field>101          <button type="submit" disabled={pk.busy}>{t('se.addPasskey')}</button>102        </form>103        <ActionStatus a={pk} />104      </Panel>105      <Panel title={t('se.account')}>106        <p><code>{s.me.user.handle}</code> — {s.me.user.display_name}</p>107        <p><button type="button" onClick={everywhere} disabled={out.busy}>{t('se.logoutEverywhere')}</button></p>108        <ActionStatus a={out} />109      </Panel>110    </>111  );112}113
Files main
Menu

Theme