Files
TREK/client/src/mobile/screens/trip/tabs/MFileMenuSheet.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

130 lines
5.4 KiB
TypeScript

import { useEffect, useRef, useState } from 'react'
import { Download, Link2, Trash2 } from 'lucide-react'
import MSheet from '../../../components/MSheet'
import MListRow from '../../../components/MListRow'
import MConfirmSheet from '../../settings/MConfirmSheet'
import { downloadFile } from '../../../../utils/fileDownload'
import { PHONE_FILE_UPDATE_RULES, trashFileWithToast, updateFileFields } from '../../../../components/Files/fileActions'
import type { TripFile } from '../../../../types'
import type { TripPlanner } from '../MTripShell'
import { Eyebrow, TileHeader } from '../sheets/MTripSheetUi'
import { formatFileDate, getFileTypeMeta } from './filesModel'
import { useTranslation } from '../../../../i18n'
import { formatSize } from '../../../../components/Files/FileManager.helpers'
interface MFileMenuSheetProps {
planner: TripPlanner
/** null closes the sheet; kept mounted through the exit animation via heldRef. */
file: TripFile | null
onClose: () => void
onOpenLinks: (file: TripFile) => void
}
/**
* Kebab context menu for a file row (spec 03 §5.2/§5.3 f.menuGo): the file
* note (desktop's only "rename" — there is no original_name-rename endpoint,
* see report), download, link-to-place/booking and delete-to-trash. Reachable
* regardless of permissions; the sensitive rows gate themselves (§7.6).
*/
export default function MFileMenuSheet({ planner, file, onClose, onOpenLinks }: MFileMenuSheetProps) {
const { t, tripId, can, trip, tripActions, toast } = planner
const { locale } = useTranslation()
const open = file != null
// Hold the last file so the sheet content survives the 280ms exit animation.
const heldRef = useRef<TripFile | null>(file)
if (file) heldRef.current = file
const shown = file ?? heldRef.current
const [noteDraft, setNoteDraft] = useState(shown?.description || '')
useEffect(() => {
setNoteDraft(shown?.description || '')
// Reset the draft only when the sheet targets a different file, not on
// every background files refetch (which would clobber an in-progress edit).
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [shown?.id])
const [saving, setSaving] = useState(false)
const [confirmDelete, setConfirmDelete] = useState(false)
const [deleting, setDeleting] = useState(false)
if (!shown) return <MSheet open={false} onClose={onClose} variant="card" material="glass" />
const canEdit = can('file_edit', trip)
const canDelete = can('file_delete', trip)
const meta = getFileTypeMeta(shown)
const TypeIcon = meta.icon
const commitNote = () => {
const value = noteDraft.trim()
if (value === (shown.description || '')) return
setSaving(true)
void updateFileFields(tripId, shown.id, { description: value }, { t, toast, refresh: () => tripActions.loadFiles(tripId) }, PHONE_FILE_UPDATE_RULES)
.finally(() => setSaving(false))
}
const download = () => { downloadFile(shown.url, shown.original_name).catch(() => {}) }
const remove = () => {
setConfirmDelete(false)
setDeleting(true)
void trashFileWithToast(() => tripActions.deleteFile(tripId, shown.id), { t, toast, onTrashed: onClose })
.finally(() => setDeleting(false))
}
return (
<>
<MSheet open={open} onClose={onClose} variant="card" material="glass" ariaLabel={shown.original_name}>
<div className="flex-none px-[18px] pt-4">
<TileHeader
icon={<TypeIcon size={19} strokeWidth={1.8} style={{ color: meta.color }} />}
title={<span dir="auto" className="truncate">{shown.original_name}</span>}
sub={[formatSize(shown.file_size), formatFileDate(shown.created_at, locale)].filter(Boolean).join(' · ')}
onClose={onClose}
closeLabel={t('common.close')}
/>
</div>
<div className="m-scroll-fade mt-2 min-h-0 flex-1 overflow-y-auto px-[18px] pb-[18px] pt-[14px]">
{canEdit && (
<div className="mt-3">
<Eyebrow className="mb-[6px]">{t('files.noteLabel')}</Eyebrow>
<input
value={noteDraft}
onChange={e => setNoteDraft(e.target.value)}
onBlur={commitNote}
onKeyDown={e => { if (e.key === 'Enter') (e.target as HTMLInputElement).blur() }}
placeholder={t('files.notePlaceholder')}
disabled={saving}
className="w-full rounded-[12px] border border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)] px-3 py-[9px] text-[0.8125rem] font-medium text-m-ink outline-none disabled:opacity-60"
/>
</div>
)}
<div className="mt-3 flex flex-col gap-[2px]">
<MListRow icon={Download} label={t('files.download')} onClick={download} />
{canEdit && (
<MListRow icon={Link2} label={t('files.link')} onClick={() => onOpenLinks(shown)} />
)}
{canDelete && (
<MListRow icon={Trash2} label={t('common.delete')} danger onClick={() => setConfirmDelete(true)} />
)}
</div>
</div>
</MSheet>
<MConfirmSheet
open={confirmDelete}
onClose={() => setConfirmDelete(false)}
title={t('common.delete')}
message={t('files.confirm.delete')}
confirmLabel={t('common.delete')}
cancelLabel={t('common.cancel')}
danger
busy={deleting}
onConfirm={remove}
/>
</>
)
}