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): open journal entries to read them, with a pencil into the editor

Maurice59b8d0037336
diff --git a/client/src/mobile/screens/journey/MJourneyDetail.tsx b/client/src/mobile/screens/journey/MJourneyDetail.tsx
index 0366f5297..cf13ce631 100644
--- a/client/src/mobile/screens/journey/MJourneyDetail.tsx
+++ b/client/src/mobile/screens/journey/MJourneyDetail.tsx
@@ -138,6 +138,13 @@ export default function MJourneyDetail({ journeyId, embedded = false }: JourneyD
[current?.entries, hideSkeletons],
)
+ // An existing entry opens to be read, also for those who may edit it (#3007);
+ // the pencil in its sheet switches to the editor. New entries and suggestions
+ // open in the editor straight away.
+ const [editEntryId, setEditEntryId] = useState<number | null>(null)
+ const readingEntry = !!editingEntry && canEditEntries && editingEntry.id !== 0
+ && editingEntry.type !== 'skeleton' && editEntryId !== editingEntry.id
+
const {
mapRef, carouselRef, cardRefs, activeIndex, focusIndex, setActiveIndex, scrubberDays,
syncMapToCard, handleMarkerClick, handleCardTap, openEntryById, jumpToDay,
@@ -698,7 +705,8 @@ export default function MJourneyDetail({ journeyId, embedded = false }: JourneyD
entry={editingEntry}
galleryPhotos={gallery}
quickCapture={editingEntry.id === 0}
- readOnly={!canEditEntries}
+ readOnly={!canEditEntries || readingEntry}
+ onEdit={readingEntry ? () => setEditEntryId(editingEntry.id) : undefined}
showVerdict={current.show_verdict !== 0}
showMood={current.show_mood !== 0}
showWeather={current.show_weather !== 0}
@@ -706,12 +714,12 @@ export default function MJourneyDetail({ journeyId, embedded = false }: JourneyD
trips={current.trips}
photoProviders={availableProviders}
onMoveEarlier={
- canEditEntries && editingEntry.id !== 0 && editingEntry.type !== 'skeleton' && dayNeighbours(editingEntry).canMoveUp
+ canEditEntries && !readingEntry && editingEntry.id !== 0 && editingEntry.type !== 'skeleton' && dayNeighbours(editingEntry).canMoveUp
? () => { void moveWithinDay(editingEntry, -1) }
: undefined
}
onMoveLater={
- canEditEntries && editingEntry.id !== 0 && editingEntry.type !== 'skeleton' && dayNeighbours(editingEntry).canMoveDown
+ canEditEntries && !readingEntry && editingEntry.id !== 0 && editingEntry.type !== 'skeleton' && dayNeighbours(editingEntry).canMoveDown
? () => { void moveWithinDay(editingEntry, 1) }
: undefined
}
@@ -720,7 +728,7 @@ export default function MJourneyDetail({ journeyId, embedded = false }: JourneyD
? () => { setEditingEntry(null); void dismissSuggestion(editingEntry) }
: undefined
}
- onClose={() => setEditingEntry(null)}
+ onClose={() => { setEditingEntry(null); setEditEntryId(null) }}
onSave={async (data, existingEntryId) => {
// existingEntryId is what the sheet already persisted in an earlier
// save attempt — without it a retry would create a second entry.
diff --git a/client/src/mobile/screens/journey/MJourneyEntrySheet.tsx b/client/src/mobile/screens/journey/MJourneyEntrySheet.tsx
index d9e753a0c..b3d6e9ddf 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 } from 'lucide-react'
+import { Briefcase, Camera, Plus, Image, Images, X, MapPin, Locate, Trash2, CheckCircle2, MinusCircle, ChevronUp, ChevronDown, EyeOff, Play, NotebookPen, Pencil } from 'lucide-react'
+import { useSettingsStore } from '../../../store/settingsStore'
+import { formatClockTime } from '../../../utils/formatters'
import MSheet from '../../components/MSheet'
import MIconBtn from '../../components/MIconBtn'
import MToggle from '../../components/MToggle'
@@ -48,6 +50,11 @@ interface MJourneyEntrySheetProps {
galleryPhotos: GalleryPhoto[]
quickCapture?: boolean
readOnly?: boolean
+ /**
+ * Given to an editor reading an entry (#3007): the sheet opens as the read view
+ * and a pencil in its header switches to the editor, without closing it.
+ */
+ onEdit?: () => void
userId?: number
trips?: JourneyTrip[]
/**
@@ -87,10 +94,10 @@ interface MJourneyEntrySheetProps {
*/
export default function MJourneyEntrySheet({
entry, galleryPhotos, quickCapture = false, readOnly = false, userId = 0, trips = [], photoProviders: providers = NO_PROVIDERS,
- showVerdict = true, showMood = true, showWeather = true, onMoveEarlier, onMoveLater, onDismiss,
+ showVerdict = true, showMood = true, showWeather = true, onEdit, onMoveEarlier, onMoveLater, onDismiss,
onClose, onSave, onUploadPhotos, onAddProviderPhotos, onDelete, onDone,
}: MJourneyEntrySheetProps) {
- const { t } = useTranslation()
+ const { t, language } = useTranslation()
const {
title, setTitle, story, setStory, entryDate, setEntryDate, entryTime, setEntryTime,
locationName, locationLat, locationQuery, locationResults, showLocationResults, setShowLocationResults,
@@ -121,6 +128,20 @@ export default function MJourneyEntrySheet({
onClose()
}
+ // An editor reading the entry: the read view, with the way into the editor.
+ const reading = readOnly && !!onEdit
+ const is12h = useSettingsStore(s => s.settings.time_format === '12h')
+ // Read, the date and time head the entry instead of standing in locked fields.
+ const readingWhen = reading && entryDate
+ ? [
+ new Date(`${entryDate}T00:00:00Z`).toLocaleDateString(language, { weekday: 'short', day: 'numeric', month: 'long', timeZone: 'UTC' }),
+ entryTime ? formatClockTime(entryTime, is12h) : '',
+ ].filter(Boolean).join(', ')
+ : ''
+ const heading = entry.id === 0
+ ? t('journey.detail.newEntry')
+ : readingWhen || t('journey.detail.editEntry')
+
const eyebrow = 'font-geist text-[0.625rem] font-bold uppercase tracking-[.09em] text-m-faint'
const fieldShell = 'rounded-xl border border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)]'
@@ -130,7 +151,7 @@ export default function MJourneyEntrySheet({
onClose={handleClose}
variant="card"
form
- ariaLabel={entry.id === 0 ? t('journey.detail.newEntry') : t('journey.detail.editEntry')}
+ ariaLabel={heading}
>
{/* FormSheetHeader's shape, with the move buttons between the title and the close. */}
<div className="m-fs-head flex flex-none items-center gap-3 px-[18px] pb-2 pt-4">
@@ -138,8 +159,13 @@ export default function MJourneyEntrySheet({
<NotebookPen size={19} strokeWidth={1.8} />
</span>
<span className="line-clamp-2 min-w-0 flex-1 break-words text-[1.0625rem] font-bold leading-tight">
- {entry.id === 0 ? t('journey.detail.newEntry') : t('journey.detail.editEntry')}
+ {heading}
</span>
+ {reading && (
+ <MIconBtn variant="neutral" size={34} onClick={onEdit} ariaLabel={t('common.edit')} className="me-1">
+ <Pencil size={15} strokeWidth={2.2} />
+ </MIconBtn>
+ )}
{(onMoveEarlier || onMoveLater) && (
<span className="me-1 flex items-center gap-1">
<MIconBtn variant="neutral" size={34} onClick={() => onMoveEarlier?.()} disabled={!onMoveEarlier} ariaLabel={t('dayplan.moveUp')}>
@@ -514,7 +540,7 @@ export default function MJourneyEntrySheet({
{/* Date + Time. Split in the date's favour: a localized date needs the
room ("10. Sept. 2026"), a clock never does. */}
- <div className="mt-3 grid grid-cols-[minmax(0,1fr)_104px] gap-2">
+ {!reading && <div className="mt-3 grid grid-cols-[minmax(0,1fr)_104px] gap-2">
<div className="min-w-0">
<div className={`${eyebrow} mb-[5px]`}>{t('journey.editor.date')}</div>
{/* TREK's own picker, like the time field beside it: a native
@@ -529,9 +555,9 @@ export default function MJourneyEntrySheet({
brings its own shell, so fieldShell goes with the input. */}
<CustomTimePicker value={entryTime} onChange={setEntryTime} disabled={readOnly} />
</div>
- </div>
+ </div>}
- {tripSuggestion.trip && (
+ {!reading && tripSuggestion.trip && (
<div className={`mt-3 flex items-center gap-3 px-3 py-[10px] ${fieldShell}`}>
<Briefcase size={15} strokeWidth={2} className="flex-none text-m-muted" />
<div className="min-w-0 flex-1">
@@ -545,7 +571,13 @@ export default function MJourneyEntrySheet({
</div>
)}
- {/* Location */}
+ {/* Location: read, a line under the story rather than a locked field. */}
+ {reading ? (locationName && (
+ <div className="mt-3 flex items-center gap-2 text-body font-semibold text-m-ink">
+ <MapPin size={14} strokeWidth={2.2} className="flex-none text-m-muted" />
+ <bdi className="min-w-0 [overflow-wrap:anywhere]">{locationName}</bdi>
+ </div>
+ )) : (
<div className="relative mt-3">
<div className={`${eyebrow} mb-[5px]`}>{t('journey.editor.location')}</div>
<div className={`flex items-center gap-2 px-3 py-[10px] ${fieldShell}`}>
@@ -594,11 +626,13 @@ export default function MJourneyEntrySheet({
{locating && <div className="mt-[5px] font-geist text-[0.65625rem] text-m-muted">{t('common.loading')}</div>}
{locationError && <div className="mt-[5px] font-geist text-[0.65625rem] text-[color:var(--m-st-danger)]">{locationError}</div>}
</div>
+ )}
{/* Off the route: the same switch the desktop editor and the Studio
travel panel offer (#2064). Read-only keeps it visible but locked,
like the date and the mood above and below it. */}
- {offersStatsToggle && (
+ {/* Settings of the entry, not its content: an editor reading it does not need them locked in view. */}
+ {offersStatsToggle && !reading && (
<div className={`mt-3 flex items-center gap-3 px-3 py-[10px] ${fieldShell}`}>
<div className="min-w-0 flex-1">
<div className="text-[0.75rem] font-semibold text-m-ink">{t('journey.editor.statsExcluded')}</div>
@@ -609,19 +643,22 @@ export default function MJourneyEntrySheet({
)}
{/* Kept among the contributors until it is ready (#696). */}
- <div className={`mt-3 flex items-center gap-3 px-3 py-[10px] ${fieldShell}`}>
- <div className="min-w-0 flex-1">
- <div className="text-[0.75rem] font-semibold text-m-ink">{t('journey.editor.draft')}</div>
- <div className="mt-[2px] font-geist text-[0.65625rem] leading-[1.4] text-m-muted">{t('journey.editor.draftHint')}</div>
+ {!reading && (
+ <div className={`mt-3 flex items-center gap-3 px-3 py-[10px] ${fieldShell}`}>
+ <div className="min-w-0 flex-1">
+ <div className="text-[0.75rem] font-semibold text-m-ink">{t('journey.editor.draft')}</div>
+ <div className="mt-[2px] font-geist text-[0.65625rem] leading-[1.4] text-m-muted">{t('journey.editor.draftHint')}</div>
+ </div>
+ <MToggle checked={isDraft} onChange={setIsDraft} disabled={readOnly} ariaLabel={t('journey.editor.draft')} />
</div>
- <MToggle checked={isDraft} onChange={setIsDraft} disabled={readOnly} ariaLabel={t('journey.editor.draft')} />
- </div>
+ )}
{/* Mood */}
- {showMood && !captureOnly && <>
+ {/* Read, only what was chosen shows, and nothing when nothing was. */}
+ {showMood && !captureOnly && (!reading || MOBILE_MOODS.some(m => m.id === mood)) && <>
<div className={`${eyebrow} mb-[6px] mt-3`}>{t('journey.editor.mood')}</div>
<div className="flex flex-wrap gap-[6px]">
- {MOBILE_MOODS.map(m => {
+ {(reading ? MOBILE_MOODS.filter(m => m.id === mood) : MOBILE_MOODS).map(m => {
const active = mood === m.id
return (
<button
@@ -644,10 +681,10 @@ export default function MJourneyEntrySheet({
</>}
{/* Weather */}
- {showWeather && <>
+ {showWeather && (!reading || MOBILE_WEATHERS.some(w => w.id === weather)) && <>
<div className={`${eyebrow} mb-[6px] mt-3`}>{t('journey.editor.weather')}</div>
<div className="flex flex-wrap gap-[6px]">
- {MOBILE_WEATHERS.map(w => {
+ {(reading ? MOBILE_WEATHERS.filter(w => w.id === weather) : MOBILE_WEATHERS).map(w => {
const active = weather === w.id
return (
<button
@@ -746,7 +783,7 @@ export default function MJourneyEntrySheet({
onClick={handleClose}
className={`${SHEET_SECONDARY} ms-auto`}
>
- {t('common.cancel')}
+ {t(reading ? 'common.close' : 'common.cancel')}
</button>
{!readOnly && (
<button
diff --git a/client/tests/unit/mobile/journey/MJourneyDetail.test.tsx b/client/tests/unit/mobile/journey/MJourneyDetail.test.tsx
index f622a5b90..16d0dfcd9 100644
--- a/client/tests/unit/mobile/journey/MJourneyDetail.test.tsx
+++ b/client/tests/unit/mobile/journey/MJourneyDetail.test.tsx
@@ -1,4 +1,4 @@
-// FE-MOB-JDET-001 to FE-MOB-JDET-052
+// FE-MOB-JDET-001 to FE-MOB-JDET-055
import { describe, it, expect, beforeEach, afterEach, onTestFinished, vi } from 'vitest';
import { setSizeClass } from '../../../helpers/sizeClass';
import { render, screen, fireEvent, waitFor, act } from '../../../helpers/render';
@@ -510,6 +510,22 @@ describe('MJourneyDetail', () => {
expect(hook.setDeleteTarget).toHaveBeenCalledWith(entry);
});
+ it('FE-MOB-JDET-054: an editor opens an existing entry to read it, and the pencil turns it into the editor (#3007)', () => {
+ setup({ editingEntry: buildEntry({ id: 4 }) });
+ expect(screen.getByTestId('entry-sheet')).toHaveAttribute('data-readonly', 'true');
+ expect(mocks.captured.entrySheet.onMoveEarlier).toBeUndefined();
+
+ act(() => (mocks.captured.entrySheet.onEdit as () => void)());
+ expect(screen.getByTestId('entry-sheet')).toHaveAttribute('data-readonly', 'false');
+ expect(mocks.captured.entrySheet.onEdit).toBeUndefined();
+ });
+
+ it('FE-MOB-JDET-055: a new entry and a suggestion open in the editor straight away', () => {
+ setup({ editingEntry: buildEntry({ id: 0 }) });
+ expect(screen.getByTestId('entry-sheet')).toHaveAttribute('data-readonly', 'false');
+ expect(mocks.captured.entrySheet.onEdit).toBeUndefined();
+ });
+
it('FE-MOB-JDET-023: a read-only viewer gets the sheet without a delete action', () => {
setup({ canEditEntries: false, editingEntry: buildEntry({ id: 4 }) });
expect(screen.getByTestId('entry-sheet')).toHaveAttribute('data-readonly', 'true');
diff --git a/client/tests/unit/mobile/journey/MJourneyEntrySheet.test.tsx b/client/tests/unit/mobile/journey/MJourneyEntrySheet.test.tsx
index 19568e2d8..3ecefebb9 100644
--- a/client/tests/unit/mobile/journey/MJourneyEntrySheet.test.tsx
+++ b/client/tests/unit/mobile/journey/MJourneyEntrySheet.test.tsx
@@ -252,6 +252,7 @@ interface MountOptions {
upload?: UploadFn;
strict?: boolean;
photoProviders?: { id: string; name: string }[];
+ onEdit?: () => void;
}
const defaultUpload: UploadFn = async (_entryId, files, cbs) => {
@@ -272,6 +273,7 @@ function mountSheet(sheetEntry: JourneyEntry, opts: MountOptions = {}) {
galleryPhotos={opts.galleryPhotos ?? []}
quickCapture={opts.quickCapture ?? false}
readOnly={opts.readOnly ?? false}
+ onEdit={opts.onEdit}
userId={42}
trips={[]}
photoProviders={opts.photoProviders}
@@ -976,6 +978,44 @@ describe('MJourneyEntrySheet read-only', () => {
});
});
+// FE-MOB-JENTRY-060 to FE-MOB-JENTRY-061: an editor reading an entry (#3007).
+
+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 () => {
+ const onEdit = vi.fn();
+ const user = userEvent.setup();
+ mountSheet(buildEntry({
+ id: 5,
+ title: 'Roman holiday',
+ entry_date: '2026-04-16',
+ entry_time: '10:30',
+ location_name: 'Rome',
+ mood: 'good',
+ stats_excluded: false,
+ location_lat: 41.9,
+ location_lng: 12.5,
+ }), { readOnly: true, onEdit });
+
+ expect(screen.getByText(/10:30/)).toBeInTheDocument();
+ expect(screen.queryByText('Date')).not.toBeInTheDocument();
+ expect(screen.queryByRole('switch', { name: 'Leave out of the route' })).not.toBeInTheDocument();
+ expect(screen.queryByRole('switch', { name: 'Draft' })).not.toBeInTheDocument();
+ expect(screen.getByRole('button', { name: 'Good' })).toBeInTheDocument();
+ expect(screen.queryByRole('button', { name: 'Neutral' })).not.toBeInTheDocument();
+ expect(screen.queryByText('Weather')).not.toBeInTheDocument();
+ expect(screen.getByRole('button', { name: 'Close' })).toBeInTheDocument();
+
+ await user.click(screen.getByRole('button', { name: 'Edit' }));
+ expect(onEdit).toHaveBeenCalledTimes(1);
+ });
+
+ 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();
+ expect(screen.getByRole('button', { name: 'Neutral' })).toBeDisabled();
+ });
+});
+
// FE-MOB-JENTRY-051 to FE-MOB-JENTRY-054: leaving a stop off the printed route
// (#2064), the phone sheet's half of the switch the desktop editor has.