mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 15:17:30 +00:00
feat(journey): the enhancements from discussion #2299
roel-de-vries pitched seventeen changes to Journey. Four were already built or rest on a misunderstanding, one cannot work as described, and three would take away more than they give; the rest are here, plus two things the list did not ask for. **The entry you write on the move now has a name.** Quick capture hid the title field outright and offered a note instead, so every entry caught on a phone arrived nameless and a day's timeline read as a column of identical placeholders. One line of input; it is the single change in this branch that users will feel most. **The map stops yanking.** Stepping through the timeline called flyTo with a zoom floor of 12, so reading a journey from a country view snapped to street level on the first scroll and stayed there — every marker filling the screen, and no sense of where anything was. Both renderers pan now and leave the frame the reader chose. The initial fitBounds still decides how close a journey opens. **The phone timeline is photos.** A 64px thumbnail beside three lines of text spent the card on a story nobody reads at that size and truncated the title after a few characters. The picture is the card now, with the name and place on it, the country's flag and the date in the corners, and the day carried as a colour rather than as a number nobody was reading. Above the carousel, a segment per day: it says how long the journey is, how far in you are, and takes you to day nine without swiping past days three to eight. Everything else, briefly: - A plus in each day header, starting a draft on that day instead of on today. - A journey opens on today when today is part of it, and at the beginning when it is not — a journey that ended last spring is something you read. - Suggestions can be waved away one at a time. The row survives so the trip sync does not offer the same place again; journey settings brings them all back. - Mood, weather and the pros/cons list can be switched off per journey. Nothing written is erased — the form stops asking, the values stay. - The weather fills itself in at the desk the way it already did on the phone. The date picks the source, so writing up last Tuesday gets last Tuesday's. - Enter opens the next pro or con, below the one you are in. - The verdict moved behind the story's fold, and the fold itself came in from nine lines to four. - The external picker lost the count it was printing twice and some padding it could not afford inside the editor. - The phone can reorder entries within a day at last; the desktop arrows finally have translated labels. - Marker labels are off where a carousel already names the entry, and on where they are the only name a marker has. - Search over a journey's titles, stories, places and tags, accent-blind. - An entry knows which country it happened in, resolved once from its coordinates against the bundled boundaries. Not built, and why: the photos-for-markers idea needs clustering first or thirty markers become soup, and the active entry's photo is already on screen in the card below. Removing mood, weather and the verdict outright would take them from everyone who uses them, so they became switches. `capture` on the file picker takes the photo library away on a phone, which is why the camera is a second input; it is hidden on desktop now instead. The suggestion strip in the new-entry flow would be a third surface over the same data — tapping a suggestion already opens the editor filled in. The one gap the list missed and this branch does not close: Journey is the only domain with no offline path. That belongs in its own change.
This commit is contained in:
@@ -8,6 +8,8 @@ interface MIconBtnProps {
|
||||
/** Diameter in px (topbar 38, sheet close 34) */
|
||||
size?: number
|
||||
className?: string
|
||||
/** Dimmed and inert. For a button whose position should stay put even when it cannot act. */
|
||||
disabled?: boolean
|
||||
children: ReactNode
|
||||
}
|
||||
|
||||
@@ -18,6 +20,7 @@ export default function MIconBtn({
|
||||
variant = 'glass',
|
||||
size = 38,
|
||||
className = '',
|
||||
disabled = false,
|
||||
children,
|
||||
}: MIconBtnProps) {
|
||||
return (
|
||||
@@ -25,7 +28,8 @@ export default function MIconBtn({
|
||||
type="button"
|
||||
onClick={onClick}
|
||||
aria-label={ariaLabel}
|
||||
className={`relative flex flex-none items-center justify-center rounded-full text-m-ink ${
|
||||
disabled={disabled}
|
||||
className={`relative flex flex-none items-center justify-center rounded-full text-m-ink disabled:opacity-35 ${
|
||||
variant === 'glass'
|
||||
? 'border border-[color:var(--m-gbr)] bg-[color:var(--m-glass)]'
|
||||
: 'bg-[color:var(--m-ic)]'
|
||||
|
||||
@@ -24,7 +24,9 @@ import MSheet from '../../components/MSheet'
|
||||
import MDancingTrek from '../../components/MDancingTrek'
|
||||
import MListRow from '../../components/MListRow'
|
||||
import MToggle from '../../components/MToggle'
|
||||
import MJourneyEntryCard from './MJourneyEntryCard'
|
||||
import JourneyEntryCover from '../../../components/Journey/JourneyEntryCover'
|
||||
import JourneyDayScrubber from '../../../components/Journey/JourneyDayScrubber'
|
||||
import { dayColorOf, journeyDays } from '../../../components/Journey/journeyCard'
|
||||
import MJourneyEntrySheet from './MJourneyEntrySheet'
|
||||
import MJourneySettingsSheet from './MJourneySettingsSheet'
|
||||
|
||||
@@ -45,7 +47,8 @@ export default function MJourneyDetail() {
|
||||
showSettings, setShowSettings,
|
||||
hideSkeletons, setHideSkeletons,
|
||||
sidebarMapItems, tracks,
|
||||
loadJourney, updateEntry, deleteEntry, uploadPhotos,
|
||||
dismissSuggestion, restoreSuggestions, openAtEntryId,
|
||||
loadJourney, updateEntry, deleteEntry, reorderEntries, uploadPhotos,
|
||||
} = useJourneyDetail()
|
||||
|
||||
// The dock's FAB is a sibling of this screen: on the Gallery it becomes the
|
||||
@@ -112,18 +115,69 @@ export default function MJourneyDetail() {
|
||||
}
|
||||
}, [entries.length, pickNearestCard])
|
||||
|
||||
// Initial focus — give Leaflet time to initialise and fit bounds first.
|
||||
// Initial focus — give Leaflet time to initialise and fit bounds first. Opens on
|
||||
// today when today is part of the journey (see openAtEntryId), rather than always
|
||||
// at the first entry (discussion #2299).
|
||||
useEffect(() => {
|
||||
if (entries.length === 0) return
|
||||
const timer = window.setTimeout(() => syncMapToCard(0), 500)
|
||||
const target = openAtEntryId ? entries.findIndex(e => String(e.id) === openAtEntryId) : -1
|
||||
const index = target === -1 ? 0 : target
|
||||
const timer = window.setTimeout(() => {
|
||||
setActiveIndex(index)
|
||||
syncMapToCard(index)
|
||||
if (index > 0) cardRefs.current.get(index)?.scrollIntoView({ inline: 'center', block: 'nearest' })
|
||||
}, 500)
|
||||
return () => window.clearTimeout(timer)
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [entries.length])
|
||||
}, [entries.length, openAtEntryId])
|
||||
|
||||
const scrollCardIntoCenter = useCallback((idx: number) => {
|
||||
cardRefs.current.get(idx)?.scrollIntoView({ behavior: 'smooth', inline: 'center', block: 'nearest' })
|
||||
}, [])
|
||||
|
||||
const scrubberDays = useMemo(() => journeyDays(entries), [entries])
|
||||
|
||||
/**
|
||||
* Move an entry within its day, from the entry sheet's header.
|
||||
*
|
||||
* Same rules as the desktop arrows: suggestions do not take part, because they
|
||||
* are the trip's order rather than the traveller's, and a day with one entry
|
||||
* has nothing to reorder. The whole day goes back to the server, which is what
|
||||
* the reorder endpoint expects.
|
||||
*/
|
||||
const moveWithinDay = useCallback(async (entry: JourneyEntry, direction: -1 | 1) => {
|
||||
if (!current) return
|
||||
const sameDay = entries.filter(e => e.entry_date === entry.entry_date && e.type !== 'skeleton')
|
||||
const index = sameDay.findIndex(e => e.id === entry.id)
|
||||
const target = index + direction
|
||||
if (index === -1 || target < 0 || target >= sameDay.length) return
|
||||
const reordered = [...sameDay]
|
||||
const [moved] = reordered.splice(index, 1)
|
||||
reordered.splice(target, 0, moved)
|
||||
try {
|
||||
await reorderEntries(current.id, reordered.map(e => e.id))
|
||||
await loadJourney(current.id)
|
||||
} catch {
|
||||
toast.error(t('common.errorOccurred'))
|
||||
}
|
||||
}, [current, entries, reorderEntries, loadJourney, toast, t])
|
||||
|
||||
/** Where in the day's run an entry sits, so the sheet knows which arrows to offer. */
|
||||
const dayNeighbours = useCallback((entry: JourneyEntry) => {
|
||||
const sameDay = entries.filter(e => e.entry_date === entry.entry_date && e.type !== 'skeleton')
|
||||
const index = sameDay.findIndex(e => e.id === entry.id)
|
||||
return { canMoveUp: index > 0, canMoveDown: index >= 0 && index < sameDay.length - 1 }
|
||||
}, [entries])
|
||||
|
||||
/** The day bar lands on the first entry of that day. */
|
||||
const jumpToDay = useCallback((date: string) => {
|
||||
const idx = entries.findIndex(e => e.entry_date === date)
|
||||
if (idx === -1) return
|
||||
setActiveIndex(idx)
|
||||
syncMapToCard(idx)
|
||||
scrollCardIntoCenter(idx)
|
||||
}, [entries, scrollCardIntoCenter, syncMapToCard])
|
||||
|
||||
const handleMarkerClick = useCallback((markerId: string) => {
|
||||
const idx = entries.findIndex(e => String(e.id) === markerId)
|
||||
if (idx === -1) return
|
||||
@@ -290,7 +344,8 @@ export default function MJourneyDetail() {
|
||||
activeMarkerId={entries[activeIndex] ? String(entries[activeIndex].id) : null}
|
||||
onMarkerClick={handleMarkerClick}
|
||||
fullScreen
|
||||
paddingBottom={200}
|
||||
paddingBottom={250}
|
||||
hideMarkerTooltip
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -428,11 +483,17 @@ export default function MJourneyDetail() {
|
||||
</MSheet>
|
||||
)}
|
||||
|
||||
{/* Horizontal card timeline */}
|
||||
{/* Day bar + horizontal card timeline */}
|
||||
{view === 'timeline' && entries.length > 0 && (
|
||||
<div className="absolute left-0 right-0 z-[8] bottom-[calc(var(--bottom-nav-h,84px)+16px)]">
|
||||
<JourneyDayScrubber
|
||||
days={scrubberDays}
|
||||
activeDate={entries[activeIndex]?.entry_date ?? null}
|
||||
onPick={jumpToDay}
|
||||
/>
|
||||
<div
|
||||
ref={carouselRef}
|
||||
className="absolute left-0 right-0 z-[8] flex gap-[10px] overflow-x-auto px-4 pb-1 bottom-[calc(var(--bottom-nav-h,84px)+16px)] [-webkit-overflow-scrolling:touch] [scrollbar-width:none]"
|
||||
className="flex items-end gap-[10px] overflow-x-auto px-4 pb-1 [-webkit-overflow-scrolling:touch] [scrollbar-width:none]"
|
||||
style={{ scrollSnapType: 'x mandatory' }}
|
||||
>
|
||||
{entries.map((entry, i) => (
|
||||
@@ -441,10 +502,19 @@ export default function MJourneyDetail() {
|
||||
ref={node => { if (node) cardRefs.current.set(i, node); else cardRefs.current.delete(i) }}
|
||||
style={{ scrollSnapAlign: 'center' }}
|
||||
>
|
||||
<MJourneyEntryCard entry={entry} number={i + 1} onClick={() => handleCardTap(entry, i)} />
|
||||
<JourneyEntryCover
|
||||
entry={entry}
|
||||
dayColor={dayColorOf(scrubberDays, entry.entry_date)}
|
||||
isActive={i === activeIndex}
|
||||
onClick={() => handleCardTap(entry, i)}
|
||||
showMood={current.show_mood !== 0}
|
||||
showWeather={current.show_weather !== 0}
|
||||
tone="mobile"
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<input ref={galleryFileRef} type="file" accept="image/*,video/*" multiple className="hidden" onChange={handleGalleryUpload} />
|
||||
@@ -493,8 +563,26 @@ export default function MJourneyDetail() {
|
||||
galleryPhotos={gallery}
|
||||
quickCapture={editingEntry.id === 0}
|
||||
readOnly={!canEditEntries}
|
||||
showVerdict={current.show_verdict !== 0}
|
||||
showMood={current.show_mood !== 0}
|
||||
showWeather={current.show_weather !== 0}
|
||||
userId={useAuthStore.getState().user?.id || 0}
|
||||
trips={current.trips}
|
||||
onMoveEarlier={
|
||||
canEditEntries && 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
|
||||
? () => { void moveWithinDay(editingEntry, 1) }
|
||||
: undefined
|
||||
}
|
||||
onDismiss={
|
||||
canEditEntries && editingEntry.type === 'skeleton' && editingEntry.id !== 0
|
||||
? () => { setEditingEntry(null); void dismissSuggestion(editingEntry) }
|
||||
: undefined
|
||||
}
|
||||
onClose={() => setEditingEntry(null)}
|
||||
onSave={async (data, existingEntryId) => {
|
||||
// existingEntryId is what the sheet already persisted in an earlier
|
||||
@@ -531,6 +619,7 @@ export default function MJourneyDetail() {
|
||||
onSaved={() => { setShowSettings(false); loadJourney(Number(id)) }}
|
||||
onOpenInvite={() => setShowInvite(true)}
|
||||
onRefresh={() => loadJourney(Number(id))}
|
||||
onRestoreSuggestions={canEditEntries ? restoreSuggestions : undefined}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
// FE-COMP-MJOURNEYCARD-001 to FE-COMP-MJOURNEYCARD-003
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { render, screen } from '../../../../tests/helpers/render'
|
||||
import MJourneyEntryCard from './MJourneyEntryCard'
|
||||
import type { JourneyEntry } from '../../../store/journeyStore'
|
||||
|
||||
// #2022: a long entry comment grew the card, and with it the bottom-anchored
|
||||
// carousel, until the timeline covered the map. jsdom does no layout, so these
|
||||
// assert the class contract the browser cascade depends on, not pixel heights.
|
||||
const LONG_STORY = Array.from({ length: 400 }, (_, i) => `wort${i % 7}`).join(' ')
|
||||
|
||||
// Tailwind emits the display plugin AFTER lineClamp, so any display utility on
|
||||
// the same element overrides `line-clamp-*`'s own `-webkit-box` and the clamp
|
||||
// silently stops working.
|
||||
const DISPLAY_UTILITIES = ['block', 'inline-block', 'flex', 'inline-flex', 'grid', 'inline-grid', 'flow-root', 'contents', 'inline']
|
||||
|
||||
const buildEntry = (overrides: Partial<JourneyEntry> = {}): JourneyEntry => ({
|
||||
id: 1,
|
||||
journey_id: 7,
|
||||
author_id: 1,
|
||||
type: 'entry',
|
||||
title: 'Erster Tag',
|
||||
story: LONG_STORY,
|
||||
entry_date: '2026-03-03',
|
||||
visibility: 'private',
|
||||
sort_order: 0,
|
||||
photos: [],
|
||||
created_at: 0,
|
||||
updated_at: 0,
|
||||
...overrides,
|
||||
})
|
||||
|
||||
describe('MJourneyEntryCard', () => {
|
||||
it('FE-COMP-MJOURNEYCARD-001: keeps the story preview clamp free of a competing display utility', () => {
|
||||
render(<MJourneyEntryCard entry={buildEntry()} number={1} onClick={vi.fn()} />)
|
||||
|
||||
const classes = screen.getByText(LONG_STORY).className.split(/\s+/)
|
||||
expect(classes).toContain('line-clamp-2')
|
||||
DISPLAY_UTILITIES.forEach(utility => expect(classes).not.toContain(utility))
|
||||
})
|
||||
|
||||
it('FE-COMP-MJOURNEYCARD-002: caps the card height so the timeline cannot grow over the map', () => {
|
||||
render(<MJourneyEntryCard entry={buildEntry()} number={1} onClick={vi.fn()} />)
|
||||
|
||||
const classes = screen.getByRole('button').className.split(/\s+/)
|
||||
expect(classes.some(c => /^max-h-\[\d+px\]$/.test(c))).toBe(true)
|
||||
expect(classes).toContain('overflow-hidden')
|
||||
})
|
||||
|
||||
it('FE-COMP-MJOURNEYCARD-003: renders no preview for an entry without a story', () => {
|
||||
render(<MJourneyEntryCard entry={buildEntry({ story: null })} number={2} onClick={vi.fn()} />)
|
||||
|
||||
expect(screen.queryByText(LONG_STORY)).not.toBeInTheDocument()
|
||||
expect(screen.getByText('Erster Tag')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -1,101 +0,0 @@
|
||||
import { MapPin, RouteOff } from 'lucide-react'
|
||||
import { useTranslation } from '../../../i18n'
|
||||
import { formatLocationName } from '../../../utils/formatters'
|
||||
import { stripMarkdown } from '../../../components/Journey/stripMarkdown'
|
||||
import type { JourneyEntry } from '../../../store/journeyStore'
|
||||
import { moodMeta, weatherMeta } from './mobileJourneyMeta'
|
||||
|
||||
interface MJourneyEntryCardProps {
|
||||
entry: JourneyEntry
|
||||
number: number
|
||||
onClick: () => void
|
||||
}
|
||||
|
||||
/** One 280px card of the horizontal journey timeline (photo column, number badge, mood/weather dots). */
|
||||
export default function MJourneyEntryCard({ entry, number, onClick }: MJourneyEntryCardProps) {
|
||||
const { t, locale } = useTranslation()
|
||||
const firstPhoto = entry.photos?.[0]
|
||||
const mood = moodMeta(entry.mood)
|
||||
const weather = weatherMeta(entry.weather)
|
||||
const location = formatLocationName(entry.location_name)
|
||||
|
||||
const dateLabel = new Date(entry.entry_date + 'T00:00:00').toLocaleDateString(locale, {
|
||||
day: 'numeric',
|
||||
month: 'short',
|
||||
})
|
||||
const storyPreview = entry.story ? stripMarkdown(entry.story) : ''
|
||||
const title = entry.title || (entry.type === 'checkin' ? t('journey.detail.journeyTab') : t('journey.editor.titlePlaceholder'))
|
||||
|
||||
// The timeline this card sits in is bottom-anchored with no height of its own, so a card
|
||||
// that grows with its story climbs over the map and swallows its touches (#2022). Cap the
|
||||
// card at the height the old journey timeline pins its active card to.
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClick}
|
||||
className="flex max-h-[140px] w-[280px] flex-none gap-[11px] overflow-hidden rounded-[20px] bg-[color:var(--m-sheet)] p-[11px] text-left shadow-[0_16px_40px_-18px_rgba(0,0,0,.5)]"
|
||||
>
|
||||
{firstPhoto && (
|
||||
<span className="flex w-16 flex-none flex-col gap-[5px]">
|
||||
<img
|
||||
src={`/api/photos/${firstPhoto.photo_id}/thumbnail`}
|
||||
alt=""
|
||||
loading="lazy"
|
||||
className="h-16 w-16 rounded-[13px] object-cover"
|
||||
/>
|
||||
{location && (
|
||||
<span className="inline-flex items-center justify-center gap-[3px] overflow-hidden truncate whitespace-nowrap rounded-full bg-[color:var(--m-ic)] px-[6px] py-[2px] font-geist text-[0.53125rem] font-bold text-m-muted">
|
||||
<MapPin size={8} strokeWidth={2.4} className="flex-none" />
|
||||
<span className="truncate">{location}</span>
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="flex items-center gap-[6px]">
|
||||
<span className="flex h-5 w-5 flex-none items-center justify-center rounded-full bg-[#4A5BD4] text-[0.625rem] font-extrabold text-white">
|
||||
{number}
|
||||
</span>
|
||||
<span className="whitespace-nowrap rounded-full bg-[color:var(--m-ic)] px-2 py-[2px] font-geist text-[0.5625rem] font-bold text-m-muted">
|
||||
{dateLabel}
|
||||
</span>
|
||||
{/* Switched off the printed route (#2064). Shrinks before the date does. */}
|
||||
{entry.stats_excluded && (
|
||||
<span className="inline-flex min-w-0 items-center gap-[3px] overflow-hidden truncate whitespace-nowrap rounded-full bg-[color:var(--m-ic)] px-2 py-[2px] font-geist text-[0.5625rem] font-bold text-m-muted">
|
||||
<RouteOff size={9} strokeWidth={2.4} className="flex-none" />
|
||||
<span className="truncate">{t('journey.entry.offRoute')}</span>
|
||||
</span>
|
||||
)}
|
||||
<span className="ml-auto flex gap-1">
|
||||
{mood && (
|
||||
<span
|
||||
className="flex h-[18px] w-[18px] items-center justify-center rounded-full"
|
||||
style={{ background: `${mood.color}22`, color: mood.color }}
|
||||
>
|
||||
<mood.icon size={11} strokeWidth={2.2} />
|
||||
</span>
|
||||
)}
|
||||
{weather && (
|
||||
<span className="flex h-[18px] w-[18px] items-center justify-center rounded-full bg-[color:var(--m-ic)] text-m-muted">
|
||||
<weather.icon size={11} strokeWidth={2.2} />
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
</span>
|
||||
<span className="mt-1 block truncate text-[0.875rem] font-extrabold">{title}</span>
|
||||
{/* No display utility on the preview: Tailwind emits it after line-clamp-2 and would kill the clamp. */}
|
||||
{storyPreview && (
|
||||
<span className="mt-[2px] font-geist text-[0.65625rem] leading-[1.4] text-m-muted line-clamp-2">
|
||||
{storyPreview}
|
||||
</span>
|
||||
)}
|
||||
{!firstPhoto && location && (
|
||||
<span className="mt-[6px] inline-flex max-w-full items-center gap-1 rounded-full bg-[color:var(--m-ic)] px-2 py-[2px] font-geist text-[0.5625rem] font-bold text-m-muted">
|
||||
<MapPin size={9} strokeWidth={2.4} className="flex-none" />
|
||||
<span className="truncate">{location}</span>
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
</button>
|
||||
)
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { localIsoDate } from '../../../utils/localDate'
|
||||
import { Camera, Plus, Image, Images, X, MapPin, Locate, Trash2, CheckCircle2, MinusCircle } from 'lucide-react'
|
||||
import { Camera, Plus, Image, Images, X, MapPin, Locate, Trash2, CheckCircle2, MinusCircle, ChevronUp, ChevronDown, EyeOff } from 'lucide-react'
|
||||
import MSheet from '../../components/MSheet'
|
||||
import MIconBtn from '../../components/MIconBtn'
|
||||
import MToggle from '../../components/MToggle'
|
||||
@@ -39,6 +39,22 @@ interface MJourneyEntrySheetProps {
|
||||
readOnly?: boolean
|
||||
userId?: number
|
||||
trips?: JourneyTrip[]
|
||||
/** The optional fields this journey still keeps (discussion #2299). Values are never cleared. */
|
||||
showVerdict?: boolean
|
||||
showMood?: boolean
|
||||
showWeather?: boolean
|
||||
/**
|
||||
* Move this entry within its day.
|
||||
*
|
||||
* The desktop feed has arrows beside every card; the phone had no way to
|
||||
* reorder at all, so a day's stops stayed in whatever order they were written
|
||||
* (discussion #2299). Absent when the entry is alone on its day, is a
|
||||
* suggestion, or the reader cannot edit.
|
||||
*/
|
||||
onMoveEarlier?: () => void
|
||||
onMoveLater?: () => void
|
||||
/** Wave a trip-derived suggestion away. Only ever passed for a skeleton. */
|
||||
onDismiss?: () => void
|
||||
onClose: () => void
|
||||
onSave: (data: Record<string, unknown>, existingEntryId?: number) => Promise<number>
|
||||
onUploadPhotos: (entryId: number, files: File[], cbs?: { onProgress?: (p: UploadProgress) => void }) => Promise<ResilientResult<JourneyPhoto>>
|
||||
@@ -54,10 +70,13 @@ interface MJourneyEntrySheetProps {
|
||||
*/
|
||||
export default function MJourneyEntrySheet({
|
||||
entry, galleryPhotos, quickCapture = false, readOnly = false, userId = 0, trips = [],
|
||||
showVerdict = true, showMood = true, showWeather = true, onMoveEarlier, onMoveLater, onDismiss,
|
||||
onClose, onSave, onUploadPhotos, onAddProviderPhotos, onDelete, onDone,
|
||||
}: MJourneyEntrySheetProps) {
|
||||
const { t, language } = useTranslation()
|
||||
const toast = useToast()
|
||||
// Which verdict row to hand the caret after the next render — see addVerdictRow.
|
||||
const verdictFocusRef = useRef<string | null>(null)
|
||||
|
||||
const [title, setTitle] = useState(entry.title || '')
|
||||
const [story, setStory] = useState(entry.story || '')
|
||||
@@ -199,6 +218,29 @@ export default function MJourneyEntrySheet({
|
||||
pendingLinkIds.length > 0 ||
|
||||
pendingProviderGroups.length > 0
|
||||
|
||||
/**
|
||||
* Enter opens the next pro or con, directly below the one you are in.
|
||||
*
|
||||
* Same behaviour and same reason as the desktop editor: a list of short things
|
||||
* should not need a button press between every item (discussion #2299). On a
|
||||
* phone keyboard the return key is right there, which is more of a gain than
|
||||
* it is with a mouse.
|
||||
*/
|
||||
const addVerdictRow = (list: 'pros' | 'cons', index: number) => {
|
||||
const [values, setValues] = list === 'pros' ? [pros, setPros] as const : [cons, setCons] as const
|
||||
const next = [...values]
|
||||
next.splice(index + 1, 0, '')
|
||||
setValues(next)
|
||||
verdictFocusRef.current = `${list}-${index + 1}`
|
||||
}
|
||||
|
||||
const verdictRowRef = (key: string) => (el: HTMLInputElement | null) => {
|
||||
if (el && verdictFocusRef.current === key) {
|
||||
verdictFocusRef.current = null
|
||||
el.focus()
|
||||
}
|
||||
}
|
||||
|
||||
const handleClose = () => {
|
||||
if (!captureOnly && !readOnly && isDirty && !window.confirm(t('journey.editor.discardChangesConfirm'))) return
|
||||
onClose()
|
||||
@@ -353,13 +395,28 @@ export default function MJourneyEntrySheet({
|
||||
<span className="flex-1 text-[1.0625rem] font-bold">
|
||||
{entry.id === 0 ? t('journey.detail.newEntry') : t('journey.detail.editEntry')}
|
||||
</span>
|
||||
{(onMoveEarlier || onMoveLater) && (
|
||||
<span className="mr-1 flex items-center gap-1">
|
||||
<MIconBtn variant="neutral" size={34} onClick={() => onMoveEarlier?.()} disabled={!onMoveEarlier} ariaLabel={t('dayplan.moveUp')}>
|
||||
<ChevronUp size={15} strokeWidth={2.4} />
|
||||
</MIconBtn>
|
||||
<MIconBtn variant="neutral" size={34} onClick={() => onMoveLater?.()} disabled={!onMoveLater} ariaLabel={t('dayplan.moveDown')}>
|
||||
<ChevronDown size={15} strokeWidth={2.4} />
|
||||
</MIconBtn>
|
||||
</span>
|
||||
)}
|
||||
<MIconBtn variant="neutral" size={34} onClick={handleClose} ariaLabel={t('common.cancel')}>
|
||||
<X size={15} strokeWidth={2.2} />
|
||||
</MIconBtn>
|
||||
</div>
|
||||
|
||||
<div className="min-h-0 flex-1 overflow-y-auto px-[18px] py-3">
|
||||
{!captureOnly && (readOnly ? (
|
||||
{/* Quick capture had no title field at all: it asked for a note and nothing
|
||||
else, so every entry caught on the move arrived nameless and the day's
|
||||
list read as a column of identical placeholders (discussion #2299). The
|
||||
name is the one thing that makes an entry findable later, and it is one
|
||||
line to type, so it comes first here too. */}
|
||||
{readOnly ? (
|
||||
<div className="pb-[10px] pt-1 text-[1.25rem] font-extrabold">{title || t('journey.editor.titlePlaceholder')}</div>
|
||||
) : (
|
||||
<input
|
||||
@@ -368,7 +425,7 @@ export default function MJourneyEntrySheet({
|
||||
placeholder={t('journey.editor.titlePlaceholder')}
|
||||
className="w-full bg-transparent pb-[10px] pt-1 text-[1.25rem] font-extrabold text-m-ink outline-none placeholder:text-m-faint"
|
||||
/>
|
||||
))}
|
||||
)}
|
||||
|
||||
{!readOnly && (
|
||||
<>
|
||||
@@ -646,8 +703,8 @@ export default function MJourneyEntrySheet({
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Pros & Cons */}
|
||||
{(!readOnly || pros.length > 0 || cons.length > 0) && (
|
||||
{/* Pros & Cons — gone when the journey has put the verdict away (#2299) */}
|
||||
{showVerdict && (!readOnly || pros.length > 0 || cons.length > 0) && (
|
||||
<div className="mt-3 rounded-2xl border border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)] p-[13px]">
|
||||
<div className={`${eyebrow} mb-2`}>{t('journey.editor.prosCons')}</div>
|
||||
<div className="flex gap-[10px]">
|
||||
@@ -660,9 +717,11 @@ export default function MJourneyEntrySheet({
|
||||
<div key={i} className="mb-[6px] flex items-center gap-[6px] rounded-[10px] border border-[color:var(--m-rowbr)] bg-m-sheetop px-2 py-[6px]">
|
||||
<span className="h-[5px] w-[5px] flex-none rounded-full" style={{ background: PRO_COLOR }} />
|
||||
<input
|
||||
ref={verdictRowRef(`pros-${i}`)}
|
||||
value={p}
|
||||
readOnly={readOnly}
|
||||
onChange={e => { const next = [...pros]; next[i] = e.target.value; setPros(next) }}
|
||||
onKeyDown={e => { if (e.key === 'Enter') { e.preventDefault(); addVerdictRow('pros', i) } }}
|
||||
placeholder={t('journey.editor.proPlaceholder')}
|
||||
className="min-w-0 flex-1 bg-transparent font-geist text-[0.6875rem] font-semibold text-m-ink outline-none placeholder:text-m-faint"
|
||||
/>
|
||||
@@ -676,7 +735,7 @@ export default function MJourneyEntrySheet({
|
||||
{!readOnly && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setPros([...pros, ''])}
|
||||
onClick={() => addVerdictRow('pros', pros.length - 1)}
|
||||
className="block w-full rounded-[10px] border border-dashed py-[9px] text-center font-geist text-[0.6875rem] font-semibold"
|
||||
style={{ borderColor: 'rgba(47,163,122,.35)', color: PRO_COLOR }}
|
||||
>
|
||||
@@ -693,9 +752,11 @@ export default function MJourneyEntrySheet({
|
||||
<div key={i} className="mb-[6px] flex items-center gap-[6px] rounded-[10px] border border-[color:var(--m-rowbr)] bg-m-sheetop px-2 py-[6px]">
|
||||
<span className="h-[5px] w-[5px] flex-none rounded-full" style={{ background: CON_COLOR }} />
|
||||
<input
|
||||
ref={verdictRowRef(`cons-${i}`)}
|
||||
value={c}
|
||||
readOnly={readOnly}
|
||||
onChange={e => { const next = [...cons]; next[i] = e.target.value; setCons(next) }}
|
||||
onKeyDown={e => { if (e.key === 'Enter') { e.preventDefault(); addVerdictRow('cons', i) } }}
|
||||
placeholder={t('journey.editor.conPlaceholder')}
|
||||
className="min-w-0 flex-1 bg-transparent font-geist text-[0.6875rem] font-semibold text-m-ink outline-none placeholder:text-m-faint"
|
||||
/>
|
||||
@@ -709,7 +770,7 @@ export default function MJourneyEntrySheet({
|
||||
{!readOnly && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setCons([...cons, ''])}
|
||||
onClick={() => addVerdictRow('cons', cons.length - 1)}
|
||||
className="block w-full rounded-[10px] border border-dashed py-[9px] text-center font-geist text-[0.6875rem] font-semibold"
|
||||
style={{ borderColor: 'rgba(214,39,59,.35)', color: CON_COLOR }}
|
||||
>
|
||||
@@ -811,7 +872,7 @@ export default function MJourneyEntrySheet({
|
||||
)}
|
||||
|
||||
{/* Mood */}
|
||||
{!captureOnly && <>
|
||||
{showMood && !captureOnly && <>
|
||||
<div className={`${eyebrow} mb-[6px] mt-3`}>{t('journey.editor.mood')}</div>
|
||||
<div className="flex flex-wrap gap-[6px]">
|
||||
{MOBILE_MOODS.map(m => {
|
||||
@@ -836,6 +897,7 @@ export default function MJourneyEntrySheet({
|
||||
</>}
|
||||
|
||||
{/* Weather */}
|
||||
{showWeather && <>
|
||||
<div className={`${eyebrow} mb-[6px] mt-3`}>{t('journey.editor.weather')}</div>
|
||||
<div className="flex flex-wrap gap-[6px]">
|
||||
{MOBILE_WEATHERS.map(w => {
|
||||
@@ -858,6 +920,7 @@ export default function MJourneyEntrySheet({
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</>}
|
||||
|
||||
{/* Tags */}
|
||||
{!captureOnly && (!readOnly || tags.length > 0) && (
|
||||
@@ -905,6 +968,18 @@ export default function MJourneyEntrySheet({
|
||||
{t('common.delete')}
|
||||
</button>
|
||||
)}
|
||||
{/* A suggestion is not deleted, it is put down: the row survives so the trip
|
||||
sync does not offer the same place again (discussion #2299). */}
|
||||
{!readOnly && onDismiss && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onDismiss}
|
||||
className="flex items-center gap-[5px] text-[0.75rem] font-bold text-m-muted"
|
||||
>
|
||||
<EyeOff size={13} strokeWidth={2} />
|
||||
{t('journey.suggestions.dismiss')}
|
||||
</button>
|
||||
)}
|
||||
{!readOnly && captureOnly && (
|
||||
<button
|
||||
type="button"
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useEffect, useRef, useState } from 'react'
|
||||
import { useNavigate } from 'react-router'
|
||||
import {
|
||||
X, Image, Plus, Trash2, UserPlus, Link as LinkIcon,
|
||||
List, Grid3x3, MapPin, Route, Archive, ArchiveRestore,
|
||||
List, Grid3x3, MapPin, Route, Archive, ArchiveRestore, Undo2,
|
||||
} from 'lucide-react'
|
||||
import MSheet from '../../components/MSheet'
|
||||
import MIconBtn from '../../components/MIconBtn'
|
||||
@@ -38,6 +38,8 @@ interface MJourneySettingsSheetProps {
|
||||
onSaved: () => void
|
||||
onOpenInvite: () => void
|
||||
onRefresh: () => void
|
||||
/** Bring back every suggestion waved away card by card. Absent for a viewer. */
|
||||
onRestoreSuggestions?: () => Promise<void> | void
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,7 +47,7 @@ interface MJourneySettingsSheetProps {
|
||||
* with per-section toggles (timeline / gallery / map), archive and delete.
|
||||
*/
|
||||
export default function MJourneySettingsSheet({
|
||||
journey, onClose, onSaved, onOpenInvite, onRefresh,
|
||||
journey, onClose, onSaved, onOpenInvite, onRefresh, onRestoreSuggestions,
|
||||
}: MJourneySettingsSheetProps) {
|
||||
const { t } = useTranslation()
|
||||
const toast = useToast()
|
||||
@@ -115,6 +117,26 @@ export default function MJourneySettingsSheet({
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn one of the optional entry fields off for this journey (discussion #2299).
|
||||
*
|
||||
* Written on the spot and through onRefresh, for the same two reasons the tracks
|
||||
* switch above is. Nothing stored is erased: the form stops asking, the values
|
||||
* stay, and switching back on brings them into view.
|
||||
*/
|
||||
const [savingField, setSavingField] = useState<string | null>(null)
|
||||
const handleFieldToggle = async (field: 'show_verdict' | 'show_mood' | 'show_weather', next: boolean) => {
|
||||
setSavingField(field)
|
||||
try {
|
||||
await updateJourney(journey.id, { [field]: next })
|
||||
onRefresh()
|
||||
} catch {
|
||||
toast.error(t('journey.settings.saveFailed'))
|
||||
} finally {
|
||||
setSavingField(null)
|
||||
}
|
||||
}
|
||||
|
||||
const openAddTrip = async () => {
|
||||
setAddTripOpen(v => !v)
|
||||
if (availableTrips.length === 0) {
|
||||
@@ -269,6 +291,42 @@ export default function MJourneySettingsSheet({
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* The three fields a journey may put away (discussion #2299) */}
|
||||
<div className={`${eyebrow} mb-[6px] mt-[14px]`}>{t('journey.settings.entryFields')}</div>
|
||||
<div className="mb-[6px] font-geist text-[0.625rem] leading-[1.45] text-m-muted">{t('journey.settings.entryFieldsHint')}</div>
|
||||
{([
|
||||
['show_verdict', t('journey.settings.showVerdict')],
|
||||
['show_mood', t('journey.settings.showMood')],
|
||||
['show_weather', t('journey.settings.showWeather')],
|
||||
] as const).map(([field, label]) => (
|
||||
<div key={field} className="mb-[6px] flex items-center gap-[11px] rounded-[14px] bg-[color:var(--m-ic)] px-3 py-[10px]">
|
||||
<div className="min-w-0 flex-1 text-[0.8125rem] font-bold">{label}</div>
|
||||
<MToggle
|
||||
checked={journey[field] !== 0}
|
||||
onChange={next => handleFieldToggle(field, next)}
|
||||
disabled={savingField !== null}
|
||||
ariaLabel={label}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
|
||||
{/* Only when there is something to bring back */}
|
||||
{onRestoreSuggestions && (journey.dismissed_count ?? 0) > 0 && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => { void onRestoreSuggestions() }}
|
||||
className="mb-[6px] flex w-full items-center gap-[11px] rounded-[14px] bg-[color:var(--m-ic)] px-3 py-[10px] text-left"
|
||||
>
|
||||
<Undo2 size={16} strokeWidth={2} className="flex-none text-m-muted" />
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="text-[0.8125rem] font-bold">{t('journey.suggestions.restore')}</div>
|
||||
<div className="font-geist text-[0.625rem] text-m-muted">
|
||||
{t('journey.suggestions.restoreCount', { count: String(journey.dismissed_count) })}
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
)}
|
||||
|
||||
{/* Synced trips */}
|
||||
<div className={`${eyebrow} mb-[6px] mt-[14px]`}>{t('journey.detail.syncedTrips')}</div>
|
||||
{journey.trips.map(trip => (
|
||||
|
||||
Reference in New Issue
Block a user