Skip to content

armgit / TREK

Public Imported from GitHub
0

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.

fix(journey): open photos and videos full screen below the status bar, with the close button in reach

Mauricee7b900d3094a
diff --git a/client/src/components/Journey/PhotoLightbox.test.tsx b/client/src/components/Journey/PhotoLightbox.test.tsx
index 9cd898883..1675afa97 100644
--- a/client/src/components/Journey/PhotoLightbox.test.tsx
+++ b/client/src/components/Journey/PhotoLightbox.test.tsx
@@ -87,9 +87,9 @@ describe('PhotoLightbox', () => {
it('FE-COMP-LIGHTBOX-007: does not render when photos array is empty', () => {
const onClose = vi.fn();
- const { container } = render(<PhotoLightbox photos={[]} onClose={onClose} />);
+ render(<PhotoLightbox photos={[]} onClose={onClose} />);
// Component returns null when photo is undefined (empty array, index 0 is undefined)
- expect(container.querySelector('img')).not.toBeInTheDocument();
+ expect(document.querySelector('img')).not.toBeInTheDocument();
});
it('FE-COMP-LIGHTBOX-008: calls onClose when close button clicked', () => {
@@ -100,10 +100,10 @@ describe('PhotoLightbox', () => {
});
it('FE-COMP-LIGHTBOX-009: opens at the requested start index', () => {
- const { container } = render(<PhotoLightbox photos={samplePhotos} startIndex={2} onClose={vi.fn()} />);
+ render(<PhotoLightbox photos={samplePhotos} startIndex={2} onClose={vi.fn()} />);
expect(screen.getByText('3 / 3')).toBeInTheDocument();
// The third photo has no caption, so its img is presentational.
- expect(container.querySelector('img')).toHaveAttribute('src', '/photos/3.jpg');
+ expect(document.querySelector('img')).toHaveAttribute('src', '/photos/3.jpg');
});
it('FE-COMP-LIGHTBOX-010: only offers the arrows that lead somewhere', () => {
@@ -162,8 +162,8 @@ describe('PhotoLightbox', () => {
});
it('FE-COMP-LIGHTBOX-015: swipes horizontally to move between photos', () => {
- const { container } = render(<PhotoLightbox photos={samplePhotos} startIndex={1} onClose={vi.fn()} />);
- const surface = container.firstElementChild as HTMLElement;
+ render(<PhotoLightbox photos={samplePhotos} startIndex={1} onClose={vi.fn()} />);
+ const surface = screen.getByRole('dialog');
fireEvent.touchStart(surface, { touches: [{ clientX: 200, clientY: 200 }] });
fireEvent.touchEnd(surface, { changedTouches: [{ clientX: 100, clientY: 210 }] });
@@ -176,8 +176,8 @@ describe('PhotoLightbox', () => {
it('FE-COMP-LIGHTBOX-016: swipes down to close', () => {
const onClose = vi.fn();
- const { container } = render(<PhotoLightbox photos={samplePhotos} onClose={onClose} />);
- const surface = container.firstElementChild as HTMLElement;
+ render(<PhotoLightbox photos={samplePhotos} onClose={onClose} />);
+ const surface = screen.getByRole('dialog');
fireEvent.touchStart(surface, { touches: [{ clientX: 200, clientY: 100 }] });
fireEvent.touchEnd(surface, { changedTouches: [{ clientX: 210, clientY: 300 }] });
@@ -187,8 +187,8 @@ describe('PhotoLightbox', () => {
it('FE-COMP-LIGHTBOX-017: ignores a touch end without a matching touch start', () => {
const onClose = vi.fn();
- const { container } = render(<PhotoLightbox photos={samplePhotos} onClose={onClose} />);
- const surface = container.firstElementChild as HTMLElement;
+ render(<PhotoLightbox photos={samplePhotos} onClose={onClose} />);
+ const surface = screen.getByRole('dialog');
fireEvent.touchEnd(surface, { changedTouches: [{ clientX: 210, clientY: 300 }] });
@@ -294,8 +294,8 @@ describe('PhotoLightbox', () => {
});
it('FE-COMP-LIGHTBOX-026: a swipe to the right turns to the next photo', () => {
- const { container } = render(<PhotoLightbox photos={samplePhotos} startIndex={1} onClose={vi.fn()} />);
- const surface = container.firstElementChild as HTMLElement;
+ render(<PhotoLightbox photos={samplePhotos} startIndex={1} onClose={vi.fn()} />);
+ const surface = screen.getByRole('dialog');
fireEvent.touchStart(surface, { touches: [{ clientX: 100, clientY: 200 }] });
fireEvent.touchEnd(surface, { changedTouches: [{ clientX: 200, clientY: 210 }] });
diff --git a/client/src/components/Journey/PhotoLightbox.tsx b/client/src/components/Journey/PhotoLightbox.tsx
index 0c890afec..3fc05269d 100644
--- a/client/src/components/Journey/PhotoLightbox.tsx
+++ b/client/src/components/Journey/PhotoLightbox.tsx
@@ -1,9 +1,11 @@
import { useState, useEffect, useCallback, useRef } from 'react'
+import { createPortal } from 'react-dom'
import { ChevronLeft, ChevronRight, Loader2, X, ZoomIn, ZoomOut } from 'lucide-react'
import VideoPlayer from './VideoPlayerLazy'
import { usePhotoZoom } from './usePhotoZoom'
import { Tooltip } from '../shared/Tooltip'
import { isRtlLanguage, useTranslation } from '../../i18n'
+import { lockBodyScroll } from '../../utils/bodyScrollLock'
interface LightboxPhoto {
id: string
@@ -34,10 +36,22 @@ interface Props {
/** The round glass buttons of the top bar. */
const ROUND_BTN: React.CSSProperties = {
background: 'rgba(255,255,255,0.1)', border: 'none', borderRadius: '50%',
- width: 36, height: 36, display: 'flex', alignItems: 'center', justifyContent: 'center',
- color: '#fff', cursor: 'pointer',
+ width: 40, height: 40, display: 'flex', alignItems: 'center', justifyContent: 'center',
+ color: '#fff', cursor: 'pointer', flex: 'none',
}
+/** Close is the one every visitor needs: a little stronger than the rest. */
+const CLOSE_BTN: React.CSSProperties = { ...ROUND_BTN, background: 'rgba(255,255,255,0.18)' }
+
+/**
+ * The device's insets, from whichever source reports them: env() in a browser,
+ * the values Capacitor's SystemBars writes on Android, the ones the iOS app
+ * measures itself. The viewer is portalled to <body>, outside the phone shell
+ * that defines its own --m-safe-* tokens, so it reads the sources directly.
+ */
+const SAFE = (side: 'top' | 'bottom' | 'left' | 'right') =>
+ `max(env(safe-area-inset-${side}, 0px), var(--safe-area-inset-${side}, 0px), var(--trek-native-safe-${side}, 0px))`
+
export default function PhotoLightbox({ photos, startIndex = 0, onClose, label }: Props) {
const [idx, setIdx] = useState(startIndex)
const touchStart = useRef<{ x: number; y: number } | null>(null)
@@ -51,7 +65,11 @@ export default function PhotoLightbox({ photos, startIndex = 0, onClose, label }
useEffect(() => {
const opener = document.activeElement instanceof HTMLElement ? document.activeElement : null
dialogRef.current?.focus()
- return () => opener?.focus()
+ const unlock = lockBodyScroll()
+ return () => {
+ unlock()
+ opener?.focus()
+ }
}, [])
const photo = photos[idx]
@@ -111,7 +129,9 @@ export default function PhotoLightbox({ photos, startIndex = 0, onClose, label }
if (!photo) return null
- return (
+ // Portalled to <body>: inside a transformed sheet or pane, `fixed` would be
+ // relative to that box and the viewer would open as a small window in it.
+ return createPortal(
<div
ref={dialogRef}
role="dialog"
@@ -120,26 +140,27 @@ export default function PhotoLightbox({ photos, startIndex = 0, onClose, label }
tabIndex={-1}
style={{
outline: 'none',
- position: 'fixed', inset: 0, zIndex: 10000,
+ position: 'fixed', inset: 0, zIndex: 'var(--z-modal)',
background: 'rgba(0,0,0,0.92)', backdropFilter: 'blur(20px)',
display: 'flex', flexDirection: 'column',
- paddingBottom: 'var(--bottom-nav-h)',
+ paddingBottom: SAFE('bottom'),
+ paddingInlineStart: SAFE('left'),
+ paddingInlineEnd: SAFE('right'),
}}
onTouchStart={onTouchStart}
onTouchMove={onTouchMove}
onTouchEnd={onTouchEnd}
>
- {/* Photo area — centered with nav overlays */}
- <div
- className="group/lightbox"
- style={{ flex: 1, display: 'flex', alignItems: 'center', justifyContent: 'center', position: 'relative', overflow: 'hidden' }}
- >
- {/* Top bar */}
- <div style={{ position: 'absolute', top: 0, insetInline: 0, zIndex: 10, display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '16px 20px' }}>
- <span style={{ color: 'rgba(255,255,255,0.5)', fontSize: 'calc(13px * var(--fs-scale-body, 1))', fontWeight: 500 }}>
- {idx + 1} / {photos.length}
- </span>
- <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
+ {/* Top bar: its own row below the status bar and a notch, so the close
+ button is always there to tap and never sits over the photo. */}
+ <div style={{
+ flex: 'none', display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 12,
+ paddingBlock: `calc(${SAFE('top')} + 10px) 10px`, paddingInline: 16,
+ }}>
+ <span style={{ color: 'rgba(255,255,255,0.5)', fontSize: 'calc(13px * var(--fs-scale-body, 1))', fontWeight: 500, fontVariantNumeric: 'tabular-nums' }}>
+ {idx + 1} / {photos.length}
+ </span>
+ <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
{isImage && (
<>
<Tooltip label={t('journey.lightbox.zoomOut')}>
@@ -162,16 +183,17 @@ export default function PhotoLightbox({ photos, startIndex = 0, onClose, label }
</Tooltip>
</>
)}
- <button type="button" onClick={onClose} aria-label={t('common.close')} style={{
- background: 'rgba(255,255,255,0.1)', border: 'none', borderRadius: '50%',
- width: 36, height: 36, display: 'flex', alignItems: 'center', justifyContent: 'center',
- color: '#fff', cursor: 'pointer',
- }}>
- <X size={18} />
+ <button type="button" onClick={onClose} aria-label={t('common.close')} style={CLOSE_BTN}>
+ <X size={20} />
</button>
- </div>
</div>
+ </div>
+ {/* Photo area: what is left below the bar, with the page arrows over it. */}
+ <div
+ className="group/lightbox"
+ style={{ flex: 1, minHeight: 0, display: 'flex', alignItems: 'center', justifyContent: 'center', position: 'relative', overflow: 'hidden', padding: '0 8px 8px' }}
+ >
{/* Prev button — visible on hover (desktop), always visible (mobile) */}
{hasPrev && (
<button type="button" onClick={prev} aria-label={t('journey.lightbox.previous')} className="flex sm:opacity-0 sm:group-hover/lightbox:opacity-100 focus-visible:opacity-100 transition-opacity" style={{
@@ -200,7 +222,7 @@ export default function PhotoLightbox({ photos, startIndex = 0, onClose, label }
onError={() => setLoadedId(photo.id)}
{...zoom.mouse}
style={{
- maxWidth: '92vw', maxHeight: '92vh',
+ maxWidth: '100%', maxHeight: '100%',
objectFit: 'contain', borderRadius: 4,
animation: 'fadeIn 0.15s ease',
userSelect: 'none',
@@ -212,7 +234,7 @@ export default function PhotoLightbox({ photos, startIndex = 0, onClose, label }
{loading && (
<div data-testid="lightbox-loading" aria-hidden="true" style={{ position: 'absolute', inset: 0, display: 'flex', alignItems: 'center', justifyContent: 'center', pointerEvents: 'none' }}>
{photo.thumbSrc && (
- <img src={photo.thumbSrc} alt="" draggable={false} style={{ width: '92vw', height: '92vh', objectFit: 'contain', borderRadius: 4 }} />
+ <img src={photo.thumbSrc} alt="" draggable={false} style={{ width: '100%', height: '100%', objectFit: 'contain', borderRadius: 4 }} />
)}
<span style={{ ...ROUND_BTN, position: 'absolute', cursor: 'default' }}>
<Loader2 size={18} className="animate-spin" />
@@ -252,6 +274,7 @@ export default function PhotoLightbox({ photos, startIndex = 0, onClose, label }
</div>
)}
</div>
- </div>
+ </div>,
+ document.body,
)
}
diff --git a/client/src/mobile/screens/trip/tabs/MFileLightbox.tsx b/client/src/mobile/screens/trip/tabs/MFileLightbox.tsx
index 21cc34156..c8b501017 100644
--- a/client/src/mobile/screens/trip/tabs/MFileLightbox.tsx
+++ b/client/src/mobile/screens/trip/tabs/MFileLightbox.tsx
@@ -45,13 +45,19 @@ export default function MFileLightbox({ files, index, onIndexChange, onClose, t
// tap-to-dismiss. Escape / arrow keys and the header buttons are the
// keyboard equivalents, wired up in useMediaLightbox.
role="presentation"
- className="m-root fixed inset-0 z-[65] flex flex-col bg-black/[.92]"
+ className="m-root fixed inset-0 z-[65] flex flex-col bg-black/[.92] pb-[env(safe-area-inset-bottom,0px)]"
onClick={onClose}
onTouchStart={onTouchStart}
onTouchEnd={onTouchEnd}
>
{/* Header */}
- <div role="presentation" className="flex flex-none items-center justify-between px-4 py-[10px]" onClick={e => e.stopPropagation()}>
+ {/* Below the status bar and a notch, and clear of a side inset in landscape,
+ so the close button is always there to tap. */}
+ <div
+ role="presentation"
+ className="flex flex-none items-center justify-between gap-2 pb-[10px] pe-[calc(var(--m-safe-r)+12px)] ps-[calc(var(--m-safe-l)+16px)] pt-[calc(var(--m-safe-t)+10px)]"
+ onClick={e => e.stopPropagation()}
+ >
<span className="min-w-0 flex-1 truncate font-geist text-[0.75rem] text-white/70">
{file.original_name}
<span className="ms-2 text-white/40">{index + 1} / {files.length}</span>
@@ -73,8 +79,13 @@ export default function MFileLightbox({ files, index, onIndexChange, onClose, t
>
<Download size={16} strokeWidth={2} />
</button>
- <button type="button" onClick={onClose} aria-label={t('common.close')} className="flex h-8 w-8 items-center justify-center text-white/70">
- <X size={18} strokeWidth={2.2} />
+ <button
+ type="button"
+ onClick={onClose}
+ aria-label={t('common.close')}
+ className="ms-1 flex h-10 w-10 items-center justify-center rounded-full bg-[var(--m-viewer-btn)] text-[var(--m-viewer-ink)]"
+ >
+ <X size={20} strokeWidth={2.2} />
</button>
</div>
</div>