Files
TREK/client/src/mobile/screens/trip/tabs/MFileLightbox.tsx
T
Maurice bf00412863 fix(mobile): Arabic reads in its direction: arrows turn round, Latin names keep their ends, figures stay whole
In the touch shell the back, forward, disclosure, date-range and flow
arrows kept pointing right in Arabic, so Settle up showed the debt the
wrong way round and Vacay's year arrows pointed inward. The shell now
mirrors lucide's direction arrows in right-to-left languages; an icon
that names its own treatment keeps it, and the lightbox arrows stay on
their physical sides.

Latin user text in Arabic rows lost its beginning when cut and moved its
punctuation to the wrong end. Names, titles, addresses and file names take
their direction from their own text (dir=auto) and still line up with the
row; markdown paragraphs, chat messages, poll options and journal stories
are isolated; signed balances, amounts, sizes, rates and leg figures read
as one left-to-right run; URL fields read left to right. Name pairs joined
by an arrow isolate each name and point from the first to the second.

The hero progress and poll result bars fill from the start edge. Arabic
and Hebrew uppercase caption labels grow a step and take the muted ink,
and a todo's due date in a notification is written in the reader's
language instead of as YYYY-MM-DD.
2026-11-07 23:25:16 +01:00

136 lines
5.4 KiB
TypeScript

import { useEffect } from 'react'
import { createPortal } from 'react-dom'
import { ChevronLeft, ChevronRight, Download, ExternalLink, X } from 'lucide-react'
import { downloadFile, openFile } from '../../../../utils/fileDownload'
import { lockBodyScroll } from '../../../../utils/bodyScrollLock'
import { useMediaLightbox } from '../../../../components/Files/useMediaLightbox'
import VideoPlayer from '../../../../components/Journey/VideoPlayerLazy'
import type { TranslationFn, TripFile } from '../../../../types'
interface MFileLightboxProps {
files: TripFile[]
index: number
onIndexChange: (index: number) => void
onClose: () => void
t: TranslationFn
}
function sheetRoot(): HTMLElement {
return document.getElementById('m-sheet-root') ?? document.body
}
/**
* Media viewer for the Files tab (spec 03 §5.3 f.openF, image/video branch):
* a v1-simple version of the desktop FileManagerImageLightbox — full-screen
* dark overlay, prev/next + swipe, download/open-in-tab, no thumbnail strip
* (kept out deliberately, see report). Images resolve through the same
* one-shot signed URL as desktop; video keeps the plain same-origin URL so
* its Range requests stay cookie-authenticated (#823).
*/
export default function MFileLightbox({ files, index, onIndexChange, onClose, t }: MFileLightboxProps) {
const { file, imgSrc, fileIsVideo, hasPrev, hasNext, goPrev, goNext, onTouchStart, onTouchEnd } = useMediaLightbox({
files,
index,
onIndexChange,
onClose,
})
useEffect(() => lockBodyScroll(), [])
if (!file) return null
return createPortal(
<div
// Backdrop, header bar and media pane are plain boxes: they only route the
// 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]"
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()}>
<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>
</span>
<div className="flex flex-none items-center gap-1">
<button
type="button"
onClick={() => { openFile(file.url, file.original_name).catch(() => {}) }}
aria-label={t('files.openTab')}
className="flex h-8 w-8 items-center justify-center text-white/70"
>
<ExternalLink size={16} strokeWidth={2} />
</button>
<button
type="button"
onClick={() => { downloadFile(file.url, file.original_name).catch(() => {}) }}
aria-label={t('files.download')}
className="flex h-8 w-8 items-center justify-center text-white/70"
>
<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>
</div>
</div>
{/* Media + nav */}
<div
role="presentation"
className="relative flex min-h-0 flex-1 items-center justify-center"
onClick={e => {
if (e.target !== e.currentTarget) return
// Without this the click also reaches the overlay handler above.
e.stopPropagation()
onClose()
}}
>
{hasPrev && (
<button
type="button"
onClick={e => { e.stopPropagation(); goPrev() }}
aria-label={t('mobileTrip.filesPrev')}
className="absolute left-3 top-1/2 z-10 flex h-10 w-10 -translate-y-1/2 items-center justify-center rounded-full bg-black/50 text-white/80"
>
{/* The buttons sit on physical sides, so their arrows stay put in Arabic. */}
<ChevronLeft size={22} strokeWidth={2} className="rtl:scale-x-100" />
</button>
)}
{fileIsVideo ? (
<div role="presentation" onClick={e => e.stopPropagation()}>
<VideoPlayer src={file.url} style={{ maxWidth: '92vw', maxHeight: '78vh', borderRadius: 8 }} />
</div>
) : (
imgSrc && (
// The stop sits on a wrapper rather than on the <img>: a picture is
// not something you activate, and this keeps its alt text intact.
<div role="presentation" onClick={e => e.stopPropagation()}>
<img
src={imgSrc}
alt={file.original_name}
className="block max-h-[78vh] max-w-[92vw] rounded-lg object-contain"
/>
</div>
)
)}
{hasNext && (
<button
type="button"
onClick={e => { e.stopPropagation(); goNext() }}
aria-label={t('mobileTrip.filesNext')}
className="absolute right-3 top-1/2 z-10 flex h-10 w-10 -translate-y-1/2 items-center justify-center rounded-full bg-black/50 text-white/80"
>
<ChevronRight size={22} strokeWidth={2} className="rtl:scale-x-100" />
</button>
)}
</div>
</div>,
sheetRoot(),
)
}