The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.
TypeScript budget-trackercollaborativedockeritinerarymcp-serveroffline-firstopen-sourceopenstreetmappacking-listpwareal-timeself-hostedselfhostedtraveltravel-apptravel-journaltravel-plannertripitwanderlog
refactor(mobile): keep the settings views under the size and complexity limits
Maurice91f8deb3f3d7
diff --git a/client/src/components/Settings/useApiKeys.ts b/client/src/components/Settings/useApiKeys.tsindex 717a38f9e..32927ee2a 100644--- a/client/src/components/Settings/useApiKeys.ts+++ b/client/src/components/Settings/useApiKeys.ts@@ -48,6 +48,29 @@ export function formatApiKeyStamp(ts: string, locale: string, dateFormat: stringreturn Number.isNaN(d.getTime()) ? ts : formatDisplayDate(d, locale, {}, dateFormat);}+/**+ * What was just copied (the key or the endpoint), for two seconds, so its+ * button can say so. A clipboard the origin lacks (plain http, where a server+ * at home tends to live) calls `onFail`.+ */+function useCopiedFlag(onFail: () => void) {+ const [copied, setCopied] = useState<'key' | 'endpoint' | null>(null);+ const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);+ useEffect(() => () => clearTimeout(timer.current), []);+ const copy = async (text: string, what: 'key' | 'endpoint') => {+ try {+ if (!navigator.clipboard) throw new Error('clipboard unavailable');+ await navigator.clipboard.writeText(text);+ setCopied(what);+ clearTimeout(timer.current);+ timer.current = setTimeout(() => setCopied(null), 2000);+ } catch {+ onFail();+ }+ };+ return { copied, setCopied, copy };+}+export function useApiKeys() {const { t } = useTranslation();const toast = useToast();@@ -60,8 +83,7 @@ export function useApiKeys() {/** The raw key, held only until the dialog closes: the server keeps a hash. */const [created, setCreated] = useState<string | null>(null);const [deleteId, setDeleteId] = useState<number | null>(null);- const [copied, setCopied] = useState<'key' | 'endpoint' | null>(null);- const copiedTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);+ const { copied, setCopied, copy: handleCopy } = useCopiedFlag(() => toast.error(t('settings.apiKeys.copyFailed')));/*** What the new key may read. Starts as everything, because that is what a key* did before this existed and what most integrations want: narrowing is a@@ -88,7 +110,6 @@ export function useApiKeys() {});return () => {cancelled = true;- clearTimeout(copiedTimer.current);};}, []);@@ -136,20 +157,6 @@ export function useApiKeys() {}};- const handleCopy = async (text: string, what: 'key' | 'endpoint') => {- try {- // Absent on a plain-http origin, which is exactly where a self-run- // instance on the LAN tends to live.- if (!navigator.clipboard) throw new Error('clipboard unavailable');- await navigator.clipboard.writeText(text);- setCopied(what);- clearTimeout(copiedTimer.current);- copiedTimer.current = setTimeout(() => setCopied(null), 2000);- } catch {- toast.error(t('settings.apiKeys.copyFailed'));- }- };-const resetForm = () => {setCreated(null);setCopied(null);diff --git a/client/src/mobile/screens/admin/MAdminSheets.tsx b/client/src/mobile/screens/admin/MAdminSheets.tsxindex 2ebdf00f0..60042040d 100644--- a/client/src/mobile/screens/admin/MAdminSheets.tsx+++ b/client/src/mobile/screens/admin/MAdminSheets.tsx@@ -28,13 +28,11 @@ docker run -d --name trek \\// and delete), the "how to update" instructions and the rotate-JWT confirm.export default function MAdminSheets({ admin, t }: MAdminSheetsProps) {const {- currentUser,editingUser, setEditingUser, editForm, setEditForm,showCreateUser, setShowCreateUser, createForm, setCreateForm,updateInfo, showUpdateModal, setShowUpdateModal,showRotateJwtModal, setShowRotateJwtModal, rotatingJwt,- handleCreateUser, handleSaveUser, handleDeleteUser,- oidcConfigured,+ handleCreateUser, handleSaveUser,} = adminconst roleOptions = [@@ -42,24 +40,10 @@ export default function MAdminSheets({ admin, t }: MAdminSheetsProps) {{ value: 'admin', label: t('settings.roleAdmin') },]- const [showResetPasskeys, setShowResetPasskeys] = useState(false)- const [resettingPk, setResettingPk] = useState(false)- const [showResetMfa, setShowResetMfa] = useState(false)- const [showUnlinkSso, setShowUnlinkSso] = useState(false)const userActions = useAdminUserActions(admin, t)const { rotateJwt } = userActions- // The sheet stays open and busy while the reset runs and closes once it worked.- const resetPasskeys = async () => {- if (!editingUser) return- setResettingPk(true)- try {- if (await userActions.resetPasskeys(editingUser)) setShowResetPasskeys(false)- } finally {- setResettingPk(false)- }- }return (<>@@ -164,70 +148,12 @@ export default function MAdminSheets({ admin, t }: MAdminSheetsProps) {onChange={(role) => setEditForm((f) => ({ ...f, role }))}/></MAdminField>- <div className="border-t border-[color:var(--m-rowbr)] pt-3">- <p className="mb-2 font-geist text-[0.625rem] leading-relaxed text-m-muted">- {t('admin.passkey.resetHint')}- </p>- <div className="flex flex-wrap gap-2">- <MAdminButton variant="ghost" className="text-[color:var(--m-st-danger)]" onClick={() => setShowResetPasskeys(true)}>- <Fingerprint size={12} strokeWidth={2.2} />- {t('admin.passkey.reset')}- </MAdminButton>- {editingUser.id !== currentUser?.id && (- <MAdminButton variant="ghost" className="text-[color:var(--m-st-danger)]" onClick={() => setShowResetMfa(true)}>- <ShieldOff size={12} strokeWidth={2.2} />- {t('admin.mfa.reset')}- </MAdminButton>- )}- {/* Unlinking single sign-on, as on the desktop: only once SSO is set up, and never for yourself. */}- {oidcConfigured && editingUser.id !== currentUser?.id && (- <MAdminButton variant="ghost" className="text-[color:var(--m-st-danger)]" onClick={() => setShowUnlinkSso(true)}>- <Unlink size={12} strokeWidth={2.2} />- {t('admin.sso.unlink')}- </MAdminButton>- )}- <MAdminButton- variant="danger"- disabled={editingUser.id === currentUser?.id}- onClick={() => {- const user = editingUser- setEditingUser(null)- void handleDeleteUser(user)- }}- >- <Trash2 size={12} strokeWidth={2.2} />- {t('admin.deleteUserTitle')}- </MAdminButton>- </div>- </div>+ <MUserDangerActions admin={admin} t={t} user={editingUser} /></div>)}</MAdminSheetFrame></MSheet>- {/* Unlink single sign-on confirm */}- <MConfirmSheet- open={showUnlinkSso && !!editingUser}- onClose={() => setShowUnlinkSso(false)}- title={t('admin.sso.unlink')}- message={`${t('admin.sso.unlinkHint')} ${t('admin.sso.unlinkConfirm', { name: editingUser?.username ?? '' })}`}- confirmLabel={t('admin.sso.unlink')}- cancelLabel={t('common.cancel')}- danger- onConfirm={() => {- setShowUnlinkSso(false)- if (editingUser) void userActions.unlinkSso(editingUser)- }}- />-- {/* Reset two-factor confirm */}- <MAdminResetMfaSheet- open={showResetMfa}- onClose={() => setShowResetMfa(false)}- user={editingUser}- onReset={userActions.resetMfa}- t={t}- />{/* How to update */}<MSheet open={showUpdateModal} onClose={() => setShowUpdateModal(false)} ariaLabel={t('admin.update.howTo')}>@@ -281,66 +207,156 @@ export default function MAdminSheets({ admin, t }: MAdminSheetsProps) {</MAdminSheetFrame></MSheet>- {/* Reset passkeys confirm */}- <MSheet open={showResetPasskeys} onClose={() => setShowResetPasskeys(false)} ariaLabel={t('admin.passkey.reset')}>++ {/* Rotate JWT confirm */}+ <MSheet open={showRotateJwtModal} onClose={() => setShowRotateJwtModal(false)} ariaLabel={t('admin.rotateJwt.title')}><MAdminSheetFrame- icon={<KeyRound size={19} strokeWidth={1.8} />}- title={t('admin.passkey.reset')}- onClose={() => setShowResetPasskeys(false)}+ icon={<RotateCcw size={19} strokeWidth={1.8} />}+ title={t('admin.rotateJwt.title')}+ onClose={() => setShowRotateJwtModal(false)}footer={<>- <MAdminButton variant="ghost" disabled={resettingPk} onClick={() => setShowResetPasskeys(false)}>+ <MAdminButton variant="ghost" disabled={rotatingJwt} onClick={() => setShowRotateJwtModal(false)}>{t('common.cancel')}</MAdminButton>- <MAdminButton variant="danger" busy={resettingPk} onClick={resetPasskeys}>- {t('admin.passkey.reset')}+ <MAdminButton variant="danger" busy={rotatingJwt} onClick={rotateJwt}>+ {t('admin.rotateJwt.confirm')}</MAdminButton></>}><div className="flex gap-3"><span className="flex h-10 w-10 flex-none items-center justify-center rounded-full bg-[color:color-mix(in_srgb,var(--m-st-danger)_12%,transparent)] text-[color:var(--m-st-danger)]">- <Fingerprint size={18} strokeWidth={2.2} />+ <AlertTriangle size={18} strokeWidth={2.2} /></span><div className="min-w-0 flex-1"><p className="text-[0.8125rem] font-bold text-m-ink">- {t('admin.passkey.resetConfirm', { name: editingUser?.username ?? '' })}+ {t('admin.rotateJwt.warning')}</p><p className="mt-1 font-geist text-[0.625rem] leading-relaxed text-m-muted">- {t('admin.passkey.resetHint')}+ {t('admin.rotateJwt.body')}</p></div></div></MAdminSheetFrame></MSheet>+ </>+ )+}- {/* Rotate JWT confirm */}- <MSheet open={showRotateJwtModal} onClose={() => setShowRotateJwtModal(false)} ariaLabel={t('admin.rotateJwt.title')}>+/**+ * The ways an admin acts on another account from its edit sheet, each behind+ * its own confirm: passkeys, two-factor, the SSO link, and deleting the user.+ */+function MUserDangerActions({ admin, t, user }: { admin: MAdminSheetsProps['admin']; t: TranslationFn; user: NonNullable<MAdminSheetsProps['admin']['editingUser']> }) {+ const { currentUser, setEditingUser, handleDeleteUser, oidcConfigured } = admin+ const editingUser = user+ const [showResetPasskeys, setShowResetPasskeys] = useState(false)+ const [resettingPk, setResettingPk] = useState(false)+ const [showResetMfa, setShowResetMfa] = useState(false)+ const [showUnlinkSso, setShowUnlinkSso] = useState(false)+ const userActions = useAdminUserActions(admin, t)++ // The sheet stays open and busy while the reset runs and closes once it worked.+ const resetPasskeys = async () => {+ if (!editingUser) return+ setResettingPk(true)+ try {+ if (await userActions.resetPasskeys(editingUser)) setShowResetPasskeys(false)+ } finally {+ setResettingPk(false)+ }+ }++ return (+ <>+ <div className="border-t border-[color:var(--m-rowbr)] pt-3">+ <p className="mb-2 font-geist text-[0.625rem] leading-relaxed text-m-muted">+ {t('admin.passkey.resetHint')}+ </p>+ <div className="flex flex-wrap gap-2">+ <MAdminButton variant="ghost" className="text-[color:var(--m-st-danger)]" onClick={() => setShowResetPasskeys(true)}>+ <Fingerprint size={12} strokeWidth={2.2} />+ {t('admin.passkey.reset')}+ </MAdminButton>+ {editingUser.id !== currentUser?.id && (+ <MAdminButton variant="ghost" className="text-[color:var(--m-st-danger)]" onClick={() => setShowResetMfa(true)}>+ <ShieldOff size={12} strokeWidth={2.2} />+ {t('admin.mfa.reset')}+ </MAdminButton>+ )}+ {/* Unlinking single sign-on, as on the desktop: only once SSO is set up, and never for yourself. */}+ {oidcConfigured && editingUser.id !== currentUser?.id && (+ <MAdminButton variant="ghost" className="text-[color:var(--m-st-danger)]" onClick={() => setShowUnlinkSso(true)}>+ <Unlink size={12} strokeWidth={2.2} />+ {t('admin.sso.unlink')}+ </MAdminButton>+ )}+ <MAdminButton+ variant="danger"+ disabled={editingUser.id === currentUser?.id}+ onClick={() => {+ setEditingUser(null)+ void handleDeleteUser(editingUser)+ }}+ >+ <Trash2 size={12} strokeWidth={2.2} />+ {t('admin.deleteUserTitle')}+ </MAdminButton>+ </div>+ </div>++ {/* Unlink single sign-on confirm */}+ <MConfirmSheet+ open={showUnlinkSso && !!editingUser}+ onClose={() => setShowUnlinkSso(false)}+ title={t('admin.sso.unlink')}+ message={`${t('admin.sso.unlinkHint')} ${t('admin.sso.unlinkConfirm', { name: editingUser?.username ?? '' })}`}+ confirmLabel={t('admin.sso.unlink')}+ cancelLabel={t('common.cancel')}+ danger+ onConfirm={() => {+ setShowUnlinkSso(false)+ if (editingUser) void userActions.unlinkSso(editingUser)+ }}+ />++ {/* Reset two-factor confirm */}+ <MAdminResetMfaSheet+ open={showResetMfa}+ onClose={() => setShowResetMfa(false)}+ user={editingUser}+ onReset={userActions.resetMfa}+ t={t}+ />++ {/* Reset passkeys confirm */}+ <MSheet open={showResetPasskeys} onClose={() => setShowResetPasskeys(false)} ariaLabel={t('admin.passkey.reset')}><MAdminSheetFrame- icon={<RotateCcw size={19} strokeWidth={1.8} />}- title={t('admin.rotateJwt.title')}- onClose={() => setShowRotateJwtModal(false)}+ icon={<KeyRound size={19} strokeWidth={1.8} />}+ title={t('admin.passkey.reset')}+ onClose={() => setShowResetPasskeys(false)}footer={<>- <MAdminButton variant="ghost" disabled={rotatingJwt} onClick={() => setShowRotateJwtModal(false)}>+ <MAdminButton variant="ghost" disabled={resettingPk} onClick={() => setShowResetPasskeys(false)}>{t('common.cancel')}</MAdminButton>- <MAdminButton variant="danger" busy={rotatingJwt} onClick={rotateJwt}>- {t('admin.rotateJwt.confirm')}+ <MAdminButton variant="danger" busy={resettingPk} onClick={resetPasskeys}>+ {t('admin.passkey.reset')}</MAdminButton></>}><div className="flex gap-3"><span className="flex h-10 w-10 flex-none items-center justify-center rounded-full bg-[color:color-mix(in_srgb,var(--m-st-danger)_12%,transparent)] text-[color:var(--m-st-danger)]">- <AlertTriangle size={18} strokeWidth={2.2} />+ <Fingerprint size={18} strokeWidth={2.2} /></span><div className="min-w-0 flex-1"><p className="text-[0.8125rem] font-bold text-m-ink">- {t('admin.rotateJwt.warning')}+ {t('admin.passkey.resetConfirm', { name: editingUser?.username ?? '' })}</p><p className="mt-1 font-geist text-[0.625rem] leading-relaxed text-m-muted">- {t('admin.rotateJwt.body')}+ {t('admin.passkey.resetHint')}</p></div></div>diff --git a/client/src/mobile/screens/settings/MSettingsGeneral.tsx b/client/src/mobile/screens/settings/MSettingsGeneral.tsxindex e5fd44ef6..92acd9386 100644--- a/client/src/mobile/screens/settings/MSettingsGeneral.tsx+++ b/client/src/mobile/screens/settings/MSettingsGeneral.tsx@@ -1,4 +1,4 @@-import { useState } from 'react'+import { useState, type ReactNode } from 'react'import { ChevronDown, Languages, Map, Rocket } from 'lucide-react'import { useTranslation, SUPPORTED_LANGUAGES } from '../../../i18n'import { useSettingSaver } from '../../../components/Settings/useSettingSaver'@@ -27,7 +27,6 @@ export default function MSettingsGeneral() {const demoLocked = useDemoAccountLock()const [currencyOpen, setCurrencyOpen] = useState(false)const [langOpen, setLangOpen] = useState(false)- const [placeLangOpen, setPlaceLangOpen] = useState(false)const [startTabOpen, setStartTabOpen] = useState(false)const [navAppOpen, setNavAppOpen] = useState(false)const [dateFormatOpen, setDateFormatOpen] = useState(false)@@ -135,19 +134,7 @@ export default function MSettingsGeneral() {<MSetSelectRow label={language.label} trailing={chevron} onClick={() => setLangOpen(true)} /></DemoLock>- {/* Place names (#1799): searches can answer in another language than the app. */}- <div className="mb-[5px] mt-[14px]">- <MHintLabel- label={t('settings.placeLanguage')}- hint={t('settings.placeLanguageHint')}- labelClassName="font-geist text-[length:calc(10px*var(--fs-scale-caption,1))] font-bold uppercase tracking-[.09em] text-m-faint"- />- </div>- <MSetSelectRow- label={SUPPORTED_LANGUAGES.find((l) => l.value === settings.place_language)?.label ?? t('settings.placeLanguageApp')}- trailing={chevron}- onClick={() => setPlaceLangOpen(true)}- />+ <MPlaceLanguage value={settings.place_language || ''} onSave={(v) => save('place_language', v)} trailing={chevron} /><MSetEyebrow className="mb-[6px] mt-[14px]">{t('settings.temperature')}</MSetEyebrow><MSetSegments@@ -246,17 +233,6 @@ export default function MSettingsGeneral() {options={dateFormats}/>- <MSetPickerSheet- open={placeLangOpen}- onClose={() => setPlaceLangOpen(false)}- title={t('settings.placeLanguage')}- value={settings.place_language || ''}- onSelect={(v) => save('place_language', v)}- options={[- { value: '', label: t('settings.placeLanguageApp') },- ...SUPPORTED_LANGUAGES.map((l) => ({ value: l.value, label: l.label })),- ]}- /><MSetPickerSheetopen={langOpen}onClose={() => setLangOpen(false)}@@ -286,3 +262,36 @@ export default function MSettingsGeneral() {</>)}++/** Place names (#1799): searches can answer in another language than the app. */+function MPlaceLanguage({ value, onSave, trailing }: { value: string; onSave: (value: string) => void; trailing: ReactNode }) {+ const { t } = useTranslation()+ const [open, setOpen] = useState(false)+ return (+ <>+ <div className="mb-[5px] mt-[14px]">+ <MHintLabel+ label={t('settings.placeLanguage')}+ hint={t('settings.placeLanguageHint')}+ labelClassName="font-geist text-[length:calc(10px*var(--fs-scale-caption,1))] font-bold uppercase tracking-[.09em] text-m-faint"+ />+ </div>+ <MSetSelectRow+ label={SUPPORTED_LANGUAGES.find((l) => l.value === value)?.label ?? t('settings.placeLanguageApp')}+ trailing={trailing}+ onClick={() => setOpen(true)}+ />+ <MSetPickerSheet+ open={open}+ onClose={() => setOpen(false)}+ title={t('settings.placeLanguage')}+ value={value}+ onSelect={onSave}+ options={[+ { value: '', label: t('settings.placeLanguageApp') },+ ...SUPPORTED_LANGUAGES.map((l) => ({ value: l.value, label: l.label })),+ ]}+ />+ </>+ )+}