mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 07:30:04 +00:00
fd35f79c36
TestFlight feedback: on an iPhone Duo the status capsule in the top right
corner covered the trip's controls, its day chips, the map's category bar and
the first cards of every trip tab, upright and on its side. The app has
measured the capsule since 0f42b8b8a, but only the shell's own bars and page
used it, and the trip, its map and the sheets place their own controls.
- Upright, a control row in the capsule's height stands beside it and the
content starts below it: the trip's top row and day chips, the map's
category bar, the road trip's stage bar, every trip tab's first row, the
places browser, the plan timeline, docked and card sheets, the assistant,
the account menu, the image viewer's close button, the atlas search,
vacay's header and a journey's content and map controls.
- On a wide window the page gives up the capsule's side over the whole
height instead, as an iPhone on its side does for its camera: lifting each
page below the capsule cost a quarter of the height of an unfolded Duo.
The list tabs, the assistant panel and the form sheets end before it too.
- Screens whose first row is part of the page (settings, administration,
collections) are lifted until that row is below the capsule; screens that
keep clear of it by themselves (atlas, vacay, a journey) are not lifted.
- Right to left the rail stands on the capsule's side and takes it.
All of it reads the corner variables the app publishes, which are 0 on every
other device and before iOS 26, so nothing else moves. The rules for the
screens that place their own controls live in mobile/corner.css.
122 lines
5.3 KiB
TypeScript
122 lines
5.3 KiB
TypeScript
import React from 'react'
|
|
import { useNavigate } from 'react-router'
|
|
import { Inbox, LogOut, Moon, Settings2, Shield, Sun, SunMoon } from 'lucide-react'
|
|
import type { LucideIcon } from 'lucide-react'
|
|
import { useTranslation } from '../../../i18n'
|
|
import { useAuthStore } from '../../../store/authStore'
|
|
import { useIsDark } from '../../../hooks/useIsDark'
|
|
import { useSettingsStore } from '../../../store/settingsStore'
|
|
import MDropdownPanel from '../../components/MDropdownPanel'
|
|
import MListRow from '../../components/MListRow'
|
|
import { useMailIngestStore } from '../../../store/mailIngestStore'
|
|
import { openMailInbox } from '../../../components/MailIngest/mailInboxOpener'
|
|
|
|
type ThemeMode = 'dark' | 'light' | 'auto'
|
|
|
|
const THEME_ICON: Record<ThemeMode, LucideIcon> = {
|
|
dark: Moon,
|
|
light: Sun,
|
|
auto: SunMoon,
|
|
}
|
|
|
|
// dark_mode is boolean in old accounts and 'light' | 'dark' | 'auto' since the
|
|
// setting grew the auto state — normalize before cycling.
|
|
function resolveMode(darkMode: boolean | string | undefined): ThemeMode {
|
|
if (darkMode === true || darkMode === 'dark') return 'dark'
|
|
if (darkMode === 'auto') return 'auto'
|
|
return 'light'
|
|
}
|
|
|
|
const NEXT_MODE: Record<ThemeMode, ThemeMode> = { dark: 'light', light: 'auto', auto: 'dark' }
|
|
|
|
interface MUserMenuProps {
|
|
open: boolean
|
|
onClose: () => void
|
|
}
|
|
|
|
/**
|
|
* Avatar popover of the mobile top bar: profile header (with admin badge),
|
|
* settings, admin panel (admins only), the dark/light/auto theme cycle, sign
|
|
* out and the app version as a footer, like the desktop account menu.
|
|
*/
|
|
export default function MUserMenu({ open, onClose }: MUserMenuProps): React.ReactElement {
|
|
const { t } = useTranslation()
|
|
const navigate = useNavigate()
|
|
const user = useAuthStore(s => s.user)
|
|
const logout = useAuthStore(s => s.logout)
|
|
const appVersion = useAuthStore(s => s.appVersion)
|
|
const dark = useIsDark()
|
|
const darkMode = useSettingsStore(s => s.settings.dark_mode)
|
|
const updateSetting = useSettingsStore(s => s.updateSetting)
|
|
// The inbox of bookings from forwarded mails, only where the import is on for this person.
|
|
const mailImport = useMailIngestStore(s => s.settings)
|
|
const mailPending = useMailIngestStore(s => s.pending)
|
|
const mailImportOn = !!mailImport?.available && mailImport.prefs.enabled
|
|
|
|
const mode = resolveMode(darkMode)
|
|
const ThemeIcon = THEME_ICON[mode]
|
|
const modeLabel = t(`settings.${mode}`)
|
|
|
|
const go = (path: string) => { onClose(); navigate(path) }
|
|
const cycleTheme = () => { updateSetting('dark_mode', NEXT_MODE[mode]).catch(() => {}) }
|
|
const signOut = async () => {
|
|
onClose()
|
|
await logout()
|
|
navigate('/login')
|
|
}
|
|
|
|
return (
|
|
<MDropdownPanel open={open} onClose={onClose} className="m-corner-beside end-4 top-[calc(var(--m-safe-top,12px)+68px)]">
|
|
<div className="flex items-center gap-[10px] p-[10px_10px_12px]">
|
|
<span className="flex h-10 w-10 flex-none items-center justify-center overflow-hidden rounded-full bg-[image:linear-gradient(135deg,#6A6A74,#1A1A1E)] text-[0.9375rem] font-bold text-white">
|
|
{user?.avatar_url
|
|
? <img src={user.avatar_url} alt="" className="h-full w-full object-cover" />
|
|
: (user?.username || '?')[0].toUpperCase()}
|
|
</span>
|
|
<div className="min-w-0 flex-1">
|
|
<div className="flex items-center gap-[6px]">
|
|
<span className="truncate text-[0.875rem] font-bold">{user?.username}</span>
|
|
{user?.role === 'admin' && (
|
|
<span className="flex-none rounded-full bg-[color:var(--m-ic)] px-[7px] py-[2px] font-geist text-[0.5625rem] font-bold uppercase tracking-[.08em] text-m-muted">
|
|
{t('nav.bottomAdminBadge')}
|
|
</span>
|
|
)}
|
|
</div>
|
|
<div className="truncate font-geist text-[0.65625rem] text-m-muted">{user?.email}</div>
|
|
</div>
|
|
</div>
|
|
<MListRow icon={Settings2} label={t('nav.bottomSettings')} onClick={() => go('/settings')} />
|
|
{mailImportOn && (
|
|
<MListRow
|
|
icon={Inbox}
|
|
label={t('mailInbox.title')}
|
|
onClick={() => { onClose(); openMailInbox() }}
|
|
trailing={mailPending > 0 ? <span className="flex-none rounded-full bg-[color:var(--m-act)] px-[7px] font-geist text-caption font-bold text-[color:var(--m-actfg)]">{mailPending}</span> : undefined}
|
|
/>
|
|
)}
|
|
{user?.role === 'admin' && (
|
|
<MListRow icon={Shield} label={t('nav.bottomAdmin')} onClick={() => go('/admin')} />
|
|
)}
|
|
<MListRow
|
|
icon={ThemeIcon}
|
|
label={t('settings.colorMode')}
|
|
onClick={cycleTheme}
|
|
trailing={<span className="flex-none font-geist text-[0.65625rem] text-m-muted">{modeLabel}</span>}
|
|
/>
|
|
<div className="mx-2 my-1 h-px bg-[color:var(--m-rowbr)]" />
|
|
<MListRow icon={LogOut} danger label={t('nav.bottomLogout')} onClick={signOut} />
|
|
{appVersion && (
|
|
<>
|
|
<div className="mx-2 my-1 h-px bg-[color:var(--m-rowbr)]" />
|
|
<div className="flex justify-center pb-1 pt-[6px]">
|
|
<span className="inline-flex items-center gap-[5px] rounded-full bg-[color:var(--m-ic)] px-3 py-1 font-geist text-caption font-bold text-m-muted">
|
|
<img src={dark ? '/text-light.svg' : '/text-dark.svg'} alt="TREK" className="h-[10px] opacity-50" />
|
|
v{appVersion}
|
|
</span>
|
|
</div>
|
|
</>
|
|
)}
|
|
</MDropdownPanel>
|
|
)
|
|
}
|