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.

feat(mobile): sort an entry's photos by dragging them on the phone

Maurice8c0cca536a9d
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<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 />
) : (
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();