From 8c0cca536a9df0d4fe95b075fec494cd44c1c888 Mon Sep 17 00:00:00 2001 From: Maurice Date: Fri, 27 Nov 2026 23:14:30 +0100 Subject: [PATCH] feat(mobile): sort an entry's photos by dragging them on the phone The phone's journal editor could only move a photo to the front. Its tiles now take a long press and a drag into any place, through the photo order the desktop editor already uses (saved at once, put back with a toast when the save fails) and the touch bridge the plan's rows use. The faded tile is the one moving, the ringed one where it lands. Moving to the front stays one tap. Addresses discussion #2851. --- .../screens/journey/MJourneyEntrySheet.tsx | 19 ++++++++++++++++--- .../journey/MJourneyEntrySheet.test.tsx | 13 ++++++++++++- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/client/src/mobile/screens/journey/MJourneyEntrySheet.tsx b/client/src/mobile/screens/journey/MJourneyEntrySheet.tsx index b3d6e9ddf..2bf01cb12 100644 --- a/client/src/mobile/screens/journey/MJourneyEntrySheet.tsx +++ b/client/src/mobile/screens/journey/MJourneyEntrySheet.tsx @@ -1,5 +1,7 @@ import { useRef, useState, type CSSProperties } from 'react' import { Briefcase, Camera, Plus, Image, Images, X, MapPin, Locate, Trash2, CheckCircle2, MinusCircle, ChevronUp, ChevronDown, EyeOff, Play, NotebookPen, Pencil } from 'lucide-react' +import { useIsTouch } from '../../../hooks/useIsTouch' +import { useTouchDragBridge } from '../../../hooks/useTouchDragBridge' import { useSettingsStore } from '../../../store/settingsStore' import { formatClockTime } from '../../../utils/formatters' import MSheet from '../../components/MSheet' @@ -103,7 +105,7 @@ export default function MJourneyEntrySheet({ locationName, locationLat, locationQuery, locationResults, showLocationResults, setShowLocationResults, locating, locationError, mood, setMood, weather, setWeather, statsExcluded, setStatsExcluded, tripSuggestion, isDraft, setIsDraft, pros, setPros, cons, setCons, tags, setTags, tagInput, setTagInput, saving, uploadProgress, - photos, photoOrder, pendingFiles, setPendingFiles, pendingPreviews, setPendingProviderGroups, + photos, photoOrder, canReorder, pendingFiles, setPendingFiles, pendingPreviews, setPendingProviderGroups, showGalleryPick, setShowGalleryPick, isDirty, availableGalleryPhotos, queuedProviderPhotos, providerAssetIds, contextLocation, offersStatsToggle, addVerdictRow, verdictRowRef, addTag, handleSave, handleFileChange, pickGalleryPhoto, removePhoto, searchLocation, pickLocation, handleUseCurrentLocation, @@ -111,6 +113,11 @@ export default function MJourneyEntrySheet({ entry, journeyId: entry.journey_id, trips, galleryPhotos, onSave, onUploadPhotos, onAddProviderPhotos, onDone, readOnly, quickCapture, withTags: true, inlineLocateError: true, }) + // A long press picks a photo up and a drag sets its place (#2851), on the + // touch bridge the plan's rows use: a finger never starts an HTML5 drag. + const sortable = canReorder && !readOnly + const isTouch = useIsTouch() + useTouchDragBridge(isTouch && sortable) const [showExternal, setShowExternal] = useState(false) const [externalProvider, setExternalProvider] = useState(null) const [captureOnly, setCaptureOnly] = useState(quickCapture) @@ -374,9 +381,15 @@ export default function MJourneyEntrySheet({ )} {(photos.length > 0 || pendingFiles.length > 0) && ( -
+
{photos.map((p, idx) => ( -
+
{posterlessVideo(p) ? ( ) : ( diff --git a/client/tests/unit/mobile/journey/MJourneyEntrySheet.test.tsx b/client/tests/unit/mobile/journey/MJourneyEntrySheet.test.tsx index 3ecefebb9..9f4dafa8f 100644 --- a/client/tests/unit/mobile/journey/MJourneyEntrySheet.test.tsx +++ b/client/tests/unit/mobile/journey/MJourneyEntrySheet.test.tsx @@ -978,7 +978,7 @@ describe('MJourneyEntrySheet read-only', () => { }); }); -// FE-MOB-JENTRY-060 to FE-MOB-JENTRY-061: an editor reading an entry (#3007). +// FE-MOB-JENTRY-060 to FE-MOB-JENTRY-062: an editor reading an entry (#3007), sorting its photos (#2851). describe('MJourneyEntrySheet reading view', () => { it('FE-MOB-JENTRY-060: reads as the entry, with its date and time on top and the way into the editor', async () => { @@ -1009,6 +1009,17 @@ describe('MJourneyEntrySheet reading view', () => { expect(onEdit).toHaveBeenCalledTimes(1); }); + it('FE-MOB-JENTRY-062: the photos of a saved entry can be dragged into order, a reader cannot move them (#2851)', () => { + const entry = buildEntry({ id: 5, photos: [buildPhoto(100), buildPhoto(101)] }); + const { container, unmount } = mountSheet(entry); + expect(container.querySelector('[data-touch-drag]')).not.toBeNull(); + expect(container.querySelectorAll('[draggable="true"]').length).toBeGreaterThanOrEqual(2); + unmount(); + + const read = mountSheet(entry, { readOnly: true }); + expect(read.container.querySelector('[data-touch-drag]')).toBeNull(); + }); + it('FE-MOB-JENTRY-061: a viewer without the editor keeps the locked sheet it always had', () => { mountSheet(buildEntry({ id: 5, mood: 'good' }), { readOnly: true }); expect(screen.queryByRole('button', { name: 'Edit' })).not.toBeInTheDocument();