mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-02 09:22:15 +00:00
feat(places): notes, visits, tours, history, tags and location in the place sheet, saved lists on the trip map
Both the desktop sheet and the phone sheet of All places show the place's location as a badge, its notes per list, its visits from trips (hidden without any), linked tours and bookings, its change history and the reader's own tags with a tag filter. A trip map can show the places of linked lists and add one to the trip. All places reloads after a list is added or removed.
This commit is contained in:
@@ -3,6 +3,7 @@ import Markdown from 'react-markdown'
|
||||
import remarkGfm from 'remark-gfm'
|
||||
import remarkBreaks from 'remark-breaks'
|
||||
import { Camera, Check, Copy, ExternalLink, Loader2, MapPin, Navigation, Pencil, Trash2, X } from 'lucide-react'
|
||||
import PlaceLocationBadge from '../../../components/Collections/PlaceLocationBadge'
|
||||
import type { CollectionLabel, CollectionLink, CollectionPlace, CollectionStatus } from '@trek/shared'
|
||||
import type { Category, TranslationFn } from '../../../types'
|
||||
import { useCollectionPlaceForm } from '../../../components/Collections/useCollectionPlaceForm'
|
||||
@@ -119,14 +120,10 @@ export default function MCollPlaceSheet({
|
||||
</div>
|
||||
</div>
|
||||
<div className="relative mt-1 text-[1.3125rem] font-extrabold text-white">{held.name}</div>
|
||||
{!editing && <div className="relative"><PlaceLocationBadge address={held.address} lat={held.lat} lng={held.lng} t={t} /></div>}
|
||||
</div>
|
||||
|
||||
<div className="min-h-0 flex-1 overflow-y-auto px-[18px] pb-[18px] pt-[14px]">
|
||||
{!editing && held.address && (
|
||||
<div className="flex items-start gap-[6px] font-geist text-[0.75rem] leading-[1.5] text-m-muted">
|
||||
<MapPin size={13} strokeWidth={2} className="mt-[1px] flex-none" /> {held.address}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Status cycle: two by two on a phone, so every label keeps its room */}
|
||||
<div className="mt-3 grid grid-cols-2 gap-[6px] wide:grid-cols-4">
|
||||
|
||||
@@ -21,7 +21,7 @@ interface MCollTripPickerSheetProps {
|
||||
* selected places and reconciles the dedup result into toasts.
|
||||
*/
|
||||
export default function MCollTripPickerSheet({ open, count, onCopy, carryOptions, onClose, t }: MCollTripPickerSheetProps) {
|
||||
const { loading, search, setSearch, filtered, busyTripId, dateRange, handleCopy, offersCarry, includeNotes, setIncludeNotes, tagIds, toggleTag } =
|
||||
const { loading, search, setSearch, filtered, busyTripId, dateRange, handleCopy, offersCarry, includeNotes, setIncludeNotes, tagIds, toggleTag, personalTagIds, togglePersonalTag } =
|
||||
useTripCopyPicker({ open, onCopy, onClose, t, carryOptions })
|
||||
|
||||
const title = t('collections.copyN', { count })
|
||||
@@ -42,7 +42,7 @@ export default function MCollTripPickerSheet({ open, count, onCopy, carryOptions
|
||||
</div>
|
||||
{offersCarry && carryOptions && (
|
||||
<div className="mb-3">
|
||||
<CopyCarryPanel options={carryOptions} includeNotes={includeNotes} onIncludeNotes={setIncludeNotes} tagIds={tagIds} onToggleTag={toggleTag} variant="sheet" t={t} />
|
||||
<CopyCarryPanel options={carryOptions} includeNotes={includeNotes} onIncludeNotes={setIncludeNotes} tagIds={tagIds} onToggleTag={toggleTag} personalTagIds={personalTagIds} onTogglePersonalTag={togglePersonalTag} variant="sheet" t={t} />
|
||||
</div>
|
||||
)}
|
||||
{loading ? (
|
||||
|
||||
@@ -651,7 +651,6 @@ function SelectionAction({ label, onClick, disabled, danger = false, children }:
|
||||
onClick={onClick}
|
||||
disabled={disabled}
|
||||
aria-label={label}
|
||||
title={label}
|
||||
className={`flex h-10 min-w-0 flex-1 items-center justify-center rounded-full border border-[color:var(--m-rowbr)] bg-m-sheetop disabled:opacity-40 ${danger ? 'text-[color:var(--m-st-danger)]' : 'text-m-ink'}`}
|
||||
>
|
||||
{children}
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
import type { PlacesLibraryDetailResponse, Tag as TagRow } from '@trek/shared';
|
||||
import { Check, Pencil, Plus, Trash2, X } from 'lucide-react';
|
||||
import { useState } from 'react';
|
||||
import { useEntryTags } from '../../../components/Collections/useEntryTags';
|
||||
import ConfirmDialog from '../../../components/shared/ConfirmDialog';
|
||||
import type { TranslationFn } from '../../../types';
|
||||
import { Eyebrow, INPUT_CLS } from './MCollSheetKit';
|
||||
|
||||
type EntryTags = ReturnType<typeof useEntryTags>;
|
||||
|
||||
function Dot({ color }: { color: string | null | undefined }) {
|
||||
// The tag's own colour, the one data-driven value of the chip.
|
||||
return <span className="h-2 w-2 flex-none rounded-full" style={{ background: color || 'var(--m-act)' }} />;
|
||||
}
|
||||
|
||||
const ICON_BTN = 'flex h-8 w-8 flex-none items-center justify-center rounded-full bg-m-ic text-m-muted';
|
||||
|
||||
/** One tag in the phone's picker: ticked when the place carries it, renamed or deleted in place. */
|
||||
function MTagRow({ tag, on, tags, t }: { tag: TagRow; on: boolean; tags: EntryTags; t: TranslationFn }) {
|
||||
const [editing, setEditing] = useState(false);
|
||||
const [name, setName] = useState(String(tag.name));
|
||||
const [confirm, setConfirm] = useState(false);
|
||||
if (editing) {
|
||||
return (
|
||||
<form
|
||||
className="flex items-center gap-2 py-1"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
void tags.rename(tag.id, name);
|
||||
setEditing(false);
|
||||
}}
|
||||
>
|
||||
<input
|
||||
autoFocus
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
aria-label={t('placeTags.rename')}
|
||||
className={INPUT_CLS}
|
||||
/>
|
||||
<button type="submit" aria-label={t('common.save')} className={ICON_BTN}>
|
||||
<Check size={14} />
|
||||
</button>
|
||||
<button type="button" onClick={() => setEditing(false)} aria-label={t('common.cancel')} className={ICON_BTN}>
|
||||
<X size={14} />
|
||||
</button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div className="flex items-center gap-2 py-1">
|
||||
<button
|
||||
type="button"
|
||||
aria-pressed={on}
|
||||
onClick={() => void tags.toggle(tag.id)}
|
||||
className="flex min-w-0 flex-1 items-center gap-2 py-1 text-start text-body text-m-ink"
|
||||
>
|
||||
<Dot color={tag.color} />
|
||||
<span className="min-w-0 flex-1 truncate">{tag.name}</span>
|
||||
{on && <Check size={15} className="flex-none" />}
|
||||
</button>
|
||||
<button type="button" onClick={() => setEditing(true)} aria-label={t('placeTags.rename')} className={ICON_BTN}>
|
||||
<Pencil size={13} />
|
||||
</button>
|
||||
<button type="button" onClick={() => setConfirm(true)} aria-label={t('placeTags.delete')} className={ICON_BTN}>
|
||||
<Trash2 size={13} />
|
||||
</button>
|
||||
<ConfirmDialog
|
||||
isOpen={confirm}
|
||||
onClose={() => setConfirm(false)}
|
||||
onConfirm={() => void tags.destroy(tag.id)}
|
||||
title={t('placeTags.deleteTitle', { name: String(tag.name) })}
|
||||
message={t('placeTags.deleteMessage')}
|
||||
confirmLabel={t('placeTags.delete')}
|
||||
danger
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** The reader's own tags on a place on the phone (PLC-21); the logic is the desktop sheet's. */
|
||||
export default function MEntryTagsSection({
|
||||
data,
|
||||
onChanged,
|
||||
t,
|
||||
}: {
|
||||
data: PlacesLibraryDetailResponse | null;
|
||||
onChanged: () => void;
|
||||
t: TranslationFn;
|
||||
}) {
|
||||
const tags = useEntryTags({ entry: data?.entry ?? null, onChanged, t });
|
||||
const [open, setOpen] = useState(false);
|
||||
return (
|
||||
<>
|
||||
<div className="mb-[6px] mt-4 flex items-center gap-2">
|
||||
<Eyebrow>{t('placeTags.title').toUpperCase()}</Eyebrow>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpen((o) => !o)}
|
||||
aria-expanded={open}
|
||||
aria-label={open ? t('common.close') : t('placeTags.add')}
|
||||
className="ms-auto flex h-7 w-7 items-center justify-center rounded-full bg-m-ic text-m-ink"
|
||||
>
|
||||
{open ? <X size={14} /> : <Plus size={14} />}
|
||||
</button>
|
||||
</div>
|
||||
{tags.assigned.length > 0 ? (
|
||||
<div className="flex flex-wrap gap-[6px]">
|
||||
{tags.assigned.map((tag) => (
|
||||
<span
|
||||
key={tag.id}
|
||||
className="inline-flex items-center gap-1.5 rounded-full border border-m-rowbr bg-m-ic px-[10px] py-[5px] text-caption font-semibold text-m-ink"
|
||||
>
|
||||
<Dot color={tag.color} />
|
||||
{tag.name}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
!open && <p className="m-0 text-caption text-m-muted">{t('placeTags.private')}</p>
|
||||
)}
|
||||
{open && (
|
||||
<div className="mt-2 rounded-2xl border border-m-rowbr bg-m-sheetop p-3">
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
if (tags.canCreate) void tags.createAndAdd();
|
||||
}}
|
||||
>
|
||||
<input
|
||||
value={tags.query}
|
||||
onChange={(e) => tags.setQuery(e.target.value)}
|
||||
placeholder={t('placeTags.search')}
|
||||
aria-label={t('placeTags.search')}
|
||||
className={INPUT_CLS}
|
||||
/>
|
||||
</form>
|
||||
<div className="mt-2 max-h-[260px] overflow-y-auto">
|
||||
{tags.matches.map((tag) => (
|
||||
<MTagRow key={tag.id} tag={tag} on={tags.assignedIds.includes(tag.id)} tags={tags} t={t} />
|
||||
))}
|
||||
{tags.matches.length === 0 && !tags.canCreate && (
|
||||
<p className="m-0 py-2 text-caption text-m-muted">{t('placeTags.none')}</p>
|
||||
)}
|
||||
</div>
|
||||
{tags.canCreate && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void tags.createAndAdd()}
|
||||
disabled={tags.busy}
|
||||
className="mt-1 flex w-full items-center gap-2 py-2 text-start text-body font-semibold text-m-ink"
|
||||
>
|
||||
<Plus size={15} /> {t('placeTags.create', { name: tags.query.trim() })}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,20 +1,5 @@
|
||||
import type { PlacesLibraryDetailResponse } from '@trek/shared';
|
||||
import {
|
||||
Bookmark,
|
||||
BookmarkPlus,
|
||||
ChevronRight,
|
||||
Copy,
|
||||
Hotel,
|
||||
Loader2,
|
||||
Luggage,
|
||||
MapPin,
|
||||
MapPinOff,
|
||||
Navigation,
|
||||
NotebookPen,
|
||||
Star,
|
||||
Ticket,
|
||||
X,
|
||||
} from 'lucide-react';
|
||||
import { BookmarkPlus, ChevronRight, Copy, Hotel, Loader2, Luggage, Navigation, Star, Ticket, X } from 'lucide-react';
|
||||
import { createElement, useRef, useState } from 'react';
|
||||
import { tripLine } from '../../../components/Collections/libraryDates';
|
||||
import {
|
||||
@@ -24,7 +9,9 @@ import {
|
||||
type TripOrigin,
|
||||
type TripPair,
|
||||
} from '../../../components/Collections/libraryPairs';
|
||||
import { listIcon } from '../../../components/Collections/listIcons';
|
||||
import { originName } from '../../../components/Collections/originName';
|
||||
import PlaceLocationBadge from '../../../components/Collections/PlaceLocationBadge';
|
||||
import {
|
||||
getNavigationTargets,
|
||||
navigationTargetLabel,
|
||||
@@ -37,6 +24,12 @@ import MSheet from '../../components/MSheet';
|
||||
import { categoryMeta, STATUS_SPEC, tint, UNCATEGORIZED_META } from './collectionsMobileModel';
|
||||
import './libraryCover.css';
|
||||
import { Eyebrow } from './MCollSheetKit';
|
||||
import MEntryTagsSection from './MEntryTagsSection';
|
||||
import MOriginNotesSection from './MOriginNotesSection';
|
||||
import MPlaceActivitiesSection from './MPlaceActivitiesSection';
|
||||
import MPlaceHistorySection from './MPlaceHistorySection';
|
||||
import MPlaceMediaSection from './MPlaceMediaSection';
|
||||
import MVisitsSection from './MVisitsSection';
|
||||
|
||||
interface MLibraryPlaceSheetProps {
|
||||
open: boolean;
|
||||
@@ -49,6 +42,8 @@ interface MLibraryPlaceSheetProps {
|
||||
onOpenTrip: (tripId: number, placeId: number) => void;
|
||||
onSaveToList: (origin: TripOrigin, detail: TripDetail) => void;
|
||||
onCopyToTrip: (collectionPlaceId: number) => void;
|
||||
/** A note was saved: read the place again. */
|
||||
onNotesSaved: () => void;
|
||||
t: TranslationFn;
|
||||
}
|
||||
|
||||
@@ -59,20 +54,6 @@ const CHIP =
|
||||
const ACTION =
|
||||
'flex flex-1 items-center justify-center gap-[6px] rounded-[13px] border border-m-rowbr bg-m-sheet px-2 py-[11px] text-caption font-semibold text-m-ink';
|
||||
|
||||
function Notes({ text, t }: { text: string | null; t: TranslationFn }) {
|
||||
if (!text?.trim()) return null;
|
||||
return (
|
||||
<span className="block rounded-xl bg-m-ic px-3 py-2">
|
||||
<span className="flex items-center gap-1 text-caption font-semibold text-m-faint">
|
||||
<NotebookPen size={11} /> {t('collections.notes')}
|
||||
</span>
|
||||
<span dir="auto" className="mt-1 block whitespace-pre-wrap text-body text-m-ink">
|
||||
{text}
|
||||
</span>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
type Entry = NonNullable<PlacesLibraryDetailResponse['entry']>;
|
||||
|
||||
/** The cover band: the picture or a gradient, the category, the close button and the name. */
|
||||
@@ -116,9 +97,12 @@ function SheetCover({
|
||||
</button>
|
||||
</div>
|
||||
{entry && (
|
||||
<h2 dir="auto" className="m-libcover-name absolute inset-x-4 bottom-3 m-0 truncate text-title font-extrabold">
|
||||
{entry.name}
|
||||
</h2>
|
||||
<div className="absolute inset-x-4 bottom-3 min-w-0">
|
||||
<h2 dir="auto" className="m-libcover-name m-0 truncate text-title font-extrabold">
|
||||
{entry.name}
|
||||
</h2>
|
||||
<PlaceLocationBadge address={entry.address} lat={entry.lat} lng={entry.lng} t={t} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
@@ -149,8 +133,12 @@ function TripCard({
|
||||
aria-label={`${t('collections.library.openTrip')}: ${originName(origin)}`}
|
||||
>
|
||||
<span className="flex items-center gap-[10px]">
|
||||
<span className={ICO}>
|
||||
<Luggage size={15} />
|
||||
<span className={`${ICO} overflow-hidden`}>
|
||||
{origin.trip_cover ? (
|
||||
<img src={origin.trip_cover} alt="" className="h-full w-full object-cover" />
|
||||
) : (
|
||||
<Luggage size={15} />
|
||||
)}
|
||||
</span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span dir="auto" className="block truncate text-body font-bold text-m-ink">
|
||||
@@ -176,7 +164,6 @@ function TripCard({
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
<Notes text={detail.notes} t={t} />
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -205,8 +192,15 @@ function ListCard({
|
||||
aria-label={`${t('collections.library.openList')}: ${originName(origin)}`}
|
||||
>
|
||||
<span className="flex items-center gap-[10px]">
|
||||
<span className={ICO}>
|
||||
<Bookmark size={15} />
|
||||
<span
|
||||
className={ICO}
|
||||
// The list's own colour, the one data-driven value of the tile.
|
||||
style={{
|
||||
color: origin.collection_color || 'var(--m-act)',
|
||||
background: `color-mix(in srgb, ${origin.collection_color || 'var(--m-act)'} 16%, var(--m-ic))`,
|
||||
}}
|
||||
>
|
||||
{createElement(listIcon(origin.collection_icon), { size: 15 })}
|
||||
</span>
|
||||
<span dir="auto" className="min-w-0 flex-1 truncate text-body font-bold text-m-ink">
|
||||
{originName(origin)}
|
||||
@@ -236,7 +230,6 @@ function ListCard({
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
<Notes text={detail.notes} t={t} />
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -306,21 +299,12 @@ function SheetBody({
|
||||
onOpenTrip,
|
||||
onSaveToList,
|
||||
onCopyToTrip,
|
||||
onNotesSaved,
|
||||
t,
|
||||
}: Omit<MLibraryPlaceSheetProps, 'open' | 'loading' | 'cover' | 'onClose'> & { entry: Entry }) {
|
||||
const { trips, lists, description } = originPairs(data);
|
||||
return (
|
||||
<>
|
||||
{entry.address && (
|
||||
<p dir="auto" className="m-0 flex items-center gap-1 text-caption text-m-muted">
|
||||
<MapPin size={12} className="flex-none" /> {entry.address}
|
||||
</p>
|
||||
)}
|
||||
{(entry.lat == null || entry.lng == null) && (
|
||||
<p className="m-0 mt-1 flex items-center gap-1 text-caption text-m-muted">
|
||||
<MapPinOff size={12} className="flex-none text-warning" /> {t('places.noCoordinates')}
|
||||
</p>
|
||||
)}
|
||||
{description && (
|
||||
<p dir="auto" className="m-0 mt-3 whitespace-pre-wrap text-body text-m-ink">
|
||||
{description}
|
||||
@@ -359,6 +343,12 @@ function SheetBody({
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
<MEntryTagsSection data={data} onChanged={onNotesSaved} t={t} />
|
||||
<MOriginNotesSection data={data} onSaved={onNotesSaved} t={t} />
|
||||
<MPlaceMediaSection entry={entry} t={t} />
|
||||
<MVisitsSection entry={entry} language={language} t={t} />
|
||||
<MPlaceActivitiesSection entry={entry} language={language} t={t} />
|
||||
<MPlaceHistorySection entry={entry} language={language} t={t} />
|
||||
<SheetActions
|
||||
entry={entry}
|
||||
trip={trips[0]}
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
import type { PlacesLibraryDetailResponse } from '@trek/shared';
|
||||
import { Bookmark, Luggage, Pencil, Plus } from 'lucide-react';
|
||||
import { useOriginNotes } from '../../../components/Collections/useOriginNotes';
|
||||
import type { TranslationFn } from '../../../types';
|
||||
import { CancelPill, Eyebrow, PrimaryPill, TEXTAREA_CLS } from './MCollSheetKit';
|
||||
|
||||
/** The notes of a place on the phone (PLC-17), each with where it comes from; the logic is the desktop sheet's. */
|
||||
export default function MOriginNotesSection({
|
||||
data,
|
||||
onSaved,
|
||||
t,
|
||||
}: {
|
||||
data: PlacesLibraryDetailResponse | null;
|
||||
onSaved: () => void;
|
||||
t: TranslationFn;
|
||||
}) {
|
||||
const n = useOriginNotes({ data, onSaved, t });
|
||||
if (n.notes.length === 0 && n.targets.length === 0) return null;
|
||||
return (
|
||||
<>
|
||||
<div className="mb-[6px] mt-4 flex items-center gap-2">
|
||||
<Eyebrow>{t('collections.notes').toUpperCase()}</Eyebrow>
|
||||
{n.targets.length > 0 && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={n.add}
|
||||
aria-label={t('placeNotes.add')}
|
||||
className="ms-auto flex h-7 w-7 items-center justify-center rounded-full bg-m-ic text-m-ink"
|
||||
>
|
||||
<Plus size={14} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{n.choosing && (
|
||||
<div className="mb-2 flex flex-wrap gap-[6px]">
|
||||
{n.targets.map((target) => (
|
||||
<button
|
||||
key={target.key}
|
||||
type="button"
|
||||
onClick={() => n.edit(target)}
|
||||
className="inline-flex items-center gap-1 rounded-full border border-m-rowbr bg-m-ic px-3 py-[6px] text-caption font-semibold text-m-ink"
|
||||
>
|
||||
{target.kind === 'trip' ? <Luggage size={11} /> : <Bookmark size={11} />} {target.source}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<div className="flex flex-col gap-2">
|
||||
{n.notes.map((note) => (
|
||||
<div key={note.key} className="rounded-2xl border border-m-rowbr bg-m-sheet p-3">
|
||||
<div className="flex items-center gap-[6px] text-caption font-semibold text-m-faint">
|
||||
{note.kind === 'trip' ? <Luggage size={11} /> : <Bookmark size={11} />}
|
||||
<span className="min-w-0 flex-1 truncate">{note.source}</span>
|
||||
{note.canEdit && n.editing !== note.key && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => n.edit(note)}
|
||||
aria-label={t('placeNotes.edit')}
|
||||
className="flex h-7 w-7 items-center justify-center rounded-full bg-m-ic text-m-ink"
|
||||
>
|
||||
<Pencil size={13} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{n.editing === note.key ? (
|
||||
<>
|
||||
<textarea
|
||||
rows={4}
|
||||
autoFocus
|
||||
className={`${TEXTAREA_CLS} mt-2`}
|
||||
value={n.draft}
|
||||
onChange={(e) => n.setDraft(e.target.value)}
|
||||
aria-label={t('placeNotes.fieldLabel', { source: note.source })}
|
||||
/>
|
||||
<div className="mt-2 flex gap-2">
|
||||
<CancelPill onClick={n.cancel} className="flex-1">
|
||||
{t('common.cancel')}
|
||||
</CancelPill>
|
||||
<PrimaryPill onClick={() => void n.save()} disabled={n.busy} className="flex-1">
|
||||
{t('common.save')}
|
||||
</PrimaryPill>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<p dir="auto" className="m-0 mt-1 whitespace-pre-wrap text-body text-m-ink">
|
||||
{note.text}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
import type { PlaceActivity, PlacesLibraryEntry } from '@trek/shared';
|
||||
import { ChevronRight, Plus, Route, Ticket, X } from 'lucide-react';
|
||||
import { useNavigate } from 'react-router';
|
||||
import { activityLine } from '../../../components/Collections/placeExtrasText';
|
||||
import { activityHref, usePlaceActivities } from '../../../components/Collections/usePlaceActivities';
|
||||
import type { TranslationFn } from '../../../types';
|
||||
import { Eyebrow } from './MCollSheetKit';
|
||||
|
||||
const CARD = 'flex w-full items-center gap-[10px] rounded-2xl border border-m-rowbr bg-m-sheet p-3 text-start';
|
||||
const ICO = 'flex h-[34px] w-[34px] flex-none items-center justify-center rounded-[10px] bg-m-ic text-m-muted';
|
||||
|
||||
function ActivityIcon({ type }: { type: PlaceActivity['type'] }) {
|
||||
return type === 'booking' ? <Ticket size={15} /> : <Route size={15} />;
|
||||
}
|
||||
|
||||
/** The tours and bookings of a place on the phone (PLC-18); the logic is the desktop sheet's. */
|
||||
export default function MPlaceActivitiesSection({
|
||||
entry,
|
||||
language,
|
||||
t,
|
||||
}: {
|
||||
entry: PlacesLibraryEntry;
|
||||
language: string;
|
||||
t: TranslationFn;
|
||||
}) {
|
||||
const navigate = useNavigate();
|
||||
const a = usePlaceActivities({ entry, t });
|
||||
if (a.activities.length === 0 && !a.canLink) return null;
|
||||
return (
|
||||
<>
|
||||
<div className="mb-[6px] mt-4 flex items-center gap-2">
|
||||
<Eyebrow>{t('placeActivities.title').toUpperCase()}</Eyebrow>
|
||||
{a.canLink && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => (a.picking ? a.closePicker() : void a.openPicker())}
|
||||
disabled={a.busy}
|
||||
aria-label={a.picking ? t('common.close') : t('placeActivities.link')}
|
||||
className="ms-auto flex h-7 w-7 items-center justify-center rounded-full bg-m-ic text-m-ink disabled:opacity-50"
|
||||
>
|
||||
{a.picking ? <X size={14} /> : <Plus size={14} />}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex flex-col gap-2">
|
||||
{a.activities.map((act) => (
|
||||
<div key={`${act.key}:${act.source.kind}`} className={CARD}>
|
||||
<span className={ICO}>
|
||||
<ActivityIcon type={act.type} />
|
||||
</span>
|
||||
<button type="button" onClick={() => navigate(activityHref(act))} className="min-w-0 flex-1 text-start">
|
||||
<span className="block truncate text-body font-bold text-m-ink">{act.title}</span>
|
||||
<span className="block truncate text-caption text-m-muted">{activityLine(act, language, t)}</span>
|
||||
</button>
|
||||
{act.can_unlink ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void a.unlink(act)}
|
||||
disabled={a.busy}
|
||||
aria-label={t('placeActivities.unlink')}
|
||||
className="flex h-8 w-8 flex-none items-center justify-center rounded-full bg-m-ic text-m-muted"
|
||||
>
|
||||
<X size={14} />
|
||||
</button>
|
||||
) : (
|
||||
<ChevronRight size={16} className="flex-none text-m-faint rtl:-scale-x-100" />
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
{a.activities.length === 0 && !a.picking && (
|
||||
<p className="m-0 text-caption text-m-muted">{t('placeActivities.none')}</p>
|
||||
)}
|
||||
{a.picking && (
|
||||
<div className="rounded-2xl border border-m-rowbr bg-m-sheetop p-2">
|
||||
{a.picking.every((g) => g.candidates.length === 0) && (
|
||||
<p className="m-0 p-2 text-caption text-m-muted">{t('placeActivities.nothingToLink')}</p>
|
||||
)}
|
||||
{a.picking.map((g) =>
|
||||
g.candidates.map((c) => (
|
||||
<button
|
||||
key={`${g.source.origin.kind}:${c.key}`}
|
||||
type="button"
|
||||
disabled={a.busy}
|
||||
onClick={() => void a.link(g.source, c)}
|
||||
className="flex w-full items-center gap-[10px] rounded-xl p-2 text-start disabled:opacity-50"
|
||||
>
|
||||
<span className={ICO}>
|
||||
<ActivityIcon type={c.type} />
|
||||
</span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block truncate text-body font-semibold text-m-ink">{c.title}</span>
|
||||
<span className="block truncate text-caption text-m-muted">{activityLine(c, language, t)}</span>
|
||||
</span>
|
||||
<Plus size={15} className="flex-none text-m-muted" />
|
||||
</button>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import type { PlacesLibraryEntry } from '@trek/shared';
|
||||
import { ArrowRight } from 'lucide-react';
|
||||
import { useState } from 'react';
|
||||
import { historyLine, historyMeta } from '../../../components/Collections/placeExtrasText';
|
||||
import { usePlaceHistory } from '../../../components/Collections/usePlaceHistory';
|
||||
import type { TranslationFn } from '../../../types';
|
||||
import { Eyebrow } from './MCollSheetKit';
|
||||
|
||||
/** How many changes show before "show all" opens the rest. */
|
||||
const FOLDED = 3;
|
||||
|
||||
/** The change history of a place on the phone (PLC-14); the logic is the desktop sheet's. */
|
||||
export default function MPlaceHistorySection({
|
||||
entry,
|
||||
language,
|
||||
t,
|
||||
}: {
|
||||
entry: PlacesLibraryEntry;
|
||||
language: string;
|
||||
t: TranslationFn;
|
||||
}) {
|
||||
const h = usePlaceHistory(entry);
|
||||
const [open, setOpen] = useState(false);
|
||||
if (h.entries.length === 0) return null;
|
||||
const shown = open ? h.entries : h.entries.slice(0, FOLDED);
|
||||
return (
|
||||
<>
|
||||
<Eyebrow className="mb-[6px] mt-4">{t('placeHistory.title').toUpperCase()}</Eyebrow>
|
||||
<ol className="m-0 flex list-none flex-col gap-2 p-0">
|
||||
{shown.map((e) => {
|
||||
const line = historyLine(e, t);
|
||||
return (
|
||||
<li key={e.id} className="border-s-2 border-m-rowbr ps-3">
|
||||
<span className="block text-body text-m-ink">
|
||||
<strong className="font-semibold">{line.field}</strong>
|
||||
{(line.from || line.to) && (
|
||||
<span className="text-m-muted">
|
||||
{': '}
|
||||
{line.from && <span className="line-through">{line.from}</span>}
|
||||
{line.from && line.to && <ArrowRight size={11} className="mx-1 inline align-[-1px]" />}
|
||||
{line.to && <span className="text-m-ink">{line.to}</span>}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
<span className="block text-caption text-m-faint">{historyMeta(e, t, language)}</span>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ol>
|
||||
{(open ? h.hasMore : h.entries.length > FOLDED || h.hasMore) && (
|
||||
<button
|
||||
type="button"
|
||||
disabled={h.loadingMore}
|
||||
onClick={() => (open ? void h.more() : setOpen(true))}
|
||||
className="mt-2 text-caption font-semibold text-m-muted"
|
||||
>
|
||||
{open ? t('placeHistory.more') : t('placeHistory.showAll')}
|
||||
</button>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import type { PlacesLibraryEntry } from '@trek/shared';
|
||||
import { ChevronRight, FileText } from 'lucide-react';
|
||||
import { usePlaceMedia } from '../../../components/Collections/usePlaceMedia';
|
||||
import PhotoLightbox from '../../../components/Journey/PhotoLightbox';
|
||||
import type { TranslationFn } from '../../../types';
|
||||
import { Eyebrow } from './MCollSheetKit';
|
||||
|
||||
/** How many pictures the phone's row shows before it counts the rest on the last one. */
|
||||
const SHOWN = 6;
|
||||
|
||||
/** The pictures and trip files of a place on the phone (PLC-19, PLC-20); the logic is the desktop sheet's. */
|
||||
export default function MPlaceMediaSection({ entry, t }: { entry: PlacesLibraryEntry; t: TranslationFn }) {
|
||||
const m = usePlaceMedia(entry);
|
||||
if (m.photos.length === 0 && m.files.length === 0) return null;
|
||||
const rest = m.photos.length - SHOWN;
|
||||
return (
|
||||
<>
|
||||
{m.photos.length > 0 && (
|
||||
<>
|
||||
<Eyebrow className="mb-[6px] mt-4">{t('places.media.photos').toUpperCase()}</Eyebrow>
|
||||
<div className="grid grid-cols-3 gap-[6px]">
|
||||
{m.photos.slice(0, SHOWN).map((p, i) => (
|
||||
<button
|
||||
key={p.id}
|
||||
type="button"
|
||||
onClick={() => m.setOpen(i)}
|
||||
className="relative aspect-square overflow-hidden rounded-xl bg-m-ic"
|
||||
aria-label={p.caption}
|
||||
>
|
||||
<img src={p.thumbSrc} alt="" loading="lazy" className="h-full w-full object-cover" />
|
||||
{i === SHOWN - 1 && rest > 0 && (
|
||||
<>
|
||||
<span className="absolute inset-0 bg-m-sheet opacity-75" />
|
||||
<span className="absolute inset-0 grid place-items-center text-body font-bold text-m-ink">
|
||||
+{rest}
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{m.files.length > 0 && (
|
||||
<>
|
||||
<Eyebrow className="mb-[6px] mt-4">{t('places.media.files').toUpperCase()}</Eyebrow>
|
||||
<div className="flex flex-col gap-2">
|
||||
{m.files.map((f) => (
|
||||
<a
|
||||
key={f.file_id}
|
||||
href={f.url}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="flex items-center gap-[10px] rounded-2xl border border-m-rowbr bg-m-sheet p-3"
|
||||
>
|
||||
<span className="flex h-[34px] w-[34px] flex-none items-center justify-center rounded-[10px] bg-m-ic text-m-muted">
|
||||
<FileText size={15} />
|
||||
</span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span dir="auto" className="block truncate text-body font-bold text-m-ink">
|
||||
{f.original_name}
|
||||
</span>
|
||||
<span className="block truncate text-caption text-m-muted">{f.trip_title}</span>
|
||||
</span>
|
||||
<ChevronRight size={16} className="flex-none text-m-faint rtl:-scale-x-100" />
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{m.open !== null && (
|
||||
<PhotoLightbox
|
||||
photos={m.photos.map((p) => ({
|
||||
id: p.id,
|
||||
src: p.src,
|
||||
thumbSrc: p.thumbSrc,
|
||||
caption: p.caption,
|
||||
provider: p.provider,
|
||||
mediaType: p.mediaType,
|
||||
}))}
|
||||
startIndex={m.open}
|
||||
onClose={m.close}
|
||||
label={entry.name}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,10 @@
|
||||
import type { CollectionPlace, CollectionStatus, PlacesLibraryEntry, PlacesLibrarySort } from '@trek/shared';
|
||||
import type {
|
||||
CollectionPlace,
|
||||
CollectionStatus,
|
||||
PlacesLibraryEntry,
|
||||
PlacesLibrarySort,
|
||||
Tag as TagRow,
|
||||
} from '@trek/shared';
|
||||
import {
|
||||
ArrowDownUp,
|
||||
Bookmark,
|
||||
@@ -13,13 +19,17 @@ import {
|
||||
MapPin,
|
||||
Search,
|
||||
Shapes,
|
||||
Tag,
|
||||
} from 'lucide-react';
|
||||
import { useMemo, useState } from 'react';
|
||||
import CollectionMap from '../../../components/Collections/CollectionMap';
|
||||
import { saveDraftOf } from '../../../components/Collections/libraryPairs';
|
||||
import EntryTagDots from '../../../components/Collections/EntryTagDots';
|
||||
import { libraryCarryOptions, saveDraftOf } from '../../../components/Collections/libraryPairs';
|
||||
import { originName } from '../../../components/Collections/originName';
|
||||
import { usePersonalTags } from '../../../components/Collections/useEntryTags';
|
||||
import { usePlaceDuplicates } from '../../../components/Collections/usePlaceDuplicates';
|
||||
import { usePlacesLibrary, type LibraryKindFilter } from '../../../components/Collections/usePlacesLibrary';
|
||||
import VisitedMark from '../../../components/Collections/VisitedMark';
|
||||
import { STATUS_ORDER } from '../../../pages/collections/collectionsModel';
|
||||
import { useCollectionStore } from '../../../store/collectionStore';
|
||||
import { useSaveToCollectionStore } from '../../../store/saveToCollectionStore';
|
||||
@@ -42,7 +52,7 @@ interface MPlacesLibraryProps {
|
||||
t: TranslationFn;
|
||||
}
|
||||
|
||||
type Drop = 'kind' | 'status' | 'category' | 'sort';
|
||||
type Drop = 'kind' | 'status' | 'category' | 'tags' | 'sort';
|
||||
|
||||
/** A map point per entry with a position; the map speaks CollectionPlace, keyed by a running id. */
|
||||
function toMapPlaces(entries: PlacesLibraryEntry[]) {
|
||||
@@ -88,8 +98,12 @@ function Row({ entry, onOpen, t }: { entry: PlacesLibraryEntry; onOpen: () => vo
|
||||
<Icon size={17} strokeWidth={2.2} />
|
||||
</span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span dir="auto" className="block truncate text-body font-bold text-m-ink">
|
||||
{entry.name}
|
||||
<span className="flex min-w-0 items-center gap-1">
|
||||
<span dir="auto" className="truncate text-body font-bold text-m-ink">
|
||||
{entry.name}
|
||||
</span>
|
||||
<VisitedMark count={entry.visit_count} t={t} />
|
||||
<EntryTagDots tags={entry.tags} />
|
||||
</span>
|
||||
{entry.address && (
|
||||
<span className="mt-[2px] flex items-center gap-[3px] truncate text-caption text-m-muted">
|
||||
@@ -126,6 +140,7 @@ function FilterDrop({
|
||||
drop,
|
||||
lib,
|
||||
categories,
|
||||
personalTags,
|
||||
kindLabel,
|
||||
pick,
|
||||
t,
|
||||
@@ -133,6 +148,7 @@ function FilterDrop({
|
||||
drop: Drop;
|
||||
lib: Library;
|
||||
categories: Category[];
|
||||
personalTags: readonly TagRow[];
|
||||
kindLabel: (k: LibraryKindFilter) => string;
|
||||
pick: (fn: () => void) => void;
|
||||
t: TranslationFn;
|
||||
@@ -204,6 +220,22 @@ function FilterDrop({
|
||||
})}
|
||||
</>
|
||||
)}
|
||||
{drop === 'tags' &&
|
||||
personalTags.map((tag) => (
|
||||
<DropRow
|
||||
key={tag.id}
|
||||
icon={
|
||||
// The tag's own colour, the one data-driven value of the row.
|
||||
<span
|
||||
className="h-2.5 w-2.5 flex-none rounded-full"
|
||||
style={{ background: tag.color || 'var(--m-act)' }}
|
||||
/>
|
||||
}
|
||||
label={String(tag.name)}
|
||||
on={lib.tagIds.includes(tag.id)}
|
||||
onPick={() => lib.toggleTag(tag.id)}
|
||||
/>
|
||||
))}
|
||||
{drop === 'sort' &&
|
||||
(['name', 'updated'] as PlacesLibrarySort[]).map((s) => (
|
||||
<DropRow
|
||||
@@ -286,12 +318,14 @@ function Results({
|
||||
*/
|
||||
export default function MPlacesLibrary({ categories, language, dark, view, onView, navigate, t }: MPlacesLibraryProps) {
|
||||
const lib = usePlacesLibrary({ active: true, t });
|
||||
const personalTags = usePersonalTags();
|
||||
const dup = usePlaceDuplicates({ active: true, onChanged: lib.reload, t });
|
||||
const [showDup, setShowDup] = useState(false);
|
||||
const openSave = useSaveToCollectionStore((s) => s.open);
|
||||
const copyToTrip = useCollectionStore((s) => s.copyToTrip);
|
||||
const [drop, setDrop] = useState<Drop | null>(null);
|
||||
const [copyId, setCopyId] = useState<number | null>(null);
|
||||
const [copyCarry, setCopyCarry] = useState<ReturnType<typeof libraryCarryOptions>>(undefined);
|
||||
const map = useMemo(() => toMapPlaces(lib.entries), [lib.entries]);
|
||||
|
||||
const kindLabel = (k: LibraryKindFilter) =>
|
||||
@@ -377,6 +411,18 @@ export default function MPlacesLibrary({ categories, language, dark, view, onVie
|
||||
<ChevronDown size={12} strokeWidth={2} className="flex-none" />
|
||||
</button>
|
||||
)}
|
||||
{personalTags.length > 0 && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setDrop((d) => (d === 'tags' ? null : 'tags'))}
|
||||
aria-expanded={drop === 'tags'}
|
||||
aria-label={t('placeTags.title')}
|
||||
className={`${chip(lib.tagIds.length > 0)} !flex-none px-3`}
|
||||
>
|
||||
<Tag size={13} strokeWidth={2} className="flex-none" />
|
||||
{lib.tagIds.length > 0 && <span>{lib.tagIds.length}</span>}
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setDrop((d) => (d === 'sort' ? null : 'sort'))}
|
||||
@@ -414,7 +460,15 @@ export default function MPlacesLibrary({ categories, language, dark, view, onVie
|
||||
<div
|
||||
className={`absolute inset-x-0 top-[calc(100%+6px)] z-20 max-h-[300px] overflow-y-auto p-[6px] ${DROP_PANEL}`}
|
||||
>
|
||||
<FilterDrop drop={drop} lib={lib} categories={categories} kindLabel={kindLabel} pick={pick} t={t} />
|
||||
<FilterDrop
|
||||
drop={drop}
|
||||
lib={lib}
|
||||
categories={categories}
|
||||
personalTags={personalTags}
|
||||
kindLabel={kindLabel}
|
||||
pick={pick}
|
||||
t={t}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
@@ -425,6 +479,7 @@ export default function MPlacesLibrary({ categories, language, dark, view, onVie
|
||||
open={lib.selectedKey != null}
|
||||
data={lib.detail}
|
||||
loading={lib.detailLoading}
|
||||
onNotesSaved={lib.reload}
|
||||
cover={lib.cover}
|
||||
language={language}
|
||||
onClose={lib.close}
|
||||
@@ -432,6 +487,8 @@ export default function MPlacesLibrary({ categories, language, dark, view, onVie
|
||||
onOpenTrip={(tripId, placeId) => navigate(`/trips/${tripId}?place=${placeId}`)}
|
||||
onSaveToList={(origin, d) => openSave(saveDraftOf(origin, d, lib.detail?.entry.category?.id))}
|
||||
onCopyToTrip={(id) => {
|
||||
// Read now: the sheet closes, and its place with it.
|
||||
setCopyCarry(libraryCarryOptions(lib.detail, id));
|
||||
lib.close();
|
||||
setCopyId(id);
|
||||
}}
|
||||
@@ -439,9 +496,15 @@ export default function MPlacesLibrary({ categories, language, dark, view, onVie
|
||||
/>
|
||||
<MDuplicatesSheet open={showDup} d={dup} onClose={() => setShowDup(false)} t={t} />
|
||||
<MCollTripPickerSheet
|
||||
carryOptions={copyCarry}
|
||||
open={copyId != null}
|
||||
count={1}
|
||||
onCopy={(tripId, carry) => copyToTrip(tripId, copyId != null ? [copyId] : [], undefined, carry)}
|
||||
onCopy={(tripId, carry) =>
|
||||
copyToTrip(tripId, copyId != null ? [copyId] : [], undefined, carry).then((res) => {
|
||||
lib.reload();
|
||||
return res;
|
||||
})
|
||||
}
|
||||
onClose={() => setCopyId(null)}
|
||||
t={t}
|
||||
/>
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
import type { PlacesLibraryEntry } from '@trek/shared';
|
||||
import { CalendarCheck } from 'lucide-react';
|
||||
import { useMemo } from 'react';
|
||||
import { visitDate } from '../../../components/Collections/libraryDates';
|
||||
import { tripPlaceEntry, usePlaceVisits } from '../../../components/Collections/usePlaceVisits';
|
||||
import { Avatar } from '../../../components/Planner/TravelerPicker';
|
||||
import type { TranslationFn } from '../../../types';
|
||||
import { Eyebrow } from './MCollSheetKit';
|
||||
|
||||
const CARD = 'flex w-full items-center gap-[10px] rounded-2xl border border-m-rowbr bg-m-sheet p-3';
|
||||
const ICO = 'flex h-[34px] w-[34px] flex-none items-center justify-center rounded-[10px] bg-m-ic text-m-muted';
|
||||
|
||||
/**
|
||||
* When the reader was at a place of All places on the phone (PLC-10): every past
|
||||
* day of a trip it was planned on. Not there at all without a visit.
|
||||
*/
|
||||
export default function MVisitsSection({
|
||||
entry,
|
||||
language,
|
||||
t,
|
||||
}: {
|
||||
entry: PlacesLibraryEntry;
|
||||
language: string;
|
||||
t: TranslationFn;
|
||||
}) {
|
||||
const v = usePlaceVisits({ entry });
|
||||
const last = visitDate(v.lastVisit, null, language);
|
||||
if (v.count === 0 || !last) return null;
|
||||
return (
|
||||
<>
|
||||
<div className="mb-[6px] mt-4 flex items-baseline gap-2">
|
||||
<Eyebrow>{t('visits.title').toUpperCase()}</Eyebrow>
|
||||
<span className="ms-auto truncate text-caption text-m-muted">
|
||||
{t('visits.summary', { count: v.count, date: last })}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex flex-col gap-2">
|
||||
{v.visits.map((visit) => (
|
||||
<div key={`${visit.trip.id}:${visit.day_id}:${visit.place_id}`} className={CARD}>
|
||||
<span className={ICO}>
|
||||
<CalendarCheck size={15} />
|
||||
</span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block truncate text-body font-bold text-m-ink">
|
||||
{visitDate(visit.visited_on, visit.visited_time, language)}
|
||||
</span>
|
||||
<span className="block truncate text-caption text-m-muted">{visit.trip.title}</span>
|
||||
</span>
|
||||
{visit.participants.length > 1 && (
|
||||
<span className="flex flex-none">
|
||||
{visit.participants.slice(0, 3).map((p, i) => (
|
||||
<span key={p.id} className={i ? '-ms-1.5 flex rounded-full ring-2 ring-m-sheet' : 'flex'}>
|
||||
<Avatar userId={p.id} username={p.username} avatarUrl={p.avatar_url} size={20} />
|
||||
</span>
|
||||
))}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/** A trip place's visits on the phone's place sheet: how often and when last; not shown before the first one. */
|
||||
export function MTripPlaceVisits({
|
||||
trip,
|
||||
place,
|
||||
language,
|
||||
t,
|
||||
}: {
|
||||
trip: { id: number; title: string; start_date?: string | null; end_date?: string | null };
|
||||
place: { id: number; name: string; address?: string | null; lat?: number | null; lng?: number | null };
|
||||
language: string;
|
||||
t: TranslationFn;
|
||||
}) {
|
||||
const entry = useMemo(() => tripPlaceEntry(trip, place), [trip, place]);
|
||||
const v = usePlaceVisits({ entry });
|
||||
const last = visitDate(v.lastVisit, null, language);
|
||||
if (v.count === 0 || !last) return null;
|
||||
return (
|
||||
<div className="mt-3 flex items-center gap-[10px] rounded-[13px] border border-m-inbr bg-m-inner px-3 py-[9px]">
|
||||
<CalendarCheck size={15} className="flex-none text-success" />
|
||||
<span className="min-w-0 flex-1 truncate text-body text-m-ink">
|
||||
{t('visits.summary', { count: v.count, date: last })}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -4,6 +4,9 @@ import { MapCompassPill, type CompassMap } from '../../../../components/Map/MapC
|
||||
import { MAP_LAYER_SWITCHER_INSET, MAP_ROUND_CONTROL_SIZE } from '../../../../components/Map/MapLayerSwitcher'
|
||||
import { TripRouteOverviewPill, TripRouteOverviewPanel } from '../../../../components/Map/TripRouteOverview'
|
||||
import { PlaceNamesPill } from '../../../../components/Map/PlaceNamesPill'
|
||||
import { TripListsPill } from '../../../../components/Collections/TripListsPill'
|
||||
import { useTripLists } from '../../../../components/Collections/useTripLists'
|
||||
import { useTranslation } from '../../../../i18n'
|
||||
import { DawarichTrailPill } from '../../../../components/Map/DawarichTrailPill'
|
||||
import PoiCategoryPill from '../../../../components/Map/PoiCategoryPill'
|
||||
import { usePoiExplore } from '../../../../components/Map/usePoiExplore'
|
||||
@@ -342,11 +345,23 @@ export default function MMapArea({ planner, shell }: MMapAreaProps) {
|
||||
return vias.filter(v => !v.nightPause || v.nightPause.day === stage.dayNumber)
|
||||
}, [onStage, planner.roadtripMapVias, planner.routeVias, stage])
|
||||
|
||||
const pois = useMergedMapPois(
|
||||
const merged = useMergedMapPois(
|
||||
onStage ? planner.roadtripCorridor.visible : null,
|
||||
onStage ? NO_POIS : poi.pois,
|
||||
planner.refuel.offered,
|
||||
)
|
||||
// PLC-15/16: the lists the trip draws on, their places as pins beside the POIs.
|
||||
const { t } = useTranslation()
|
||||
const lists = useTripLists({ tripId: Number(planner.tripId), canEdit: planner.can('place_edit', planner.trip), t })
|
||||
const pois = useMemo(() => (lists.pois.length ? [...merged, ...lists.pois] : merged), [merged, lists.pois])
|
||||
const { claim } = lists
|
||||
const { handlePoiClick, openAddPlaceFromPoi, selectedDayId } = planner
|
||||
// Stable, so neither renderer rebuilds every POI pin on each render.
|
||||
const onPoiClick = useCallback((marker: Poi) => {
|
||||
if (claim(marker)) return
|
||||
if (onStage) handlePoiClick(marker)
|
||||
else openAddPlaceFromPoi(marker, selectedDayId)
|
||||
}, [claim, onStage, handlePoiClick, openAddPlaceFromPoi, selectedDayId])
|
||||
|
||||
return (
|
||||
// `isolate` keeps the map's internal z-indexes (Leaflet panes, the z-1000
|
||||
@@ -443,9 +458,7 @@ export default function MMapArea({ planner, shell }: MMapAreaProps) {
|
||||
// the distance it carries and sends it to the draft sheet with the stop kind, the
|
||||
// stay and the position in the chain already worked out. The plan tab has no
|
||||
// chain to place anything in, so there it stays the plain place form.
|
||||
onPoiClick={onStage
|
||||
? planner.handlePoiClick
|
||||
: marker => planner.openAddPlaceFromPoi(marker, planner.selectedDayId)}
|
||||
onPoiClick={onPoiClick}
|
||||
onViewportChange={onViewportChange}
|
||||
onMapReady={setGlMap}
|
||||
// Other ways of driving the leg the stage asked about, and the one lit up.
|
||||
@@ -539,6 +552,7 @@ export default function MMapArea({ planner, shell }: MMapAreaProps) {
|
||||
{!planner.roadtripActive && (
|
||||
<TripRouteOverviewPill active={planner.overviewShown} onToggle={planner.toggleOverview} />
|
||||
)}
|
||||
<TripListsPill lists={lists} t={t} />
|
||||
<PlaceNamesPill />
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useTripVisitedIds } from '../../../../hooks/useTripVisitedIds'
|
||||
import { ReactNode, useEffect, useMemo, useState } from 'react'
|
||||
import {
|
||||
Bookmark, CheckCheck, CheckCircle2, Download, ListChecks, Loader2, MapPinOff, Plus,
|
||||
@@ -76,14 +77,15 @@ export default function MPlacesBrowser({ planner, shell }: MPlacesBrowserProps)
|
||||
|
||||
// A hotel is linked through its stay and a venue through its booking; neither is
|
||||
// ever dragged onto a day, and the pool used to call both unplanned (#2072).
|
||||
const visitedIds = useTripVisitedIds(tripId)
|
||||
const plannedIds = useMemo(
|
||||
() => plannedPlaceIds(assignments, planner.tripAccommodations, planner.reservations),
|
||||
[assignments, planner.tripAccommodations, planner.reservations],
|
||||
)
|
||||
const dayNumberByPlace = useMemo(() => firstPlannedDayNumbers(assignments, days), [assignments, days])
|
||||
const filtered = useMemo(() => {
|
||||
return filterPool(poolPlaces, { filter, categoryFilters, ratingFilter, search, plannedIds })
|
||||
}, [poolPlaces, filter, categoryFilters, ratingFilter, search, plannedIds])
|
||||
return filterPool(poolPlaces, { filter, categoryFilters, ratingFilter, search, plannedIds, visitedIds })
|
||||
}, [poolPlaces, filter, categoryFilters, ratingFilter, search, plannedIds, visitedIds])
|
||||
|
||||
// Compare the ids, not just the counts: a place removed remotely while another
|
||||
// one is selected keeps the sizes equal without the sets matching.
|
||||
@@ -159,6 +161,13 @@ export default function MPlacesBrowser({ planner, shell }: MPlacesBrowserProps)
|
||||
label={t('places.planned')}
|
||||
onClick={() => pickFilter('planned')}
|
||||
/>
|
||||
{(visitedIds.size > 0 || filter === 'visited') && (
|
||||
<FilterChip
|
||||
active={filter === 'visited'}
|
||||
label={t('places.filterVisited')}
|
||||
onClick={() => pickFilter('visited')}
|
||||
/>
|
||||
)}
|
||||
{hasTracks && (
|
||||
<FilterChip
|
||||
active={filter === 'tracks'}
|
||||
|
||||
@@ -54,8 +54,10 @@ interface PoolFilterArgs {
|
||||
ratingFilter?: PlacesRatingFloor
|
||||
search: string
|
||||
plannedIds: Set<number>
|
||||
/** The trip's places the reader visited, for the "visited" choice (PLC-23). */
|
||||
visitedIds?: ReadonlySet<number>
|
||||
}
|
||||
|
||||
export function filterPool(places: Place[], { filter, categoryFilters, ratingFilter = 'all', search, plannedIds }: PoolFilterArgs): Place[] {
|
||||
return places.filter(p => matchesPlacesFilter(p, { filter, categoryFilters, ratingFilter }, { plannedIds }) && matchesSearch(p, search))
|
||||
export function filterPool(places: Place[], { filter, categoryFilters, ratingFilter = 'all', search, plannedIds, visitedIds }: PoolFilterArgs): Place[] {
|
||||
return places.filter(p => matchesPlacesFilter(p, { filter, categoryFilters, ratingFilter }, { plannedIds, visitedIds }) && matchesSearch(p, search))
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import { resolveTrackColor, inheritedTrackColor } from '../../../../components/M
|
||||
import { avatarSrc } from '../../../../utils/avatarSrc'
|
||||
import { safeHttpUrl } from '../../../../utils/safeUrl'
|
||||
import { openFile } from '../../../../utils/fileDownload'
|
||||
import { MTripPlaceVisits } from '../../collections/MVisitsSection'
|
||||
import { filesForPlace } from '../../../../utils/placeFiles'
|
||||
import { navigationTargetLabel, getNavigationTargets, openNavigationTarget } from '../../../../components/Planner/placeNavigation'
|
||||
import { addressWithoutCoordinates } from '../../../../components/Planner/placeCoordinates'
|
||||
@@ -543,6 +544,7 @@ export default function MPlaceSheet({ planner, shell }: MTripSheetsProps) {
|
||||
</>
|
||||
)}
|
||||
|
||||
{planner.trip && <MTripPlaceVisits trip={planner.trip} place={place} language={language} t={t} />}
|
||||
{/* ── Files ── */}
|
||||
<div className={`mt-3 rounded-[13px] px-3 py-[9px] ${INNER_CLS}`}>
|
||||
<div
|
||||
|
||||
Reference in New Issue
Block a user