diff --git a/client/scripts/feature-pairs.json b/client/scripts/feature-pairs.json index 540547485..1484df5b7 100644 --- a/client/scripts/feature-pairs.json +++ b/client/scripts/feature-pairs.json @@ -658,9 +658,15 @@ ], "mobile": ["src/mobile/screens/journey/MJourneySettingsSheet.tsx"] }, + { + "feature": "Journey entries from photos: useJourneyEntriesFromPhotos", + "hooks": ["src/components/Journey/useJourneyEntriesFromPhotos.ts"], + "desktop": ["src/components/Journey/JourneyFromPhotosDialog.tsx"], + "mobile": ["src/mobile/screens/journey/MJourneyFromPhotosSheet.tsx"] + }, { "feature": "Journey settings: useJourneyShareLink", - "hooks": ["src/components/Journey/useJourneyShareLink.ts"], + "hooks": ["src/components/Journey/useJourneyShareLink.ts", "src/components/Journey/useJourneyShareAccess.ts"], "desktop": ["src/components/Journey/JourneyShareSection.tsx"], "mobile": ["src/mobile/screens/journey/MJourneySettingsSheet.tsx"] }, diff --git a/client/src/App.tsx b/client/src/App.tsx index 301816bbb..c88c193f0 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -72,6 +72,7 @@ const JourneyDetailPage = lazyWithRetry(() => import('./pages/JourneyDetailPage' const JourneyStudioPage = lazyWithRetry(() => import('./pages/JourneyStudioPage')) const CollectionsPage = lazyWithRetry(() => import('./pages/CollectionsPage')) const JourneyPublicPage = lazyWithRetry(() => import('./pages/JourneyPublicPage')) +const JourneyFollowPage = lazyWithRetry(() => import('./pages/JourneyFollowPage')) const SharedTripPage = lazyWithRetry(() => import('./pages/SharedTripPage')) const JoinTripPage = lazyWithRetry(() => import('./pages/JoinTripPage')) const InAppNotificationsPage = lazyWithRetry(() => import('./pages/InAppNotificationsPage.tsx')) @@ -518,6 +519,7 @@ export default function App() { } /> } /> } /> + } /> } /> } /> } /> diff --git a/client/src/api/client.ts b/client/src/api/client.ts index 6f66323b0..056b13662 100644 --- a/client/src/api/client.ts +++ b/client/src/api/client.ts @@ -1047,12 +1047,6 @@ export const journeyApi = { createShareLink: (id: number, perms: JourneyShareLinkRequest) => apiClient.post(`/journeys/${id}/share-link`, perms).then(r => r.data), deleteShareLink: (id: number) => apiClient.delete(`/journeys/${id}/share-link`).then(r => r.data), getPublicJourney: (token: string) => apiClient.get(`/public/journey/${token}`).then(r => r.data), - /** - * A reader's password for a protected link (#2553). The answer sets the link's - * unlock cookie, which every later read and photo of that link sends along. - */ - unlockPublicJourney: (token: string, password: string): Promise<{ success: true }> => - apiClient.post(`/public/journey/${token}/unlock`, { password }).then(r => r.data), } // Photo providers (Immich, Synology Photos, …) behind /api/integrations/memories. diff --git a/client/src/api/journeyRecordings.ts b/client/src/api/journeyRecordings.ts index 9e3e76307..5edfbc636 100644 --- a/client/src/api/journeyRecordings.ts +++ b/client/src/api/journeyRecordings.ts @@ -28,7 +28,7 @@ const upstream = { timeout: DAWARICH_UPSTREAM_TIMEOUT_MS }; */ export const journeyRecordingsApi = { list: (journeyId: number, signal?: AbortSignal): Promise => - apiClient.get(base(journeyId), { signal }).then((r) => r.data), + apiClient.get(base(journeyId), { signal, params: { includeGpx: true } }).then((r) => r.data), prep: (journeyId: number, signal?: AbortSignal): Promise => apiClient.get(`${base(journeyId)}/prep`, { signal }).then((r) => r.data), preview: ( diff --git a/client/src/api/journeySocial.ts b/client/src/api/journeySocial.ts index 39fd62551..be3a1a53f 100644 --- a/client/src/api/journeySocial.ts +++ b/client/src/api/journeySocial.ts @@ -34,6 +34,10 @@ export const journeySocialApi = { publicComments: (token: string, signal?: AbortSignal): Promise => apiClient.get(`${pub(token)}/comments`, { signal }).then((r) => r.data), + recordPublicView: (token: string): Promise<{ success: true }> => + apiClient.post(`${pub(token)}/view`).then((r) => r.data), + unlockPublicJourney: (token: string, password: string): Promise<{ success: true }> => + apiClient.post(`${pub(token)}/unlock`, { password }).then((r) => r.data), addPublicComment: ( token: string, entryId: number, diff --git a/client/src/components/Journey/JourneyDayRecordingButton.tsx b/client/src/components/Journey/JourneyDayRecordingButton.tsx index 41ed9a95e..792642e7a 100644 --- a/client/src/components/Journey/JourneyDayRecordingButton.tsx +++ b/client/src/components/Journey/JourneyDayRecordingButton.tsx @@ -1,9 +1,11 @@ import type { JourneyRecordedDay } from '@trek/shared'; -import { Route } from 'lucide-react'; +import { FileUp, RefreshCw, Route, Trash2 } from 'lucide-react'; import type React from 'react'; +import { useRef } from 'react'; import { useTranslation } from '../../i18n'; import { useSettingsStore } from '../../store/settingsStore'; import { formatDistance } from '../../utils/units'; +import { ContextMenu, useContextMenu } from '../shared/ContextMenu'; import DawarichIcon from '../shared/DawarichIcon'; import { fs } from '../shared/DialogShell'; import { Tooltip } from '../shared/Tooltip'; @@ -15,14 +17,28 @@ const ROUND = const PILL = 'inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 font-bold tabular-nums transition-colors aria-disabled:cursor-default [&:not([aria-disabled=true])]:hover:bg-surface-hover'; +const GPX_TYPES = '.gpx,application/gpx+xml'; + +/** Reading a day's route from a GPX file (#3085): open to every editor, with or without Dawarich. */ +export interface DayGpx { + /** The day's route read from a file, if it keeps one. */ + day: JourneyRecordedDay | undefined; + canImport: boolean; + busy: boolean; + onImport: (file: File) => void; + onRemove: () => void; +} + /** - * The recorded route of one journey day in its header (JRN-01). + * The recorded route of one journey day in its header (JRN-01, #3085). * * A day that keeps its route shows how far it went, for everyone who can open * the journey, with whose recording it is and since when in the tooltip; an - * editor opens it to check it against Dawarich again, replace it or drop it. - * A day without one offers an editor whose Dawarich answers to take it over; - * offline the offer stays, dimmed, and says why. + * editor opens a Dawarich day to check it again, replace it or drop it, and a + * day read from a GPX file to replace or drop that file's route. A day without + * one offers an editor one button: take it over from Dawarich, read it from a + * GPX file, or a small menu with both when both are possible. Offline the + * Dawarich offer stays, dimmed, and says why. */ export default function JourneyDayRecordingButton({ day, @@ -30,23 +46,48 @@ export default function JourneyDayRecordingButton({ canTakeOver, needsConnection, onOpen, + gpx, }: { + /** The day's route taken over from Dawarich. */ day: JourneyRecordedDay | undefined; canEdit: boolean; canTakeOver: boolean; needsConnection: boolean; onOpen: () => void; + gpx?: DayGpx; }): React.ReactElement | null { const { t, locale } = useTranslation(); const unit = useSettingsStore((s) => s.settings.distance_unit) ?? 'metric'; + const fileRef = useRef(null); + const menu = useContextMenu(); + + const canImportGpx = !!gpx?.canImport && canEdit; + const pickFile = () => fileRef.current?.click(); + const fileInput = canImportGpx ? ( + { + const file = e.target.files?.[0]; + e.target.value = ''; + if (file) gpx?.onImport(file); + }} + /> + ) : null; + + const keptLabel = (kept: JourneyRecordedDay) => { + const distance = formatDistance(kept.stats.distanceMeters / 1000, unit); + const date = new Date(kept.savedAt).toLocaleDateString(locale, { day: 'numeric', month: 'short' }); + const text = kept.importedBy + ? t('journey.recording.keptBy', { distance, name: kept.importedBy.username, date }) + : t('journey.recording.keptOn', { distance, date }); + return { distance, label: kept.provisional ? `${text} ${t('journey.recording.keptRunning')}` : text }; + }; if (day) { - const distance = formatDistance(day.stats.distanceMeters / 1000, unit); - const date = new Date(day.savedAt).toLocaleDateString(locale, { day: 'numeric', month: 'short' }); - const kept = day.importedBy - ? t('journey.recording.keptBy', { distance, name: day.importedBy.username, date }) - : t('journey.recording.keptOn', { distance, date }); - const label = day.provisional ? `${kept} ${t('journey.recording.keptRunning')}` : kept; + const { distance, label } = keptLabel(day); return ( + + + + ); + } + + if (!canTakeOver && !needsConnection && !canImportGpx) return null; + + // Only a file to read: the button opens the file picker straight away. + if (canImportGpx && !canTakeOver) { + const label = t('journey.recording.gpx.import'); + return ( + <> + {fileInput} + + + + + ); + } + const label = canTakeOver ? t('journey.recording.takeOver') : t('dawarich.error.offline'); return ( - - - + <> + {fileInput} + + + + + ); } diff --git a/client/src/components/Journey/JourneyDetailPageEntryCard.tsx b/client/src/components/Journey/JourneyDetailPageEntryCard.tsx index 9cc6e8c55..eda476015 100644 --- a/client/src/components/Journey/JourneyDetailPageEntryCard.tsx +++ b/client/src/components/Journey/JourneyDetailPageEntryCard.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect } from 'react' +import { useState, useEffect, type ReactNode } from 'react' import { MapPin, Clock, Pencil, Trash2, Plus, PencilLine, RouteOff, X } from 'lucide-react' import { formatLocationName } from '../../utils/formatters' import { useTranslation } from '../../i18n' @@ -14,9 +14,11 @@ import { MoodChip, WeatherChip } from './JourneyDetailPageChips' import { ExpandableStory } from './JourneyDetailPageExpandableStory' import { VerdictSection } from './JourneyDetailPageVerdictSection' -export function EntryCard({ entry, readOnly, onEdit, onDelete, onPhotoClick }: { +export function EntryCard({ entry, readOnly, onEdit, onDelete, onPhotoClick, comments }: { entry: JourneyEntry readOnly?: boolean + /** The comment thread under the entry (#1702), drawn by the page. */ + comments?: ReactNode onEdit: () => void onDelete: () => void onPhotoClick: (photos: JourneyPhoto[], index: number) => void @@ -178,6 +180,8 @@ export function EntryCard({ entry, readOnly, onEdit, onDelete, onPhotoClick }: { )))} )} + + {comments &&
{comments}
} ) diff --git a/client/src/components/Journey/JourneyDetailPageGalleryView.tsx b/client/src/components/Journey/JourneyDetailPageGalleryView.tsx index 7f952d649..f6641d2e1 100644 --- a/client/src/components/Journey/JourneyDetailPageGalleryView.tsx +++ b/client/src/components/Journey/JourneyDetailPageGalleryView.tsx @@ -1,5 +1,6 @@ import { useEffect, useState, useRef } from 'react' -import { RefreshCw, Camera, X, Play } from 'lucide-react' +import { RefreshCw, Camera, X, Play, NotebookPen } from 'lucide-react' +import JourneyFromPhotosDialog from './JourneyFromPhotosDialog' import { useJourneyStore } from '../../store/journeyStore' import { useTranslation } from '../../i18n' import { useToast } from '../shared/Toast' @@ -68,6 +69,11 @@ export function GalleryView({ entries, gallery, journeyId, userId, trips, canEdi // Deleting is final on the server and takes the photo out of every entry that // uses it too, so the tile only asks; the dialog does the deleting (#2593). const [deleteTarget, setDeleteTarget] = useState(null) + const [showFromPhotos, setShowFromPhotos] = useState(false) + const coverOf = (galleryPhotoId: number) => { + const photo = allPhotos.find(p => p.id === galleryPhotoId) + return photo && !posterlessVideo(photo) ? photoUrl(photo, 'thumbnail') : null + } const handleDeletePhoto = async (galleryPhotoId: number) => { const store = useJourneyStore.getState() @@ -89,7 +95,26 @@ export function GalleryView({ entries, gallery, journeyId, userId, trips, canEdi {allPhotos.length} {t('journey.detail.photos', { count: allPhotos.length })} + {/* #1920: the gallery's loose photos as drafts, grouped by day and place. */} + {canEdit && allPhotos.length > 0 && ( + + )} + {showFromPhotos && ( + setShowFromPhotos(false)} + /> + )} {allPhotos.length === 0 ? ( diff --git a/client/src/components/Journey/JourneyEntryComments.test.tsx b/client/src/components/Journey/JourneyEntryComments.test.tsx new file mode 100644 index 000000000..c4b55ff66 --- /dev/null +++ b/client/src/components/Journey/JourneyEntryComments.test.tsx @@ -0,0 +1,71 @@ +import { fireEvent, render, screen, waitFor } from '@testing-library/react'; +import { afterEach, describe, expect, it, vi } from 'vitest'; + +import JourneyEntryComments, { GuestEntryComments, MemberEntryComments } from './JourneyEntryComments'; + +vi.mock('../../i18n', () => ({ useTranslation: () => ({ t: (key: string) => key, locale: 'en' }) })); + +afterEach(() => localStorage.removeItem('trek.journey.guestName')); + +const entry = { + id: 17, + author_name: 'Robin', + is_guest: false, + body: 'A quiet spot by the river', + created_at: '2026-05-14T09:00:00Z', +}; + +describe('Journey entry comments', () => { + it('opens and closes a thread and omits the control for an empty read-only thread', () => { + const onAdd = vi.fn(); + const { rerender } = render(); + const control = () => screen.getByRole('button', { name: 'journey.comments.count' }); + expect(control()).toHaveAttribute('aria-expanded', 'false'); + fireEvent.click(control()); + expect(control()).toHaveAttribute('aria-expanded', 'true'); + expect(screen.getByText(entry.body)).toBeVisible(); + fireEvent.click(control()); + expect(screen.queryByText(entry.body)).toBeNull(); + rerender(); + expect(screen.queryByRole('button')).toBeNull(); + }); + + it('takes a guest name, shows a refusal, and remembers the name after a successful retry', async () => { + const addComment = vi.fn().mockResolvedValueOnce('rate_limited').mockResolvedValueOnce('ok'); + render(); + fireEvent.click(screen.getByRole('button', { name: 'journey.comments.write' })); + const text = screen.getByRole('textbox', { name: 'journey.comments.write' }); + const name = screen.getByRole('textbox', { name: 'common.name' }); + const send = screen.getByRole('button', { name: 'journey.comments.send' }); + fireEvent.change(text, { target: { value: ' Walked here too ' } }); + expect(send).toBeDisabled(); + fireEvent.change(name, { target: { value: ' Lee ' } }); + fireEvent.click(send); + expect(await screen.findByText('common.tooManyAttempts')).toBeVisible(); + expect(text).toHaveValue(' Walked here too '); + expect(localStorage.getItem('trek.journey.guestName')).toBeNull(); + fireEvent.click(send); + await waitFor(() => expect(text).toHaveValue('')); + expect(addComment).toHaveBeenLastCalledWith(13, 'Lee', 'Walked here too'); + expect(localStorage.getItem('trek.journey.guestName')).toBe('Lee'); + }); + + it('lets the moderator show and delete a hidden comment and keeps the public-sharing hint visible', () => { + const setHidden = vi.fn().mockResolvedValue(true); + const remove = vi.fn().mockResolvedValue(true); + const thread = { + byEntry: new Map([[13, [{ ...entry, hidden: true }]]]), + canModerate: true, + add: vi.fn().mockResolvedValue(true), + setHidden, + remove, + }; + render(); + expect(screen.getByText('journey.comments.hidden')).toBeVisible(); + expect(screen.getByText('journey.comments.publicHint')).toBeVisible(); + fireEvent.click(screen.getByRole('button', { name: 'journey.comments.show' })); + fireEvent.click(screen.getByRole('button', { name: 'common.delete' })); + expect(setHidden).toHaveBeenCalledWith(entry.id, false); + expect(remove).toHaveBeenCalledWith(entry.id); + }); +}); diff --git a/client/src/components/Journey/JourneyEntryComments.tsx b/client/src/components/Journey/JourneyEntryComments.tsx new file mode 100644 index 000000000..ae608e1c5 --- /dev/null +++ b/client/src/components/Journey/JourneyEntryComments.tsx @@ -0,0 +1,312 @@ +import { JOURNEY_COMMENT_MAX_LENGTH, JOURNEY_GUEST_NAME_MAX_LENGTH } from '@trek/shared'; +import { Eye, EyeOff, MessageCircle, SendHorizontal, Trash2 } from 'lucide-react'; +import { useState, type FormEvent } from 'react'; +import { useTranslation } from '../../i18n'; +import { useToast } from '../shared/Toast'; +import { Tooltip } from '../shared/Tooltip'; + +/** One comment as the thread draws it: in the app and on the shared page alike. */ +export interface EntryCommentItem { + id: number; + author_name: string | null; + is_guest: boolean; + body: string; + created_at: string | null; + hidden?: boolean; + own?: boolean; +} + +interface Props { + comments: EntryCommentItem[]; + /** Whether a new comment can be written here at all. */ + canWrite: boolean; + /** A reader of the shared page signs with a name; a member writes as their account. */ + guest?: boolean; + /** An editor may hide and delete every comment. */ + canModerate?: boolean; + /** Saves a comment; resolves null when it was taken, else the text to show under the field. */ + onAdd: (body: string, name: string) => Promise; + onHide?: (id: number, hidden: boolean) => Promise; + onDelete?: (id: number) => Promise; + /** Members are told when the share link shows their comments to its readers too. */ + publicHint?: boolean; + /** Start unfolded, where the thread already has a section of its own. */ + defaultOpen?: boolean; +} + +const GUEST_NAME_KEY = 'trek.journey.guestName'; + +function rememberedName(): string { + try { + return localStorage.getItem(GUEST_NAME_KEY) ?? ''; + } catch { + return ''; + } +} + +function rememberName(name: string) { + try { + localStorage.setItem(GUEST_NAME_KEY, name); + } catch { + // A private window keeps no name; the field simply starts empty next time. + } +} + +/** + * The comments under a journal entry (#1702): folded into one quiet line until + * somebody opens it, then the thread oldest first and a field to add one. + * The same thread serves the journey's members in the app and the readers of a + * shared link, who sign with a name instead of an account. + */ +export default function JourneyEntryComments({ + comments, + canWrite, + guest, + canModerate, + onAdd, + onHide, + onDelete, + publicHint, + defaultOpen, +}: Props) { + const { t, locale } = useTranslation(); + const [open, setOpen] = useState(!!defaultOpen); + const [body, setBody] = useState(''); + const [name, setName] = useState(guest ? rememberedName : ''); + const [trap, setTrap] = useState(''); + const [busy, setBusy] = useState(false); + const [message, setMessage] = useState(null); + + if (!canWrite && comments.length === 0) return null; + + const submit = async (e: FormEvent) => { + e.preventDefault(); + if (busy || !body.trim() || (guest && !name.trim())) return; + // Only a bot fills the field people never see: it is told all went well. + if (trap) { + setBody(''); + return; + } + setBusy(true); + setMessage(null); + const failure = await onAdd(body.trim(), name.trim()); + setBusy(false); + if (failure) { + setMessage(failure); + return; + } + if (guest) rememberName(name.trim()); + setBody(''); + }; + + const dateOf = (iso: string | null) => + iso ? new Date(iso).toLocaleDateString(locale || undefined, { day: 'numeric', month: 'short' }) : ''; + + const toggle = ( + + ); + if (!open) return toggle; + + return ( + // The thread sits inside clickable cards: a click in it must not open the entry. +
e.stopPropagation()} role="presentation"> + {!defaultOpen && toggle} + {comments.length > 0 && ( +
    + {comments.map((c) => { + const mayDelete = !!onDelete && (canModerate || c.own); + const mayHide = !!onHide && canModerate; + return ( +
  • +
    +
    + + {c.author_name ?? t('journey.comments.deletedUser')} + + {c.is_guest && ( + + {t('journey.comments.guest')} + + )} + {c.hidden && ( + + {t('journey.comments.hidden')} + + )} + {dateOf(c.created_at)} +
    +

    {c.body}

    +
    + {(mayHide || mayDelete) && ( +
    + {mayHide && ( + + + + )} + {mayDelete && ( + + + + )} +
    + )} +
  • + ); + })} +
+ )} + + {canWrite && ( +
void submit(e)} className="flex flex-col gap-2"> + {guest && ( + setName(e.target.value)} + maxLength={JOURNEY_GUEST_NAME_MAX_LENGTH} + placeholder={t('common.name')} + aria-label={t('common.name')} + autoComplete="name" + className="w-full rounded-xl border border-edge bg-surface px-3 py-2 text-body text-content outline-none placeholder:text-content-faint focus:border-content-faint" + /> + )} + {/* Left empty by people: the field sits off screen and out of the tab order. */} + setTrap(e.target.value)} + name="website" + tabIndex={-1} + autoComplete="off" + aria-hidden="true" + className="absolute -start-[9999px] h-px w-px opacity-0" + /> +
+