mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 05:26:47 +00:00
11a0780a5b
Three reports from the same week, all "the layout is in my way". #2247 — the Plan tab shows both side panels from 768px up, unconditionally. A Pixel 10 Pro Fold unfolded is ~860 CSS px, so 340 + 300 of panel left the map a 200px strip; those same widths became fit padding, shrinking the framing window to 140px and opening the camera two zoom levels out over half of East Asia. The floating POI/compass cluster is centred on the viewport at z-25, which at that width put it on top of both collapse tabs (z-1 inside z-20 containers) and on the Add Place/Activity button — and its pills set pointer-events: auto, so it ate the taps meant for them. The resize handles are mousedown-only, so a touch user could not narrow anything either. Between 768 and 1023px only one panel is open now, the day plan first, the places list one tap away — the Google Maps shape the reporter asked for. The collapse flags stay the wide-layout state, so a fold back restores what was there, and a marker tap reopening "both" no longer re-crowds the screen. The control cluster centres on the corridor the panels leave (the formula PlaceInspector and DayDetailPanel already use), the tabs finally have accessible names, the dead resize handles go, and a panel dragged to 520px on a desktop is clamped so the map keeps 360px without touching the stored width. computeMapViewport refuses to frame for less than a third of the box, so absurd padding can never pick the zoom again. #2248 — the public journey hero clips its own overflow to keep its decorative circles from widening the document, which also amputated the language menu at the hero's bottom edge: 8 of 23 locales, the rest unreachable. Both share pages inlined the same menu, so it is one component now, portalled to the body and anchored to its trigger the way CustomSelect is, with a height cap and its own scroll. It closes on Escape and on an outside click, which it never did, and `zh-TW` stops labelling itself 简体中文. #2249 — the note row's pencil/trash pill is absolutely positioned over the row's own reorder chevrons, and a coarse-pointer `opacity: 1 !important` pinned it permanently visible on tablets. On a mouse it was no better: the chevrons are revealed on hover, which is exactly when the opaque pill covers them, so note reordering has never been clickable on any pointer. The pill is gone; the row opens the note the way the phone shell already does, and delete lives in that dialog behind the same confirmation. A link in the note body keeps its own tap, on both shells. Closes #2247 Closes #2248 Closes #2249
147 lines
6.1 KiB
TypeScript
147 lines
6.1 KiB
TypeScript
import { useEffect, useRef } from 'react'
|
|
import { createPortal } from 'react-dom'
|
|
import { SUPPORTED_LANGUAGES } from '../../i18n'
|
|
import { useSettingsStore } from '../../store/settingsStore'
|
|
import { useAnchoredPosition } from '../../hooks/useAnchoredPosition'
|
|
|
|
/** Wide enough for the longest label ("Português (Brasil)") at the default text size. */
|
|
const MENU_MIN_WIDTH = 190
|
|
const MENU_MAX_HEIGHT = 320
|
|
|
|
interface PublicLanguagePickerProps {
|
|
/** Current UI locale, e.g. `de` or `pt-BR`. */
|
|
locale?: string | null
|
|
open: boolean
|
|
onOpenChange: React.Dispatch<React.SetStateAction<boolean>>
|
|
}
|
|
|
|
/**
|
|
* The language pill both anonymous share pages carry in their top-right corner (#2248).
|
|
*
|
|
* Each page used to inline the same absolutely-positioned menu. On the journey
|
|
* page that menu sits inside a hero with `overflow: hidden` — the clip that keeps
|
|
* the hero's decorative circles from widening the document — so the list of 23
|
|
* languages was amputated at the hero's bottom edge and most of it could never be
|
|
* picked. The menu is portalled to `document.body` and positioned against the
|
|
* trigger now, which no ancestor can clip, and it caps its own height at the room
|
|
* the viewport actually has: the treatment `CustomSelect` already gets.
|
|
*/
|
|
export default function PublicLanguagePicker({ locale, open, onOpenChange }: PublicLanguagePickerProps) {
|
|
const wrapRef = useRef<HTMLDivElement>(null)
|
|
const menuRef = useRef<HTMLDivElement>(null)
|
|
// matchWidth stays on: the anchored box's `width` is the trigger's own width,
|
|
// which is what the right-edge alignment below needs.
|
|
const anchored = useAnchoredPosition(wrapRef, open, { estimatedHeight: MENU_MAX_HEIGHT, offset: 6 })
|
|
|
|
useEffect(() => {
|
|
if (!open) return
|
|
const onPointerDown = (e: MouseEvent) => {
|
|
if (wrapRef.current?.contains(e.target as Node)) return
|
|
if (menuRef.current?.contains(e.target as Node)) return
|
|
onOpenChange(false)
|
|
}
|
|
const onKeyDown = (e: KeyboardEvent) => { if (e.key === 'Escape') onOpenChange(false) }
|
|
document.addEventListener('mousedown', onPointerDown)
|
|
document.addEventListener('keydown', onKeyDown)
|
|
return () => {
|
|
document.removeEventListener('mousedown', onPointerDown)
|
|
document.removeEventListener('keydown', onKeyDown)
|
|
}
|
|
}, [open, onOpenChange])
|
|
|
|
// The two pages hand in different shapes: the journey page passes the stored
|
|
// setting (`br`, `zh-TW`), the trip page the resolved locale (`de-DE`). Try the
|
|
// whole string before its prefix, or `zh-TW` would label itself 简体中文.
|
|
const raw = locale || 'en'
|
|
const current = SUPPORTED_LANGUAGES.some(l => l.value === raw) ? raw : raw.split('-')[0]
|
|
// Pinned by its RIGHT edge, the way `right: 0` did inside the trigger's box. That
|
|
// also lets the panel size to its content: a reader on the largest text setting
|
|
// gets a wider menu instead of "Português (Brasil)" wrapping to two lines.
|
|
const right = anchored
|
|
? Math.max(8, (typeof window === 'undefined' ? 0 : window.innerWidth) - anchored.left - anchored.width)
|
|
: 8
|
|
|
|
return (
|
|
<div ref={wrapRef} style={{ position: 'absolute', top: 12, right: 12, zIndex: 10 }}>
|
|
<button
|
|
type="button"
|
|
aria-haspopup="true"
|
|
aria-expanded={open}
|
|
onClick={() => onOpenChange(v => !v)}
|
|
className="bg-[rgba(255,255,255,0.1)] text-[rgba(255,255,255,0.7)]"
|
|
style={{
|
|
padding: '5px 12px',
|
|
borderRadius: 20,
|
|
border: '1px solid rgba(255,255,255,0.15)',
|
|
backdropFilter: 'blur(8px)',
|
|
WebkitBackdropFilter: 'blur(8px)',
|
|
fontSize: 'calc(11px * var(--fs-scale-caption, 1))',
|
|
fontWeight: 500,
|
|
cursor: 'pointer',
|
|
fontFamily: 'inherit',
|
|
}}
|
|
>
|
|
{SUPPORTED_LANGUAGES.find(l => l.value === current)?.label || 'Language'}
|
|
</button>
|
|
{open && createPortal(
|
|
<div
|
|
ref={menuRef}
|
|
data-testid="public-language-menu"
|
|
className="bg-surface-card border border-edge"
|
|
style={{
|
|
position: 'fixed',
|
|
...(anchored?.flipped ? { bottom: anchored.bottom } : { top: anchored?.top ?? 0 }),
|
|
right,
|
|
minWidth: MENU_MIN_WIDTH,
|
|
maxWidth: 'calc(100vw - 16px)',
|
|
// 23 languages do not fit beside a short viewport; scroll them there
|
|
// rather than letting the list run past the bottom of the screen.
|
|
maxHeight: Math.min(MENU_MAX_HEIGHT, anchored?.maxHeight ?? MENU_MAX_HEIGHT),
|
|
overflowY: 'auto',
|
|
// Portalled and fixed, so the scroll chain runs to the viewport: without
|
|
// this a flick past either end scrolls the page behind it instead (#2078).
|
|
overscrollBehavior: 'contain',
|
|
borderRadius: 10,
|
|
boxShadow: '0 8px 32px rgba(0,0,0,0.2)',
|
|
padding: 4,
|
|
zIndex: 99999,
|
|
}}
|
|
>
|
|
{SUPPORTED_LANGUAGES.map(lang => (
|
|
<button
|
|
type="button"
|
|
key={lang.value}
|
|
aria-current={lang.value === current}
|
|
onClick={() => {
|
|
// No API call: a share-link visitor has no account to save it to.
|
|
useSettingsStore.setState(s => ({ settings: { ...s.settings, language: lang.value } }))
|
|
onOpenChange(false)
|
|
}}
|
|
onMouseEnter={e => (e.currentTarget.style.background = 'var(--bg-hover)')}
|
|
onMouseLeave={e => (e.currentTarget.style.background = 'none')}
|
|
className="text-content-secondary"
|
|
style={{
|
|
display: 'block',
|
|
width: '100%',
|
|
padding: '7px 12px',
|
|
border: 'none',
|
|
background: 'none',
|
|
textAlign: 'left',
|
|
cursor: 'pointer',
|
|
fontSize: 'calc(12px * var(--fs-scale-body, 1))',
|
|
fontWeight: lang.value === current ? 600 : 400,
|
|
borderRadius: 6,
|
|
fontFamily: 'inherit',
|
|
whiteSpace: 'nowrap',
|
|
}}
|
|
>
|
|
{lang.label}
|
|
</button>
|
|
))}
|
|
</div>,
|
|
document.body,
|
|
)}
|
|
</div>
|
|
)
|
|
}
|