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.
This commit is contained in:
Maurice
2026-11-27 23:14:30 +01:00
parent dd1a117b92
commit 8c0cca536a
2 changed files with 28 additions and 4 deletions
@@ -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<string | null>(null)
const [captureOnly, setCaptureOnly] = useState(quickCapture)
@@ -374,9 +381,15 @@ export default function MJourneyEntrySheet({
)}
{(photos.length > 0 || pendingFiles.length > 0) && (
<div className="mt-[10px] flex flex-wrap gap-2">
<div className="mt-[10px] flex flex-wrap gap-2" data-touch-drag={sortable ? '' : undefined}>
{photos.map((p, idx) => (
<div key={p.id} className="relative h-16 w-16 overflow-hidden rounded-[13px]">
<div
key={p.id}
{...(sortable ? photoOrder.dragProps(idx) : {})}
className={`relative h-16 w-16 overflow-hidden rounded-[13px] transition-opacity ${
photoOrder.dragIndex === idx ? 'opacity-40' : ''
} ${photoOrder.overIndex === idx && photoOrder.dragIndex !== idx ? 'ring-2 ring-[color:var(--m-act)]' : ''}`}
>
{posterlessVideo(p) ? (
<ClipTile />
) : (
@@ -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();