Files
sfhorizont/wasm/frontend/src/screens/Settings.jsx
T
2026-10-24 13:20:55 +02:00

72 lines
3.4 KiB
React
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { NightBackdrop } from './Welcome'
import { IconBack } from '../components/Icons'
import { defaultFovFor } from '../lib/camera'
import { APP_NAME } from '../lib/app'
import { num } from '../lib/format'
import { t, LOCALES, systemLocale, localeName } from '../i18n'
// Typical phone portrait frame (9:16) when nothing is calibrated yet.
const PORTRAIT_GUESS = defaultFovFor(9, 16)
export default function Settings({ settings, onSettingsChange, onBack, onCalibrate }) {
const fov = settings.fovDeg
const adjust = (d) => {
const base = fov != null ? fov : PORTRAIT_GUESS
onSettingsChange({ fovDeg: Math.round(Math.min(120, Math.max(20, base + d)) * 10) / 10 })
}
return (
<div className="screen with-backdrop">
<NightBackdrop />
<div className="screen-body">
<div className="title-row">
{onBack && <button className="icon-btn back" aria-label={t('common.back')} onClick={onBack}><IconBack className="flip-rtl" /></button>}
<h1>{t('settings.title')}</h1>
</div>
<div style={{ marginTop: 20, display: 'flex', flexDirection: 'column', gap: 8 }}>
<span className="overline">{t('settings.camera')}</span>
<div className="row-card">
<div className="grow">
<span className="strong">{t('settings.fov')}</span>
<span className="small">
{fov != null
? t('settings.fovValue', { fov: num(fov, 1) })
: t('settings.fovAssumed', { fov: num(PORTRAIT_GUESS, 0) })}
</span>
</div>
<button className="step-btn" aria-label={t('settings.narrower')} onClick={() => adjust(-1)}>−</button>
<button className="step-btn" aria-label={t('settings.wider')} onClick={() => adjust(1)}>+</button>
</div>
<div style={{ display: 'flex', gap: 10 }}>
<button className="btn btn-secondary" style={{ flex: 1 }} onClick={onCalibrate}>{t('settings.calibrate')}</button>
{fov != null && (
<button className="btn btn-secondary" style={{ padding: '0 16px' }} onClick={() => onSettingsChange({ fovDeg: null })}>{t('settings.reset')}</button>
)}
</div>
<span style={{ fontSize: 13, color: 'var(--muted)' }}>{t('settings.fovHint')}</span>
</div>
<div style={{ marginTop: 28, display: 'flex', flexDirection: 'column', gap: 8 }}>
<label className="overline" htmlFor="language">{t('settings.language')}</label>
<select id="language" className="text-input select" value={settings.language || ''}
onChange={(e) => onSettingsChange({ language: e.target.value })}>
<option value="">{t('settings.systemLanguage', { name: localeName(systemLocale()) })}</option>
{LOCALES.map((l) => <option key={l.code} value={l.code}>{l.name}</option>)}
</select>
</div>
<div style={{ marginTop: 28, display: 'flex', flexDirection: 'column', gap: 8 }}>
<label className="overline" htmlFor="author">{t('settings.author')}</label>
<input id="author" className="text-input" value={settings.author} placeholder={t('settings.authorPlaceholder')}
onChange={(e) => onSettingsChange({ author: e.target.value })} autoComplete="name" dir="auto" />
</div>
<div style={{ marginTop: 28, fontSize: 13, color: 'var(--faint)' }}>
{t('settings.about', { app: APP_NAME })}
</div>
</div>
</div>
)
}