feat(places): one place view for All places and the lists

The desktop dialog and the phone sheet of a place show its overview, notes,
tours and bookings, photos and files and its history in tabs, with the tags
of each list and trip, a markdown notes editor, uploads and the place
picture. The rating bar of All places is the rating row the lists show,
with its voters, and votes once for every copy. All places filters by a
lowest rating and sorts by it, and the edit form changes the first copy the
reader may edit, which the server carries to the others.
This commit is contained in:
Maurice
2026-11-29 23:36:43 +00:00
parent 783c98f41e
commit d758f4c592
78 changed files with 5604 additions and 2797 deletions
@@ -4,6 +4,7 @@ import type { CollectionPlace, CollectionStatus } from '@trek/shared'
import type { TranslationFn } from '../../../types'
import { nextStatus } from '../../../pages/collections/collectionsModel'
import { categoryMeta, STATUS_SPEC, tint, UNCATEGORIZED_META } from './collectionsMobileModel'
import EntryTagDots from '../../../components/Collections/EntryTagDots'
interface MCollPlaceRowProps {
place: CollectionPlace
@@ -13,6 +14,8 @@ interface MCollPlaceRowProps {
onOpen: (id: number) => void
onToggleSelect: (id: number) => void
onSetStatus: (id: number, status: CollectionStatus) => void
/** The list's tags on the place, as dots behind its name. */
tags?: readonly { name: string; color: string | null }[]
/** The drag of the list's own order (#1457), while it may be dragged. */
reorder?: {
handle: React.HTMLAttributes<HTMLElement> & { draggable?: boolean }
@@ -32,7 +35,7 @@ interface MCollPlaceRowProps {
* and a third of a narrow window wide, which cut the names short.
*/
export default function MCollPlaceRow({
place, selectMode, selected, canEdit, onOpen, onToggleSelect, onSetStatus, reorder, t,
place, selectMode, selected, canEdit, onOpen, onToggleSelect, onSetStatus, tags, reorder, t,
}: MCollPlaceRowProps) {
const cat = categoryMeta(place.category)
const meta = cat ?? UNCATEGORIZED_META
@@ -79,7 +82,10 @@ export default function MCollPlaceRow({
{selected ? <Check size={17} strokeWidth={2.4} /> : <TileIcon size={17} strokeWidth={2.2} />}
</span>
<span className="min-w-0 flex-1">
<span dir="auto" className="block truncate text-[0.78125rem] font-bold text-m-ink">{place.name}</span>
<span className="flex min-w-0 items-center gap-[6px]">
<span dir="auto" className="truncate text-[0.78125rem] font-bold text-m-ink">{place.name}</span>
<EntryTagDots tags={tags} />
</span>
{place.address && (
<span className="mt-[2px] flex items-center gap-[3px] truncate font-geist text-[0.625rem] text-m-muted">
<MapPin size={9} strokeWidth={2.2} className="flex-none" />
@@ -1,306 +1,402 @@
import { useRef, useState } from 'react'
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'
import { normalizeLinkUrl, STATUS_ORDER } from '../../../pages/collections/collectionsModel'
import MSheet from '../../components/MSheet'
import PlaceRating from '../../../components/shared/StarRating'
import MCollCategoryPicker from './MCollCategoryPicker'
import MCollLinksEditor from './MCollLinksEditor'
import MCollLocationSearch from './MCollLocationSearch'
import { STATUS_SPEC } from './collectionsMobileModel'
import { CancelPill, Eyebrow, INPUT_CLS, PrimaryPill, TEXTAREA_CLS } from './MCollSheetKit'
import { getNavigationTargets, navigationTargetLabel, openNavigationTarget } from '../../../components/Planner/placeNavigation'
import { NavigationMenu } from '../../../components/shared/NavigationMenu'
import type { CollectionLabel, CollectionLink, CollectionPlace, CollectionStatus } from '@trek/shared';
import { Camera, Check, Copy, ExternalLink, Loader2, Navigation, Pencil, Trash2 } from 'lucide-react';
import { useRef, useState } from 'react';
import Markdown from 'react-markdown';
import { useNavigate } from 'react-router';
import remarkBreaks from 'remark-breaks';
import remarkGfm from 'remark-gfm';
import { originPairs } from '../../../components/Collections/libraryPairs';
import { useCollectionPlaceForm } from '../../../components/Collections/useCollectionPlaceForm';
import { useLibraryPlace } from '../../../components/Collections/useLibraryPlace';
import { usePlaceSheet } from '../../../components/Collections/usePlaceSheet';
import { usePlaceTags } from '../../../components/Collections/usePlaceTags';
import { getNavigationTargets, openNavigationTarget } from '../../../components/Planner/placeNavigation';
import { NavigationMenu } from '../../../components/shared/NavigationMenu';
import PlaceRating from '../../../components/shared/StarRating';
import { useTranslation } from '../../../i18n';
import { normalizeLinkUrl, STATUS_ORDER } from '../../../pages/collections/collectionsModel';
import type { Category, TranslationFn } from '../../../types';
import { placesPath } from '../../../utils/placesRoutes';
import { STATUS_SPEC } from './collectionsMobileModel';
import MCollCategoryPicker from './MCollCategoryPicker';
import MCollLinksEditor from './MCollLinksEditor';
import MCollLocationSearch from './MCollLocationSearch';
import { Eyebrow, INPUT_CLS, TEXTAREA_CLS } from './MCollSheetKit';
import MPlaceOrigins from './MPlaceOrigins';
import MPlaceSheetShell, { COVER_BTN, SHEET_ACTION } from './MPlaceSheetShell';
import MPlaceSheetTabs from './MPlaceSheetTabs';
import MPlaceTagsCard from './MPlaceTagsCard';
function linkHost(url: string): string {
try { return new URL(url).hostname.replace(/^www\./, '') } catch { return url }
try {
return new URL(url).hostname.replace(/^www\./, '');
} catch {
return url;
}
}
// Hero chrome sits on a photo/gradient — fixed white/black scrims in both themes.
const HERO_CAT_CHIP =
'inline-flex min-w-0 items-center gap-1 rounded-full bg-[rgba(255,255,255,.9)] px-[10px] py-[3px] font-geist text-[0.59375rem] font-extrabold text-[#101013]' // theme-lint-disable
// Close and the cover controls beside it.
const HERO_BTN =
'flex h-8 w-8 items-center justify-center rounded-full bg-[rgba(0,0,0,.28)] text-white' // theme-lint-disable
type PlacePatch = {
name?: string;
description?: string | null;
notes?: string | null;
links?: CollectionLink[];
category_id?: number | null;
label_ids?: number[];
image_url?: string | null;
address?: string | null;
lat?: number | null;
lng?: number | null;
};
interface MCollPlaceSheetProps {
place: CollectionPlace | null
canEdit: boolean
canDelete: boolean
categories: Category[]
labels: CollectionLabel[]
onClose: () => void
onSetStatus: (status: CollectionStatus) => void
onSave: (patch: { name?: string; description?: string | null; notes?: string | null; links?: CollectionLink[]; category_id?: number | null; label_ids?: number[]; image_url?: string | null; address?: string | null; lat?: number | null; lng?: number | null }) => Promise<void>
onUploadImage?: (file: File) => Promise<void>
onCopyToTrip: () => void
onRemove: () => void
place: CollectionPlace | null;
canEdit: boolean;
canDelete: boolean;
categories: Category[];
labels: CollectionLabel[];
onClose: () => void;
onSetStatus: (status: CollectionStatus) => void;
onSave: (patch: PlacePatch) => Promise<void>;
onUploadImage?: (file: File) => Promise<void>;
onCopyToTrip: () => void;
onRemove: () => void;
/** Cast/clear the current user's star vote (#1435); every member may vote. */
onRate?: (rating: number | null) => Promise<void> | void
t: TranslationFn
onRate?: (rating: number | null) => Promise<void> | void;
t: TranslationFn;
}
type Form = ReturnType<typeof useCollectionPlaceForm>;
/** The list's status of the place, two by two on a phone so every label keeps its room. */
function StatusGrid({
status,
canEdit,
onSet,
t,
}: {
status: CollectionStatus;
canEdit: boolean;
onSet: (s: CollectionStatus) => void;
t: TranslationFn;
}) {
return (
<div className="grid grid-cols-2 gap-[6px] wide:grid-cols-4">
{STATUS_ORDER.map((s) => {
const meta = STATUS_SPEC[s];
const Icon = meta.icon;
const on = status === s;
return (
<button
key={s}
type="button"
disabled={!canEdit}
onClick={() => onSet(s)}
aria-pressed={on}
className={
on
? 'flex flex-1 items-center justify-center gap-[5px] rounded-[12px] bg-m-act py-[9px] text-caption font-bold text-m-actfg'
: 'flex flex-1 items-center justify-center gap-[5px] rounded-[12px] border border-m-rowbr bg-m-sheetop py-[9px] text-caption font-bold text-m-ink'
}
>
<Icon size={13} strokeWidth={2.2} style={on ? undefined : { color: meta.color }} />
<span className="truncate">{t(meta.labelKey)}</span>
</button>
);
})}
</div>
);
}
/** The edit form: name with category, address (and a lookup without a position), description, links. */
function EditForm({ form, categories, t }: { form: Form; categories: Category[]; t: TranslationFn }) {
return (
<div className="flex flex-col pt-3">
<Eyebrow className="mb-[6px]">{t('common.name').toUpperCase()}</Eyebrow>
<MCollCategoryPicker
variant="tile"
categories={categories}
value={form.categoryId}
onChange={form.setCategoryId}
t={t}
>
<input value={form.name} onChange={(e) => form.setName(e.target.value)} className={INPUT_CLS} />
</MCollCategoryPicker>
<Eyebrow className="mb-[6px] mt-[14px]">{t('places.formAddress').toUpperCase()}</Eyebrow>
<input
value={form.address}
onChange={(e) => form.setAddress(e.target.value)}
placeholder={t('places.formAddressPlaceholder')}
className={INPUT_CLS}
/>
{form.needsPosition && <MCollLocationSearch picked={form.positionPicked} onPick={form.pickPosition} t={t} />}
<Eyebrow className="mb-[6px] mt-[14px]">{t('collections.description').toUpperCase()}</Eyebrow>
<textarea
rows={5}
value={form.description}
onChange={(e) => form.setDescription(e.target.value)}
placeholder={t('collections.descriptionPlaceholder')}
className={TEXTAREA_CLS}
/>
<Eyebrow className="mb-[6px] mt-[14px]">{t('collections.links').toUpperCase()}</Eyebrow>
<MCollLinksEditor links={form.links} onChange={form.setLinks} t={t} />
</div>
);
}
/** The bottom row: edit, get there, copy into a trip, take it off the list. */
function Actions({
place,
form,
canEdit,
canDelete,
onCopyToTrip,
onRemove,
t,
}: {
place: CollectionPlace;
form: Form;
canEdit: boolean;
canDelete: boolean;
onCopyToTrip: () => void;
onRemove: () => void;
t: TranslationFn;
}) {
const [navOpen, setNavOpen] = useState(false);
const navRef = useRef<HTMLButtonElement | null>(null);
const targets = getNavigationTargets(place);
if (form.editing) {
return (
<>
<button type="button" onClick={form.cancelEdit} className={SHEET_ACTION}>
{t('common.cancel')}
</button>
<button
type="button"
onClick={() => void form.save()}
disabled={form.saving}
className="flex flex-1 items-center justify-center gap-[6px] rounded-[13px] bg-m-act px-2 py-[11px] text-caption font-bold text-m-actfg"
>
<Check size={14} /> {t('common.save')}
</button>
</>
);
}
return (
<>
{canEdit && (
<button
type="button"
onClick={() => form.setEditing(true)}
aria-label={t('common.edit')}
className={`${SHEET_ACTION} !flex-none px-4`}
>
<Pencil size={14} />
</button>
)}
{targets.length > 0 && (
<>
<button
ref={navRef}
type="button"
aria-label={t('inspector.navigation')}
className={`${SHEET_ACTION} !flex-none px-4`}
onClick={() => (targets.length === 1 ? openNavigationTarget(targets[0]) : setNavOpen(true))}
>
<Navigation size={14} />
</button>
{navOpen && (
<NavigationMenu
targets={targets}
anchor={navRef.current}
onClose={() => setNavOpen(false)}
title={t('inspector.openWith')}
/>
)}
</>
)}
<button type="button" onClick={onCopyToTrip} className={SHEET_ACTION}>
<Copy size={14} /> {t('collections.copyToTrip')}
</button>
{canDelete && (
<button
type="button"
onClick={onRemove}
aria-label={t('collections.removeFromList')}
className={`${SHEET_ACTION} !flex-none px-4 text-danger`}
>
<Trash2 size={14} />
</button>
)}
</>
);
}
/**
* Saved-place detail: auto-cover hero with the category chip, the live status
* cycle (Idea → Want to go → Visited), markdown description, links, copy to
* trip and remove. Edit mode swaps the body for name / category / labels /
* description / links.
* A place of a list on the phone, in the one place view All places opens too:
* the same cover, then the list's status and votes, the description and links,
* then the same tabs (where it is kept and its tags, notes, tours and bookings,
* pictures, changes) and the things to do with it in the bottom row.
*/
export default function MCollPlaceSheet({
place, canEdit, canDelete, categories, labels, onClose, onSetStatus, onSave, onUploadImage, onCopyToTrip, onRemove, onRate, t,
place,
canEdit,
canDelete,
categories,
labels,
onClose,
onSetStatus,
onSave,
onUploadImage,
onCopyToTrip,
onRemove,
onRate,
t,
}: MCollPlaceSheetProps) {
const imageInputRef = useRef<HTMLInputElement | null>(null)
const [navOpen, setNavOpen] = useState(false)
const navBtnRef = useRef<HTMLButtonElement | null>(null)
const {
shown: held, editing, setEditing, name, setName, address, setAddress, pickPosition, positionPicked, needsPosition, categoryId, setCategoryId, description, setDescription, notes, setNotes,
links, setLinks, labelIds, toggleLabel, saving, imgBusy, cover, assignedLabels, handleImagePick, handleImageRemove, cancelEdit, save,
} = useCollectionPlaceForm({
place, labels, onSave, onUploadImage, t, normalizeLinkUrl, holdLastPlace: true, dropPhotoOnPlaceUpdate: true,
})
const navTargets = getNavigationTargets(held)
const actionBtn =
'flex flex-1 items-center justify-center gap-[6px] rounded-[13px] border border-[color:var(--m-rowbr)] bg-[color:var(--m-sheet)] px-2 py-[11px] text-[0.78125rem] font-semibold text-m-ink'
const imageInputRef = useRef<HTMLInputElement | null>(null);
const navigate = useNavigate();
const { language } = useTranslation();
// The list's own change (status, votes, an edit, a remote one) shows in the tabs too.
const library = useLibraryPlace('list', place?.id ?? null, place);
const { reload } = library;
const save = async (patch: PlacePatch) => {
await onSave(patch);
reload();
};
const form = useCollectionPlaceForm({
place,
labels,
onSave: save,
onUploadImage,
t,
normalizeLinkUrl,
holdLastPlace: true,
dropPhotoOnPlaceUpdate: true,
});
const sheet = usePlaceSheet({ data: library.data, onChanged: reload, t });
const tags = usePlaceTags({ data: library.data, onChanged: reload, t });
const held = form.shown;
const entry = library.data?.entry ?? null;
const { trips, lists } = originPairs(library.data);
return (
<MSheet open={place != null} onClose={onClose} material="glass" className="!rounded-[24px]" ariaLabel={held?.name}>
{held && (
<MPlaceSheetShell
open={place != null}
name={held?.name ?? null}
category={held?.category}
cover={form.cover}
seed={held?.id ?? 0}
// While editing, the form's address and position fields stand for them (#1870).
address={form.editing ? null : held?.address}
lat={form.editing ? null : held?.lat}
lng={form.editing ? null : held?.lng}
onClose={onClose}
t={t}
controls={
held &&
canEdit &&
onUploadImage && (
<>
<input
ref={imageInputRef}
type="file"
accept="image/jpeg,image/png,image/gif,image/webp,.heic,.heif"
className="hidden"
onChange={form.handleImagePick}
/>
{held.image_url && !form.imgBusy && (
<button
type="button"
onClick={form.handleImageRemove}
aria-label={t('places.removeImage')}
className={COVER_BTN}
>
<Trash2 size={15} />
</button>
)}
<button
type="button"
onClick={() => {
if (!form.imgBusy) imageInputRef.current?.click();
}}
aria-label={held.image_url ? t('places.changeImage') : t('places.uploadImage')}
className={COVER_BTN}
>
{form.imgBusy ? <Loader2 size={15} className="animate-spin" /> : <Camera size={15} />}
</button>
</>
)
}
footer={
held && (
<Actions
place={held}
form={form}
canEdit={canEdit}
canDelete={canDelete}
onCopyToTrip={onCopyToTrip}
onRemove={onRemove}
t={t}
/>
)
}
>
{held && form.editing && <EditForm form={form} categories={categories} t={t} />}
{held && !form.editing && (
<>
{/* Hero: auto cover (photo when available, the design gradient otherwise) */}
<div
className="relative flex-none px-[18px] pb-4 pt-[14px]"
style={cover ? undefined : { background: 'linear-gradient(120deg,#2FA9A0,#3B8C7E)' }}
>
{cover && (
<>
<img src={cover} alt="" className="absolute inset-0 h-full w-full object-cover" />
<div className="absolute inset-0 bg-[linear-gradient(180deg,rgba(0,0,0,.18),rgba(0,0,0,.44))]" />
</>
)}
{/* Chip and cover controls share the top row, in flow: the name always
starts below the buttons, chip or not, and a long category name
ellipsizes against them instead of running underneath. */}
<div className="relative flex items-center gap-2">
{held.category?.name && (
<span className={HERO_CAT_CHIP}>
<MapPin size={9} strokeWidth={2.6} className="flex-none" />
<span dir="auto" className="truncate">{held.category.name}</span>
</span>
)}
{/* -me-1 keeps the buttons 14px off the edge, where close has always sat. */}
<div className="-me-1 ms-auto flex flex-none gap-[6px]">
{canEdit && onUploadImage && (
<>
<input ref={imageInputRef} type="file" accept="image/jpeg,image/png,image/gif,image/webp,.heic,.heif" className="hidden" onChange={handleImagePick} />
{held.image_url && !imgBusy && (
<button type="button" onClick={handleImageRemove} aria-label={t('places.removeImage')} className={HERO_BTN}>
<Trash2 size={15} strokeWidth={2.2} />
</button>
)}
<button
type="button"
onClick={() => { if (!imgBusy) imageInputRef.current?.click() }}
aria-label={held.image_url ? t('places.changeImage') : t('places.uploadImage')}
className={HERO_BTN}
>
{imgBusy ? <Loader2 size={15} strokeWidth={2.2} className="animate-spin" /> : <Camera size={15} strokeWidth={2.2} />}
</button>
</>
)}
<button type="button" onClick={onClose} aria-label={t('common.close')} className={HERO_BTN}>
<X size={15} strokeWidth={2.2} />
</button>
</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 className="mt-3">
<StatusGrid status={held.status} canEdit={canEdit} onSet={onSetStatus} t={t} />
</div>
<div className="min-h-0 flex-1 overflow-y-auto px-[18px] pb-[18px] pt-[14px]">
{/* 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">
{STATUS_ORDER.map(s => {
const meta = STATUS_SPEC[s]
const Icon = meta.icon
const on = held.status === s
return (
<button
key={s}
type="button"
disabled={!canEdit}
onClick={() => onSetStatus(s)}
aria-pressed={on}
className={`flex flex-1 items-center justify-center gap-[5px] rounded-[12px] py-[9px] text-[0.71875rem] font-bold ${
on ? 'bg-m-act text-m-actfg' : 'bg-m-sheetop text-m-ink shadow-[inset_0_0_0_1.5px_var(--m-rowbr)]'
}`}
>
<Icon size={13} strokeWidth={2.2} style={on ? undefined : { color: meta.color }} />
<span className="truncate">{t(meta.labelKey)}</span>
</button>
)
})}
{/* Collaborative rating (#1435): tap a star to cast or clear your vote. */}
{onRate && (
<div className="mt-3 flex min-h-[46px] items-center rounded-[14px] border border-m-rowbr bg-m-sheet px-3 py-2">
<PlaceRating ratings={held.ratings ?? []} ratingAvg={held.rating_avg} onRate={onRate} size={18} />
</div>
{/* Collaborative rating (#1435) — tap a star to cast/clear your vote. */}
{onRate && (
<div className="mt-3">
<PlaceRating ratings={held.ratings ?? []} ratingAvg={held.rating_avg} onRate={onRate} size={18} />
</div>
)}
{editing ? (
<>
<Eyebrow className="mb-[6px] mt-4">{t('common.name').toUpperCase()}</Eyebrow>
<MCollCategoryPicker variant="tile" categories={categories} value={categoryId} onChange={setCategoryId} t={t}>
<input value={name} onChange={e => setName(e.target.value)} className={INPUT_CLS} />
</MCollCategoryPicker>
{/* Address (#1870): free text, same as the add sheet offers */}
<Eyebrow className="mb-[6px] mt-[14px]">{t('places.formAddress').toUpperCase()}</Eyebrow>
<input value={address} onChange={e => setAddress(e.target.value)} placeholder={t('places.formAddressPlaceholder')} className={INPUT_CLS} />
{needsPosition && <MCollLocationSearch picked={positionPicked} onPick={pickPosition} t={t} />}
{labels.length > 0 && (
<>
<Eyebrow className="mb-[6px] mt-[14px]">{t('collections.labels.title').toUpperCase()}</Eyebrow>
<div className="flex flex-wrap gap-[6px]">
{labels.map(l => {
const on = labelIds.includes(l.id)
const color = l.color || '#6366F1'
return (
<button
key={l.id}
type="button"
onClick={() => toggleLabel(l.id)}
aria-pressed={on}
className="flex items-center gap-[5px] rounded-full border px-3 py-[7px] text-[0.71875rem] font-bold"
style={on
? { background: `${color}18`, color, borderColor: `${color}2e` }
: { background: 'var(--m-ic)', color: 'var(--m-ink)', borderColor: 'var(--m-rowbr)' }}
>
<span className="h-[7px] w-[7px] rounded-full" style={{ background: color }} />
{l.name}
</button>
)
})}
</div>
</>
)}
<Eyebrow className="mb-[6px] mt-[14px]">{t('collections.description').toUpperCase()}</Eyebrow>
<textarea rows={4} value={description} onChange={e => setDescription(e.target.value)} placeholder={t('collections.descriptionPlaceholder')} className={TEXTAREA_CLS} />
<Eyebrow className="mb-[6px] mt-[14px]">{t('collections.notes').toUpperCase()}</Eyebrow>
<textarea rows={3} value={notes} onChange={e => setNotes(e.target.value)} placeholder={t('collections.notesPlaceholder')} className={TEXTAREA_CLS} />
<Eyebrow className="mb-[6px] mt-[14px]">{t('collections.links').toUpperCase()}</Eyebrow>
<MCollLinksEditor links={links} onChange={setLinks} t={t} />
<div className="mt-4 flex items-center gap-2">
<CancelPill className="ms-auto" onClick={cancelEdit}>{t('common.cancel')}</CancelPill>
<PrimaryPill onClick={save} disabled={saving}>
<Check size={14} strokeWidth={2.4} /> {t('common.save')}
</PrimaryPill>
</div>
</>
) : (
<>
{assignedLabels.length > 0 && (
<div className="mt-3 flex flex-wrap gap-[6px]">
{assignedLabels.map(l => {
const color = l.color || '#6366F1'
return (
<span
key={l.id}
className="inline-flex items-center gap-[5px] rounded-full px-[10px] py-[5px] font-geist text-[0.625rem] font-bold"
style={{ background: `${color}18`, color }}
>
<span className="h-[7px] w-[7px] rounded-full" style={{ background: color }} />
{l.name}
</span>
)
})}
</div>
)}
{held.description && (
<div className="collab-note-md mt-3 font-geist text-[0.78125rem] leading-[1.55] text-m-ink">
<Markdown remarkPlugins={[remarkGfm, remarkBreaks]}>{held.description}</Markdown>
</div>
)}
{/* The traveller's own notes (#3168), the way the place sheet of a trip shows them. */}
{held.notes?.trim() && (
<>
<Eyebrow className="mb-[6px] mt-[14px]">{t('collections.notes').toUpperCase()}</Eyebrow>
<p className="m-0 whitespace-pre-wrap rounded-[14px] bg-m-card px-[13px] py-[10px] font-geist text-caption leading-[1.55] text-m-muted [overflow-wrap:anywhere]">
{held.notes}
</p>
</>
)}
{held.links && held.links.length > 0 && (
<div className="mt-3 flex flex-wrap gap-[6px]">
{held.links.map((l, i) => (
<a
key={i}
href={l.url}
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center gap-[5px] rounded-full border border-[color:var(--m-rowbr)] bg-[color:var(--m-sheet)] px-3 py-[7px] text-[0.71875rem] font-semibold text-m-ink"
>
<ExternalLink size={13} strokeWidth={2} className="text-m-muted" /> {l.label || linkHost(l.url)}
</a>
))}
</div>
)}
{/* Collections are a store of places to go to, so the way there leads
the actions, as it does in the trip's place sheet (#2091). One
app offered opens straight away; more open the same picker. */}
{navTargets.length > 0 && (
<>
<button
ref={navBtnRef}
type="button"
onClick={() => (navTargets.length === 1 ? openNavigationTarget(navTargets[0]) : setNavOpen(true))}
className="mt-[14px] flex w-full items-center justify-center gap-[6px] rounded-[13px] bg-[color:var(--m-act)] px-2 py-[11px] text-[0.78125rem] font-semibold text-[color:var(--m-actfg)]"
>
<Navigation size={14} strokeWidth={2.2} />
{navTargets.length === 1 ? navigationTargetLabel(navTargets[0], t) : t('inspector.navigation')}
</button>
{navOpen && (
<NavigationMenu
targets={navTargets}
anchor={navBtnRef.current}
onClose={() => setNavOpen(false)}
title={t('inspector.openWith')}
/>
)}
</>
)}
<div className={`${navTargets.length > 0 ? 'mt-2' : 'mt-[14px]'} flex gap-2`}>
{canEdit && (
<button type="button" onClick={() => setEditing(true)} className={actionBtn}>
<Pencil size={13} strokeWidth={2.2} /> {t('common.edit')}
</button>
)}
<button type="button" onClick={onCopyToTrip} className={actionBtn}>
<Copy size={13} strokeWidth={2.2} /> {t('collections.copyToTrip')}
</button>
</div>
{canDelete && (
<button
type="button"
onClick={onRemove}
className="mt-[10px] flex w-full items-center justify-center gap-[6px] rounded-[13px] p-[11px] text-[0.78125rem] font-bold text-[color:var(--m-st-danger)]"
>
<Trash2 size={14} strokeWidth={2} /> {t('collections.removeFromList')}
</button>
)}
</>
)}
</div>
)}
{held.description && (
<div className="collab-note-md mt-3 text-body leading-[1.55] text-m-ink">
<Markdown remarkPlugins={[remarkGfm, remarkBreaks]}>{held.description}</Markdown>
</div>
)}
{held.links && held.links.length > 0 && (
<div className="mt-3 flex flex-wrap gap-[6px]">
{held.links.map((l, i) => (
<a
key={i}
href={l.url}
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center gap-[5px] rounded-full border border-m-rowbr bg-m-sheet px-3 py-[7px] text-caption font-semibold text-m-ink"
>
<ExternalLink size={13} className="text-m-muted" /> {l.label || linkHost(l.url)}
</a>
))}
</div>
)}
<MPlaceSheetTabs
sheet={sheet}
language={language}
t={t}
overview={
entry && (
<>
<MPlaceTagsCard tags={tags} t={t} />
<MPlaceOrigins
entry={entry}
trips={trips}
lists={lists}
language={language}
onOpenTrip={(tripId, placeId) => void navigate(`/trips/${tripId}?place=${placeId}`)}
onOpenList={(collectionId, placeId) =>
void navigate(`${placesPath(collectionId)}?place=${placeId}`)
}
t={t}
/>
</>
)
}
/>
</>
)}
</MSheet>
)
</MPlaceSheetShell>
);
}
@@ -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, personalTagIds, togglePersonalTag } =
const { loading, search, setSearch, filtered, busyTripId, dateRange, handleCopy, offersCarry, includeNotes, setIncludeNotes, tagIds, toggleTag } =
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} personalTagIds={personalTagIds} onTogglePersonalTag={togglePersonalTag} variant="sheet" t={t} />
<CopyCarryPanel options={carryOptions} includeNotes={includeNotes} onIncludeNotes={setIncludeNotes} tagIds={tagIds} onToggleTag={toggleTag} variant="sheet" t={t} />
</div>
)}
{loading ? (
@@ -508,6 +508,7 @@ export default function MCollections() {
onOpen={c.setSelectedPlaceId}
onToggleSelect={c.toggleSelect}
onSetStatus={(id: number, status: CollectionStatus) => c.handleStatusChange(id, status)}
tags={(p.label_ids ?? []).flatMap(id => c.labels.filter(l => l.id === id)).map(l => ({ name: l.name, color: l.color ?? null }))}
reorder={reorder.enabled ? {
handle: reorder.handleProps(p.id),
row: reorder.rowProps(p.id),
@@ -1,159 +0,0 @@
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,35 +1,20 @@
import type { PlacesLibraryDetailResponse } from '@trek/shared';
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 {
originPairs,
type ListPair,
type TripDetail,
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,
openNavigationTarget,
} from '../../../components/Planner/placeNavigation';
import { BookmarkPlus, Check, Copy, Loader2, Navigation, Pencil } from 'lucide-react';
import { useRef, useState } from 'react';
import { originPairs, type TripDetail, type TripOrigin } from '../../../components/Collections/libraryPairs';
import PlaceRatingRow from '../../../components/Collections/PlaceRatingRow';
import { usePlaceEdit, type PlaceEditState } from '../../../components/Collections/usePlaceEdit';
import { usePlaceRating } from '../../../components/Collections/usePlaceRating';
import { usePlaceSheet } from '../../../components/Collections/usePlaceSheet';
import { usePlaceTags } from '../../../components/Collections/usePlaceTags';
import { getNavigationTargets, openNavigationTarget } from '../../../components/Planner/placeNavigation';
import { NavigationMenu } from '../../../components/shared/NavigationMenu';
import type { TranslationFn } from '../../../types';
import { entityGradient } from '../../../utils/gradients';
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';
import type { Category, TranslationFn } from '../../../types';
import MPlaceEditForm from './MPlaceEditForm';
import MPlaceOrigins from './MPlaceOrigins';
import MPlaceSheetShell, { SHEET_ACTION } from './MPlaceSheetShell';
import MPlaceSheetTabs from './MPlaceSheetTabs';
import MPlaceTagsCard from './MPlaceTagsCard';
interface MLibraryPlaceSheetProps {
open: boolean;
@@ -37,234 +22,81 @@ interface MLibraryPlaceSheetProps {
loading: boolean;
cover: string | null;
language: string;
categories: Category[];
onClose: () => void;
onOpenList: (collectionId: number, collectionPlaceId: number) => void;
onOpenTrip: (tripId: number, placeId: number) => void;
onSaveToList: (origin: TripOrigin, detail: TripDetail) => void;
onCopyToTrip: (collectionPlaceId: number) => void;
/** A note was saved: read the place again. */
/** Something of the place was saved: read it again. */
onNotesSaved: () => void;
t: TranslationFn;
}
const CARD = 'flex w-full flex-col gap-[9px] 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';
const CHIP =
'inline-flex items-center gap-1 rounded-full border border-m-rowbr bg-m-ic px-[9px] py-[3px] text-caption font-semibold text-m-muted';
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';
type Entry = NonNullable<PlacesLibraryDetailResponse['entry']>;
/** The cover band: the picture or a gradient, the category, the close button and the name. */
function SheetCover({
/** The bottom row: edit, get there, save the trip's place to a list, copy the list's place to a trip. */
function Actions({
entry,
cover,
onClose,
t,
}: {
entry: Entry | null;
cover: string | null;
onClose: () => void;
t: TranslationFn;
}) {
const meta = categoryMeta(entry?.category) ?? UNCATEGORIZED_META;
const gradient = entry ? entry.name.length + entry.key.length : 0;
return (
<div
className="relative h-[150px] flex-none overflow-hidden"
style={cover ? undefined : { backgroundImage: entityGradient(gradient) }}
>
{cover && <img src={cover} alt="" className="absolute inset-0 h-full w-full object-cover" />}
<div className="m-libcover-scrim absolute inset-0" />
<div className="absolute inset-x-3 top-3 flex items-center gap-2">
{entry?.category && (
<span
className="inline-flex min-w-0 items-center gap-1 rounded-full bg-m-sheetop px-[10px] py-[3px] text-caption font-bold"
style={{ color: meta.color }}
>
{createElement(meta.icon, { size: 12, className: 'flex-none' })}{' '}
<span className="truncate">{entry.category.name}</span>
</span>
)}
<button
type="button"
onClick={onClose}
aria-label={t('common.close')}
className="m-libcover-btn ms-auto flex h-8 w-8 items-center justify-center rounded-full"
>
<X size={16} />
</button>
</div>
{entry && (
<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>
);
}
/** A trip the place is in: its day or dates, whether it is only readable, and what the trip keeps. */
function TripCard({
pair,
entryName,
language,
onOpen,
t,
}: {
pair: TripPair;
entryName: string;
language: string;
onOpen: () => void;
t: TranslationFn;
}) {
const { origin, detail } = pair;
const line = tripLine(origin, detail, language, t);
const renamed = detail.info.name !== entryName;
return (
<button
type="button"
className={CARD}
onClick={onOpen}
aria-label={`${t('collections.library.openTrip')}: ${originName(origin)}`}
>
<span className="flex items-center gap-[10px]">
<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">
{originName(origin)}
</span>
{line && <span className="block truncate text-caption text-m-muted">{line}</span>}
</span>
{origin.read_only && <span className={CHIP}>{t('collections.library.readOnly')}</span>}
<ChevronRight size={16} className="flex-none text-m-faint rtl:-scale-x-100" />
</span>
{(detail.has_accommodation || detail.has_reservation || renamed) && (
<span className="flex flex-wrap gap-[6px]">
{renamed && <span className={CHIP}>{t('collections.library.calledHere', { name: detail.info.name })}</span>}
{detail.has_accommodation && (
<span className={CHIP}>
<Hotel size={11} /> {t('collections.library.stay')}
</span>
)}
{detail.has_reservation && (
<span className={CHIP}>
<Ticket size={11} /> {t('collections.library.booking')}
</span>
)}
</span>
)}
</button>
);
}
/** A list the place is in: its status there, its labels and the list's vote. */
function ListCard({
pair,
entryName,
onOpen,
t,
}: {
pair: ListPair;
entryName: string;
onOpen: () => void;
t: TranslationFn;
}) {
const { origin, detail } = pair;
const status = STATUS_SPEC[origin.status];
const renamed = detail.info.name !== entryName;
const average = detail.rating.average;
return (
<button
type="button"
className={CARD}
onClick={onOpen}
aria-label={`${t('collections.library.openList')}: ${originName(origin)}`}
>
<span className="flex items-center gap-[10px]">
<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)}
</span>
<span
className="inline-flex flex-none items-center gap-1 rounded-full px-[9px] py-[3px] text-caption font-bold"
style={{ background: tint(status.color, '1f'), color: status.color }}
>
{createElement(status.icon, { size: 11 })} {t(status.labelKey)}
</span>
<ChevronRight size={16} className="flex-none text-m-faint rtl:-scale-x-100" />
</span>
{(detail.labels.length > 0 || average != null || renamed) && (
<span className="flex flex-wrap gap-[6px]">
{renamed && <span className={CHIP}>{t('collections.library.calledHere', { name: detail.info.name })}</span>}
{detail.labels.map((label) => (
<span key={label.id} className={CHIP}>
<span className="h-2 w-2 rounded-full" style={{ background: label.color || 'var(--m-act)' }} />{' '}
{label.name}
</span>
))}
{average != null && (
<span className={CHIP}>
<Star size={11} />{' '}
{t('collections.library.rating', { rating: average.toFixed(1), count: detail.rating.count })}
</span>
)}
</span>
)}
</button>
);
}
/** Navigate there, save the trip's place to a list, copy the list's place to a trip. */
function SheetActions({
entry,
trip,
list,
data,
edit,
onSaveToList,
onCopyToTrip,
t,
}: {
entry: Entry;
trip: TripPair | undefined;
list: ListPair | undefined;
data: PlacesLibraryDetailResponse | null;
edit: PlaceEditState;
onSaveToList: (origin: TripOrigin, detail: TripDetail) => void;
onCopyToTrip: (collectionPlaceId: number) => void;
t: TranslationFn;
}) {
const [navOpen, setNavOpen] = useState(false);
const navRef = useRef<HTMLButtonElement | null>(null);
const { trips, lists } = originPairs(data);
const trip = trips[0];
const list = lists[0];
const targets = getNavigationTargets({ name: entry.name, address: entry.address, lat: entry.lat, lng: entry.lng });
const single = targets.length === 1 ? targets[0] : null;
if (edit.editing) {
return (
<>
<button type="button" onClick={edit.cancel} className={SHEET_ACTION}>
{t('common.cancel')}
</button>
<button
type="button"
onClick={() => void edit.save()}
disabled={edit.saving}
className="flex flex-1 items-center justify-center gap-[6px] rounded-[13px] bg-m-act px-2 py-[11px] text-caption font-bold text-m-actfg"
>
<Check size={14} /> {t('common.save')}
</button>
</>
);
}
return (
<div className="mt-4 flex gap-2">
<>
{edit.canEdit && (
<button
type="button"
onClick={edit.start}
aria-label={t('common.edit')}
className={`${SHEET_ACTION} !flex-none px-4`}
>
<Pencil size={14} />
</button>
)}
{targets.length > 0 && (
<>
<button
ref={navRef}
type="button"
className={ACTION}
aria-label={t('inspector.navigation')}
className={`${SHEET_ACTION} !flex-none px-4`}
onClick={() => (single ? openNavigationTarget(single) : setNavOpen((o) => !o))}
>
<Navigation size={14} /> {single ? navigationTargetLabel(single, t) : t('inspector.navigation')}
<Navigation size={14} />
</button>
{navOpen && (
<NavigationMenu
@@ -276,109 +108,108 @@ function SheetActions({
)}
</>
)}
{trip && (
<button type="button" className={ACTION} onClick={() => onSaveToList(trip.origin, trip.detail)}>
{trip && !list && (
<button type="button" className={SHEET_ACTION} onClick={() => onSaveToList(trip.origin, trip.detail)}>
<BookmarkPlus size={14} /> {t('inspector.saveToCollection')}
</button>
)}
{list && (
<button type="button" className={ACTION} onClick={() => onCopyToTrip(list.origin.collection_place_id)}>
<button type="button" className={SHEET_ACTION} onClick={() => onCopyToTrip(list.origin.collection_place_id)}>
<Copy size={14} /> {t('collections.copyToTrip')}
</button>
)}
</div>
</>
);
}
/** Where it is, its description, its trips and lists, and what to do with it. */
function SheetBody({
entry,
/**
* One place of All places on the phone (PLC-08), in the one place view a list's
* place opens too: the cover, the description, then the same tabs as on the
* desktop, and the things to do with it in the bottom row.
*/
export default function MLibraryPlaceSheet({
open,
data,
loading,
cover,
language,
categories,
onClose,
onOpenList,
onOpenTrip,
onSaveToList,
onCopyToTrip,
onNotesSaved,
t,
}: Omit<MLibraryPlaceSheetProps, 'open' | 'loading' | 'cover' | 'onClose'> & { entry: Entry }) {
}: MLibraryPlaceSheetProps) {
const entry = data?.entry ?? null;
const { trips, lists, description } = originPairs(data);
const sheet = usePlaceSheet({ data, onChanged: onNotesSaved, t });
const tags = usePlaceTags({ data, onChanged: onNotesSaved, t });
const edit = usePlaceEdit({ data, onSaved: onNotesSaved, t });
const rating = usePlaceRating({ data, onChanged: onNotesSaved, t });
return (
<>
{description && (
<p dir="auto" className="m-0 mt-3 whitespace-pre-wrap text-body text-m-ink">
{description}
</p>
<MPlaceSheetShell
open={open}
name={entry?.name ?? null}
category={entry?.category}
cover={cover}
seed={entry ? entry.name.length + entry.key.length : 0}
address={entry?.address}
lat={entry?.lat}
lng={entry?.lng}
onClose={onClose}
t={t}
footer={
entry && (
<Actions
entry={entry}
data={data}
edit={edit}
onSaveToList={onSaveToList}
onCopyToTrip={onCopyToTrip}
t={t}
/>
)
}
>
{loading && !entry && (
<div className="flex justify-center py-10 text-m-faint">
<Loader2 size={20} className="animate-spin" />
</div>
)}
{trips.length > 0 && (
{entry && edit.editing && <MPlaceEditForm edit={edit} categories={categories} t={t} />}
{entry && !edit.editing && (
<>
<Eyebrow className="mb-[6px] mt-4">{t('collections.library.inTrips').toUpperCase()}</Eyebrow>
<div className="flex flex-col gap-2">
{trips.map((pair) => (
<TripCard
key={pair.origin.place_id}
pair={pair}
entryName={entry.name}
language={language}
onOpen={() => onOpenTrip(pair.origin.trip_id, pair.origin.place_id)}
t={t}
/>
))}
<div className="mt-3 flex min-h-[46px] items-center rounded-[14px] border border-m-rowbr bg-m-sheet px-3 py-2">
<PlaceRatingRow rating={rating} />
</div>
{description && (
<p dir="auto" className="m-0 mt-3 whitespace-pre-wrap text-body text-m-ink">
{description}
</p>
)}
<MPlaceSheetTabs
sheet={sheet}
language={language}
t={t}
overview={
<>
<MPlaceTagsCard tags={tags} t={t} />
<MPlaceOrigins
entry={entry}
trips={trips}
lists={lists}
language={language}
onOpenTrip={onOpenTrip}
onOpenList={onOpenList}
t={t}
/>
</>
}
/>
</>
)}
{lists.length > 0 && (
<>
<Eyebrow className="mb-[6px] mt-4">{t('collections.library.inLists').toUpperCase()}</Eyebrow>
<div className="flex flex-col gap-2">
{lists.map((pair) => (
<ListCard
key={pair.origin.collection_place_id}
pair={pair}
entryName={entry.name}
onOpen={() => onOpenList(pair.origin.collection_id, pair.origin.collection_place_id)}
t={t}
/>
))}
</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]}
list={lists[0]}
onSaveToList={onSaveToList}
onCopyToTrip={onCopyToTrip}
t={t}
/>
</>
);
}
/**
* One place of "All places" on the phone (PLC-08): the sheet a list's place opens
* in, with the cover, then every trip and list the place sits in and what each
* keeps of it, and the things to do with it at the bottom.
*/
export default function MLibraryPlaceSheet({ open, loading, cover, onClose, ...rest }: MLibraryPlaceSheetProps) {
const entry = rest.data?.entry ?? null;
return (
<MSheet open={open} onClose={onClose} ariaLabel={entry?.name ?? rest.t('collections.library.title')}>
<SheetCover entry={entry} cover={cover} onClose={onClose} t={rest.t} />
<div className="min-h-0 flex-1 overflow-y-auto px-4 pb-4 pt-3">
{loading && !entry && (
<div className="flex justify-center py-10 text-m-faint">
<Loader2 size={20} className="animate-spin" />
</div>
)}
{entry && <SheetBody entry={entry} {...rest} />}
</div>
</MSheet>
</MPlaceSheetShell>
);
}
@@ -1,10 +1,172 @@
import type { PlacesLibraryDetailResponse } from '@trek/shared';
import { Bookmark, Luggage, Pencil, Plus } from 'lucide-react';
import { Bookmark, Eye, Layers, Luggage, NotebookPen, Pencil, PenLine } from 'lucide-react';
import Markdown from 'react-markdown';
import remarkBreaks from 'remark-breaks';
import remarkGfm from 'remark-gfm';
import { useOriginNotes } from '../../../components/Collections/useOriginNotes';
import { markdownLinkComponents } from '../../../components/shared/markdownLink';
import type { TranslationFn } from '../../../types';
import { CancelPill, Eyebrow, PrimaryPill, TEXTAREA_CLS } from './MCollSheetKit';
import { CancelPill, PrimaryPill } from './MCollSheetKit';
import MPlaceCard from './MPlaceCard';
type Notes = ReturnType<typeof useOriginNotes>;
const SourceIcon = ({ kind }: { kind: 'trip' | 'list' }) =>
kind === 'trip' ? <Luggage size={12} /> : <Bookmark size={12} />;
const CHIP = 'inline-flex h-[30px] items-center gap-[5px] rounded-full px-3 text-caption font-semibold';
const CHIP_ON = `${CHIP} border border-m-act bg-m-ic text-m-ink`;
const CHIP_OFF = `${CHIP} border border-m-rowbr bg-m-ic text-m-ink`;
function Rendered({ text }: { text: string }) {
return (
<div className="collab-note-md text-body leading-[1.55] text-m-ink [overflow-wrap:anywhere]">
<Markdown remarkPlugins={[remarkGfm, remarkBreaks]} components={markdownLinkComponents}>
{text}
</Markdown>
</div>
);
}
/** Writing a note on the phone: where it goes, write or preview, save. */
function MNoteEditor({ n, t }: { n: Notes; t: TranslationFn }) {
const current = n.composeTargets.find((x) => x.key === n.editing) ?? n.notes.find((x) => x.key === n.editing);
const multi = n.isNew && n.composeTargets.length > 1;
return (
<>
{multi && (
<div className="flex flex-wrap items-center gap-[6px] rounded-[14px] border border-m-rowbr bg-m-inner py-[6px] pe-[6px] ps-3">
<span className="me-1 text-caption font-semibold text-m-faint">{t('placeNotes.for')}</span>
<button
type="button"
aria-pressed={n.everywhere}
onClick={() => n.retarget('all')}
className={n.everywhere ? CHIP_ON : CHIP_OFF}
>
<Layers size={12} /> {t('placeMedia.everywhere')}
</button>
{n.composeTargets.map((x) => {
const on = !n.everywhere && x.key === n.editing;
return (
<button
key={x.key}
type="button"
aria-pressed={on}
onClick={() => n.retarget(x.key)}
className={on ? CHIP_ON : CHIP_OFF}
>
<SourceIcon kind={x.kind} /> {x.source}
</button>
);
})}
</div>
)}
<div className="flex flex-col gap-2 rounded-[14px] border border-m-rowbr bg-m-inner p-3">
{!multi && current && (
<div className="flex items-center gap-[6px] text-caption font-semibold text-m-faint">
<SourceIcon kind={current.kind} />
<span className="min-w-0 flex-1 truncate">{current.source}</span>
</div>
)}
<div className="flex gap-1 self-start rounded-full border border-m-rowbr bg-m-ic p-[3px]">
{[false, true].map((preview) => (
<button
key={String(preview)}
type="button"
aria-pressed={n.preview === preview}
onClick={() => n.setPreview(preview)}
className={
n.preview === preview
? 'inline-flex items-center gap-1 rounded-full bg-m-sheet px-3 py-[5px] text-caption font-bold text-m-ink'
: 'inline-flex items-center gap-1 rounded-full px-3 py-[5px] text-caption font-semibold text-m-muted'
}
>
{preview ? <Eye size={12} /> : <PenLine size={12} />}
{t(preview ? 'placeNotes.preview' : 'placeNotes.write')}
</button>
))}
</div>
{n.preview ? (
<div className="min-h-[120px] rounded-[12px] border border-m-rowbr bg-m-sheet px-3 py-[10px]">
{n.draft.trim() ? (
<Rendered text={n.draft} />
) : (
<span className="text-caption text-m-muted">{t('placeNotes.nothingYet')}</span>
)}
</div>
) : (
<textarea
autoFocus
rows={6}
value={n.draft}
onChange={(e) => n.setDraft(e.target.value)}
placeholder={t('placeNotes.placeholder')}
aria-label={current ? t('placeNotes.fieldLabel', { source: current.source }) : t('collections.notes')}
className="min-h-[120px] w-full resize-none rounded-[12px] border border-m-rowbr bg-m-sheet px-3 py-[10px] text-body leading-[1.55] text-m-ink outline-none placeholder:text-m-faint"
/>
)}
<span className="text-caption text-m-faint">{t('placeNotes.markdownHint')}</span>
<div className="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>
</div>
</>
);
}
/** The notes of a place on the phone (PLC-17), the desktop view's twin: rendered notes, a field to write one, the editor. */
export function MOriginNotesView({ state: n, t }: { state: Notes; t: TranslationFn }) {
if (n.notes.length === 0 && n.targets.length === 0 && !n.editing) return null;
return (
<MPlaceCard
icon={<NotebookPen size={14} />}
title={t('collections.notes')}
count={n.notes.filter((x) => x.text.trim()).length}
>
{n.notes.map((note) =>
n.editing === note.key && !n.isNew ? (
<MNoteEditor key={note.key} n={n} t={t} />
) : (
note.text.trim() && (
<article key={note.key} className="flex flex-col gap-1 rounded-[14px] border border-m-inbr bg-m-inner p-3">
<div className="flex items-center gap-[6px] text-caption font-semibold text-m-faint">
<SourceIcon kind={note.kind} />
<span className="min-w-0 flex-1 truncate">{note.source}</span>
{note.canEdit && (
<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>
<Rendered text={note.text} />
</article>
)
)
)}
{n.isNew && <MNoteEditor n={n} t={t} />}
{!n.editing && n.targets.length > 0 && (
<button
type="button"
onClick={n.compose}
className="flex w-full items-center gap-[10px] rounded-[14px] border border-m-rowbr bg-m-inner px-[14px] py-3 text-start text-body text-m-muted"
>
<PenLine size={15} /> {t('placeNotes.composer')}
</button>
)}
</MPlaceCard>
);
}
/** 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,
@@ -15,80 +177,5 @@ export default function MOriginNotesSection({
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>
</>
);
return <MOriginNotesView state={n} t={t} />;
}
@@ -1,19 +1,114 @@
import type { PlaceActivity, PlacesLibraryEntry } from '@trek/shared';
import { ChevronRight, Plus, Route, Ticket, X } from 'lucide-react';
import { ChevronRight, Link2, 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';
import MPlaceCard, { M_ICO, M_ROW } from './MPlaceCard';
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. */
/** The tours and bookings of a place on the phone (PLC-18); the logic is the desktop view's. */
export function MPlaceActivitiesView({
state: a,
language,
t,
}: {
state: ReturnType<typeof usePlaceActivities>;
language: string;
t: TranslationFn;
}) {
const navigate = useNavigate();
if (a.activities.length === 0 && !a.canLink) return null;
return (
<MPlaceCard
icon={<Ticket size={14} />}
title={t('placeActivities.title')}
count={a.activities.length}
action={
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="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>
)
}
>
{a.activities.map((act) => (
<div key={`${act.key}:${act.source.kind}`} className={M_ROW}>
<span className={M_ICO}>
<ActivityIcon type={act.type} />
</span>
<button type="button" onClick={() => void 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 && (
<button
type="button"
onClick={() => void a.openPicker()}
disabled={!a.canLink || a.busy}
className="flex w-full items-center gap-[10px] rounded-[14px] border border-m-rowbr bg-m-inner px-[14px] py-3 text-start text-body text-m-muted"
>
<Link2 size={15} /> {t('placeActivities.none')}
</button>
)}
{a.picking && (
<div className="rounded-[14px] border border-m-inbr bg-m-inner p-2">
<div className="-mx-2 mb-1 flex items-center gap-2 border-b border-m-rowbr px-3 pb-2 pt-1 text-body font-bold text-m-ink">
<Link2 size={13} /> <span className="flex-1">{t('placeActivities.pickTitle')}</span>
</div>
{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={M_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>
)}
</MPlaceCard>
);
}
export default function MPlaceActivitiesSection({
entry,
language,
@@ -23,81 +118,6 @@ export default function MPlaceActivitiesSection({
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>
</>
);
return <MPlaceActivitiesView state={a} language={language} t={t} />;
}
@@ -0,0 +1,47 @@
import type { ReactNode } from 'react';
/** A row inside a card on the phone: one step lower than the card's own ground. */
export const M_ROW =
'flex w-full items-center gap-[10px] rounded-[14px] border border-m-inbr bg-m-inner p-[10px] text-start';
export const M_ICO = 'flex h-[34px] w-[34px] flex-none items-center justify-center rounded-[10px] bg-m-ic text-m-muted';
/**
* One group of the place view on the phone (tags, visits, notes, tours, pictures,
* changes), the desktop card's twin: its own ground, a head of icon, title, count
* and action, then its rows.
*/
export default function MPlaceCard({
icon,
title,
count,
action,
children,
}: {
icon: ReactNode;
title: string;
count?: number;
action?: ReactNode;
children?: ReactNode;
}) {
return (
<section
aria-label={title}
className="flex flex-col gap-[10px] rounded-[20px] border border-m-rowbr bg-m-sheet p-3"
>
<header className="flex min-h-[28px] items-center gap-2">
<span
aria-hidden="true"
className="flex h-7 w-7 flex-none items-center justify-center rounded-[9px] bg-m-ic text-m-muted"
>
{icon}
</span>
<span className="text-body font-bold text-m-ink">{title}</span>
{!!count && (
<span className="rounded-full bg-m-ic px-[7px] py-px text-caption font-bold text-m-muted">{count}</span>
)}
{action && <span className="ms-auto flex items-center gap-1">{action}</span>}
</header>
{children}
</section>
);
}
@@ -0,0 +1,69 @@
import type { PlaceEditState } from '../../../components/Collections/usePlaceEdit';
import { NumericInput } from '../../../components/shared/NumericInput';
import type { Category, TranslationFn } from '../../../types';
import MCollCategoryPicker from './MCollCategoryPicker';
import { Eyebrow, INPUT_CLS, TEXTAREA_CLS } from './MCollSheetKit';
/**
* Editing a place of All places on the phone, the desktop form's twin: name and
* category, address, position and description, made on every copy the reader may
* edit. Save and cancel sit in the sheet's bottom row.
*/
export default function MPlaceEditForm({
edit,
categories,
t,
}: {
edit: PlaceEditState;
categories: Category[];
t: TranslationFn;
}) {
const { draft, target } = edit;
if (!draft || !target) return null;
return (
<div className="flex flex-col pt-3">
<Eyebrow className="mb-[6px]">{t('common.name').toUpperCase()}</Eyebrow>
<MCollCategoryPicker
variant="tile"
categories={categories}
value={draft.categoryId}
onChange={(id) => edit.set('categoryId', id)}
t={t}
>
<input value={draft.name} onChange={(e) => edit.set('name', e.target.value)} className={INPUT_CLS} />
</MCollCategoryPicker>
<Eyebrow className="mb-[6px] mt-[14px]">{t('places.formAddress').toUpperCase()}</Eyebrow>
<input
value={draft.address}
onChange={(e) => edit.set('address', e.target.value)}
placeholder={t('places.formAddressPlaceholder')}
className={INPUT_CLS}
/>
<Eyebrow className="mb-[6px] mt-[14px]">{t('collections.coordinates').toUpperCase()}</Eyebrow>
<div className="flex gap-2">
<NumericInput
mode="signed"
value={draft.lat}
onValueChange={(v) => edit.set('lat', v)}
placeholder={t('places.formLat')}
className={INPUT_CLS}
/>
<NumericInput
mode="signed"
value={draft.lng}
onValueChange={(v) => edit.set('lng', v)}
placeholder={t('places.formLng')}
className={INPUT_CLS}
/>
</div>
<Eyebrow className="mb-[6px] mt-[14px]">{t('collections.description').toUpperCase()}</Eyebrow>
<textarea
rows={5}
value={draft.description}
onChange={(e) => edit.set('description', e.target.value)}
placeholder={t('collections.descriptionPlaceholder')}
className={TEXTAREA_CLS}
/>
</div>
);
}
@@ -1,15 +1,95 @@
import type { PlacesLibraryEntry } from '@trek/shared';
import { ArrowRight } from 'lucide-react';
import { ArrowRight, Bookmark, History, Luggage } from 'lucide-react';
import { useState } from 'react';
import { historyLine, historyMeta } from '../../../components/Collections/placeExtrasText';
import { historyEditor, historyLine, historyWhen } from '../../../components/Collections/placeExtrasText';
import { usePlaceHistory } from '../../../components/Collections/usePlaceHistory';
import { Avatar } from '../../../components/Planner/TravelerPicker';
import type { TranslationFn } from '../../../types';
import { Eyebrow } from './MCollSheetKit';
import MPlaceCard from './MPlaceCard';
/** 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. */
/** The change history of a place on the phone (PLC-14); the logic is the desktop view's. */
export function MPlaceHistoryView({
state: h,
language,
folded = true,
t,
}: {
state: ReturnType<typeof usePlaceHistory>;
language: string;
/** In its own tab the whole history shows at once; folded, the newest few. */
folded?: boolean;
t: TranslationFn;
}) {
const [open, setOpen] = useState(!folded);
if (h.entries.length === 0) return null;
const shown = open ? h.entries : h.entries.slice(0, FOLDED);
return (
<MPlaceCard icon={<History size={14} />} title={t('placeHistory.title')} count={h.entries.length}>
<ol className="relative m-0 flex list-none flex-col gap-[14px] p-0 ps-1 before:absolute before:bottom-2 before:start-2 before:top-2 before:w-[1.5px] before:rounded before:bg-m-rowbr">
{shown.map((e, i) => {
const line = historyLine(e, t);
return (
<li key={e.id} className="relative flex flex-col gap-[6px] ps-[22px]">
<span
aria-hidden="true"
className={
i === 0
? 'absolute start-0 top-1 h-[10px] w-[10px] rounded-full border-2 border-m-act bg-m-act'
: 'absolute start-0 top-1 h-[10px] w-[10px] rounded-full border-2 border-m-faint bg-m-sheet'
}
/>
<div className="flex items-baseline gap-[10px] text-body text-m-ink">
<strong className="font-semibold">{line.field}</strong>
<time className="ms-auto whitespace-nowrap text-caption text-m-faint">{historyWhen(e, language)}</time>
</div>
{(line.from || line.to) && (
<div className="flex flex-wrap items-center gap-[6px]">
{line.from && (
<span className="rounded-lg border border-m-rowbr bg-m-inner px-[9px] py-1 text-caption text-m-faint line-through [overflow-wrap:anywhere]">
{line.from}
</span>
)}
{line.from && line.to && (
<ArrowRight size={12} className="flex-none text-m-faint rtl:-scale-x-100" aria-hidden="true" />
)}
{line.to && (
<span className="rounded-lg border border-m-rowbr bg-m-ic px-[9px] py-1 text-caption text-m-ink [overflow-wrap:anywhere]">
{line.to}
</span>
)}
</div>
)}
<div className="flex flex-wrap items-center gap-[6px] text-caption text-m-faint">
{e.editor && !e.automatic ? (
<Avatar userId={e.editor.id} username={e.editor.username} avatarUrl={e.editor.avatar_url} size={18} />
) : null}
<span>{historyEditor(e, t)}</span>
<span className="inline-flex items-center gap-1 rounded-full border border-m-rowbr bg-m-inner px-2 py-[2px]">
{e.origin.kind === 'trip' ? <Luggage size={11} /> : <Bookmark size={11} />}
{e.origin.kind === 'trip' ? e.origin.trip_title : e.origin.collection_name}
</span>
</div>
</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="self-start text-caption font-semibold text-m-muted"
>
{open ? t('placeHistory.more') : t('placeHistory.showAll')}
</button>
)}
</MPlaceCard>
);
}
export default function MPlaceHistorySection({
entry,
language,
@@ -20,43 +100,5 @@ export default function MPlaceHistorySection({
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>
)}
</>
);
return <MPlaceHistoryView state={h} language={language} t={t} />;
}
@@ -1,72 +1,155 @@
import type { PlacesLibraryEntry } from '@trek/shared';
import { ChevronRight, FileText } from 'lucide-react';
import { usePlaceMedia } from '../../../components/Collections/usePlaceMedia';
import { Bookmark, ChevronRight, FileText, Images, Layers, Loader2, Luggage, Plus, Upload } from 'lucide-react';
import { useMediaAdd } from '../../../components/Collections/mediaAdd';
import { usePlaceMedia, type MediaTarget } from '../../../components/Collections/usePlaceMedia';
import PhotoLightbox from '../../../components/Journey/PhotoLightbox';
import type { TranslationFn } from '../../../types';
import { Eyebrow } from './MCollSheetKit';
import MPlaceCard, { M_ICO, M_ROW } from './MPlaceCard';
import './libraryCover.css';
/** How many pictures the phone's row shows before it counts the rest on the last one. */
/** How many pictures the phone's grid 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;
type Media = ReturnType<typeof usePlaceMedia>;
/** Where an upload goes, asked when the place takes one in more than one trip or list. */
function MTargetChoice({ m, pick, t }: { m: Media; pick: (target: MediaTarget | 'all') => void; t: TranslationFn }) {
if (!m.choosing) return null;
const chip =
'inline-flex h-[30px] items-center gap-[5px] rounded-full border border-m-rowbr bg-m-ic px-3 text-caption font-semibold text-m-ink';
return (
<div className="flex flex-wrap items-center gap-[6px] rounded-[14px] border border-m-rowbr bg-m-inner py-[6px] pe-[6px] ps-3">
<span className="me-1 text-caption font-semibold text-m-faint">{t('placeMedia.where')}</span>
<button type="button" onClick={() => pick('all')} className={chip}>
<Layers size={12} /> {t('placeMedia.everywhere')}
</button>
{m.targets.map((x) => (
<button key={x.key} type="button" onClick={() => pick(x)} className={chip}>
{x.kind === 'trip' ? <Luggage size={12} /> : <Bookmark size={12} />}
{t(x.kind === 'trip' ? 'placeMedia.toTrip' : 'placeMedia.toList', { name: x.source })}
</button>
))}
</div>
);
}
/** The pictures and trip files of a place on the phone (PLC-19, PLC-20); the logic is the desktop view's. */
export function MPlaceMediaView({
state: m,
label,
t,
}: {
state: ReturnType<typeof usePlaceMedia>;
label: string;
t: TranslationFn;
}) {
const add = useMediaAdd(m);
const canAdd = m.targets.length > 0;
if (m.photos.length === 0 && m.files.length === 0 && !canAdd) return null;
const rest = m.photos.length - SHOWN;
const addAction = canAdd && (
<button
type="button"
onClick={add.start}
disabled={m.uploading}
aria-label={t('placeMedia.add')}
className="flex h-7 w-7 items-center justify-center rounded-full bg-m-ic text-m-ink disabled:opacity-50"
>
{m.uploading ? <Loader2 size={14} className="animate-spin" /> : <Plus size={14} />}
</button>
);
return (
<>
{add.field}
{m.photos.length === 0 && m.files.length === 0 && (
<MPlaceCard icon={<Images size={14} />} title={t('placeSheet.tab.media')}>
<button
type="button"
onClick={add.start}
disabled={m.uploading}
className="flex w-full flex-col items-center gap-1 rounded-[14px] border-[1.5px] border-dashed border-m-rowbr px-4 py-6 text-center text-caption text-m-muted"
>
{m.uploading ? <Loader2 size={18} className="animate-spin" /> : <Upload size={18} />}
<span className="text-body font-semibold text-m-ink">{t('placeMedia.addFirst')}</span>
<span>{t('placeMedia.hint')}</span>
</button>
<MTargetChoice m={m} pick={add.pick} t={t} />
</MPlaceCard>
)}
{m.photos.length > 0 && (
<>
<Eyebrow className="mb-[6px] mt-4">{t('places.media.photos').toUpperCase()}</Eyebrow>
<MPlaceCard
icon={<Images size={14} />}
title={t('places.media.photos')}
count={m.photos.length}
action={addAction}
>
<MTargetChoice m={m} pick={add.pick} t={t} />
<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}
{m.photos.slice(0, SHOWN).map((p, i) => {
const more = i === SHOWN - 1 && rest > 0;
return (
<div key={p.id} className="relative aspect-square overflow-hidden rounded-xl bg-m-ic">
<button
type="button"
onClick={() => m.setOpen(i)}
className="relative block h-full w-full"
aria-label={p.caption}
>
<img src={p.thumbSrc} alt="" loading="lazy" className="h-full w-full object-cover" />
{more && (
<>
<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>
{p.src === m.cover && (
<span className="m-photo-chip pointer-events-none absolute bottom-[5px] start-[5px]">
{t('placeMedia.isCover')}
</span>
</>
)}
</button>
))}
)}
{m.canCover(p) && !more && (
<button
type="button"
onClick={() => void m.setCover(p)}
disabled={m.uploading}
aria-label={t('placeMedia.setCover')}
className="m-photo-chip absolute end-[5px] top-[5px] flex h-7 w-7 items-center justify-center"
>
<ImageUp size={13} />
</button>
)}
</div>
);
})}
</div>
</>
</MPlaceCard>
)}
{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} />
<MPlaceCard
icon={<FileText size={14} />}
title={t('places.media.files')}
count={m.files.length}
action={m.photos.length === 0 ? addAction : undefined}
>
{m.photos.length === 0 && <MTargetChoice m={m} pick={add.pick} t={t} />}
{m.files.map((f) => (
<a key={f.file_id} href={f.url} target="_blank" rel="noreferrer" className={M_ROW}>
<span className={M_ICO}>
<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="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>
</>
<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>
))}
</MPlaceCard>
)}
{m.open !== null && (
<PhotoLightbox
@@ -80,9 +163,14 @@ export default function MPlaceMediaSection({ entry, t }: { entry: PlacesLibraryE
}))}
startIndex={m.open}
onClose={m.close}
label={entry.name}
label={label}
/>
)}
</>
);
}
export default function MPlaceMediaSection({ entry, t }: { entry: PlacesLibraryEntry; t: TranslationFn }) {
const m = usePlaceMedia(entry, t);
return <MPlaceMediaView state={m} label={entry.name} t={t} />;
}
@@ -0,0 +1,183 @@
import type { PlacesLibraryDetailResponse } from '@trek/shared';
import { Bookmark, ChevronRight, Hotel, Luggage, Ticket } from 'lucide-react';
import { createElement } from 'react';
import { tripLine } from '../../../components/Collections/libraryDates';
import type { ListPair, TripPair } from '../../../components/Collections/libraryPairs';
import { listIcon } from '../../../components/Collections/listIcons';
import { originName } from '../../../components/Collections/originName';
import type { TranslationFn } from '../../../types';
import { STATUS_SPEC, tint } from './collectionsMobileModel';
import MPlaceCard, { M_ICO } from './MPlaceCard';
const ROW = 'flex w-full flex-col gap-[9px] rounded-[14px] border border-m-inbr bg-m-inner p-[10px] text-start';
const CHIP =
'inline-flex items-center gap-1 rounded-full border border-m-rowbr bg-m-ic px-[9px] py-[3px] text-caption font-semibold text-m-muted';
type Entry = NonNullable<PlacesLibraryDetailResponse['entry']>;
/** A trip the place is in: its day or dates, whether it is only readable, and what the trip keeps. */
function TripCard({
pair,
entryName,
language,
onOpen,
t,
}: {
pair: TripPair;
entryName: string;
language: string;
onOpen: () => void;
t: TranslationFn;
}) {
const { origin, detail } = pair;
const line = tripLine(origin, detail, language, t);
const renamed = detail.info.name !== entryName;
return (
<button
type="button"
className={ROW}
onClick={onOpen}
aria-label={`${t('collections.library.openTrip')}: ${originName(origin)}`}
>
<span className="flex items-center gap-[10px]">
<span className={`${M_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">
{originName(origin)}
</span>
{line && <span className="block truncate text-caption text-m-muted">{line}</span>}
</span>
{origin.read_only && <span className={CHIP}>{t('collections.library.readOnly')}</span>}
<ChevronRight size={16} className="flex-none text-m-faint rtl:-scale-x-100" />
</span>
{(detail.has_accommodation || detail.has_reservation || renamed) && (
<span className="flex flex-wrap gap-[6px]">
{renamed && <span className={CHIP}>{t('collections.library.calledHere', { name: detail.info.name })}</span>}
{detail.has_accommodation && (
<span className={CHIP}>
<Hotel size={11} /> {t('collections.library.stay')}
</span>
)}
{detail.has_reservation && (
<span className={CHIP}>
<Ticket size={11} /> {t('collections.library.booking')}
</span>
)}
</span>
)}
</button>
);
}
/** A list the place is in, with its status there. */
function ListCard({
pair,
entryName,
onOpen,
t,
}: {
pair: ListPair;
entryName: string;
onOpen: () => void;
t: TranslationFn;
}) {
const { origin, detail } = pair;
const status = STATUS_SPEC[origin.status];
const renamed = detail.info.name !== entryName;
return (
<button
type="button"
className={ROW}
onClick={onOpen}
aria-label={`${t('collections.library.openList')}: ${originName(origin)}`}
>
<span className="flex items-center gap-[10px]">
<span
className={M_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)}
</span>
<span
className="inline-flex flex-none items-center gap-1 rounded-full px-[9px] py-[3px] text-caption font-bold"
style={{ background: tint(status.color, '1f'), color: status.color }}
>
{createElement(status.icon, { size: 11 })} {t(status.labelKey)}
</span>
<ChevronRight size={16} className="flex-none text-m-faint rtl:-scale-x-100" />
</span>
{renamed && (
<span className="flex flex-wrap gap-[6px]">
{renamed && <span className={CHIP}>{t('collections.library.calledHere', { name: detail.info.name })}</span>}
</span>
)}
</button>
);
}
/**
* Where the place is kept, in the overview of the one place view on the phone:
* its lists and its trips, each a card that opens the place there.
*/
export default function MPlaceOrigins({
entry,
trips,
lists,
language,
onOpenTrip,
onOpenList,
t,
}: {
entry: Entry;
trips: TripPair[];
lists: ListPair[];
language: string;
onOpenTrip: (tripId: number, placeId: number) => void;
onOpenList: (collectionId: number, collectionPlaceId: number) => void;
t: TranslationFn;
}) {
return (
<>
{lists.length > 0 && (
<MPlaceCard icon={<Bookmark size={14} />} title={t('collections.library.inLists')} count={lists.length}>
{lists.map((pair) => (
<ListCard
key={pair.origin.collection_place_id}
pair={pair}
entryName={entry.name}
onOpen={() => onOpenList(pair.origin.collection_id, pair.origin.collection_place_id)}
t={t}
/>
))}
</MPlaceCard>
)}
{trips.length > 0 && (
<MPlaceCard icon={<Luggage size={14} />} title={t('collections.library.inTrips')} count={trips.length}>
{trips.map((pair) => (
<TripCard
key={pair.origin.place_id}
pair={pair}
entryName={entry.name}
language={language}
onOpen={() => onOpenTrip(pair.origin.trip_id, pair.origin.place_id)}
t={t}
/>
))}
</MPlaceCard>
)}
</>
);
}
@@ -0,0 +1,98 @@
import { X } from 'lucide-react';
import { createElement, type ReactNode } from 'react';
import PlaceLocationBadge from '../../../components/Collections/PlaceLocationBadge';
import type { TranslationFn } from '../../../types';
import { entityGradient } from '../../../utils/gradients';
import MSheet from '../../components/MSheet';
import { categoryMeta, UNCATEGORIZED_META } from './collectionsMobileModel';
import './libraryCover.css';
/** A round control on the cover, beside close (change or remove the picture). */
export const COVER_BTN = 'm-libcover-btn flex h-8 w-8 items-center justify-center rounded-full';
/** An action in the sheet's bottom row. */
export const SHEET_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';
/**
* The frame of the one place view on the phone, the same from All places and from
* a list: the cover with the category, its controls and close, the name and where
* the place is; then the scrolling body; then the row of things to do with it.
*/
export default function MPlaceSheetShell({
open,
name,
category,
cover,
seed,
address,
lat,
lng,
controls,
head,
footer,
onClose,
t,
children,
}: {
open: boolean;
name: string | null;
category: { name: string; color?: string | null; icon?: string | null } | null | undefined;
cover: string | null;
/** Picks the gradient when there is no picture. */
seed: number;
address?: string | null;
lat?: number | null;
lng?: number | null;
/** More round buttons on the cover, before close. */
controls?: ReactNode;
/** Replaces the name and position on the cover (the edit form's name field). */
head?: ReactNode;
footer?: ReactNode;
onClose: () => void;
t: TranslationFn;
children: ReactNode;
}) {
const meta = categoryMeta(category) ?? UNCATEGORIZED_META;
return (
<MSheet open={open} onClose={onClose} ariaLabel={name ?? undefined}>
<div
className="relative h-[164px] flex-none overflow-hidden"
style={cover ? undefined : { backgroundImage: entityGradient(seed) }}
>
{cover && <img src={cover} alt="" className="absolute inset-0 h-full w-full object-cover" />}
<div className="m-libcover-scrim absolute inset-0" />
<div className="absolute inset-x-3 top-3 flex items-center gap-2">
{category && (
<span
className="inline-flex min-w-0 items-center gap-1 rounded-full bg-m-sheetop px-[10px] py-[3px] text-caption font-bold"
style={{ color: meta.color }}
>
{createElement(meta.icon, { size: 12, className: 'flex-none' })}{' '}
<span className="truncate">{category.name}</span>
</span>
)}
<div className="ms-auto flex flex-none gap-[6px]">
{controls}
<button type="button" onClick={onClose} aria-label={t('common.close')} className={COVER_BTN}>
<X size={16} />
</button>
</div>
</div>
<div className="absolute inset-x-4 bottom-3 min-w-0">
{head ??
(name && (
<>
<h2 dir="auto" className="m-libcover-name m-0 truncate text-title font-extrabold">
{name}
</h2>
<PlaceLocationBadge address={address} lat={lat} lng={lng} t={t} />
</>
))}
</div>
</div>
<div className="min-h-0 flex-1 overflow-y-auto px-4 pb-4">{children}</div>
{footer && <div className="flex flex-none gap-2 border-t border-m-rowbr px-4 py-3">{footer}</div>}
</MSheet>
);
}
@@ -0,0 +1,88 @@
import { createElement, useId, type ReactNode } from 'react';
import {
PLACE_TAB_EMPTY,
PLACE_TAB_ICON,
PLACE_TAB_LABEL,
PLACE_TABS,
type PlaceSheetState,
} from '../../../components/Collections/usePlaceSheet';
import type { TranslationFn } from '../../../types';
import { MOriginNotesView } from './MOriginNotesSection';
import { MPlaceActivitiesView } from './MPlaceActivitiesSection';
import { MPlaceHistoryView } from './MPlaceHistorySection';
import { MPlaceMediaView } from './MPlaceMediaSection';
import { MVisitsView } from './MVisitsSection';
/**
* The tabs of the one place view on the phone, the desktop's twin: a row of
* pills that stays at the top while the cards scroll, each counting what it holds.
*/
export default function MPlaceSheetTabs({
sheet,
overview,
language,
t,
}: {
sheet: PlaceSheetState;
overview: ReactNode;
language: string;
t: TranslationFn;
}) {
const id = useId();
const { tab } = sheet;
return (
<>
<div
role="tablist"
aria-label={t('placeSheet.tabs')}
className="sticky top-0 z-[2] -mx-4 flex gap-[6px] overflow-x-auto bg-m-sheetop px-4 py-[10px] [scrollbar-width:none]"
>
{PLACE_TABS.map((key) => {
const on = tab === key;
return (
<button
key={key}
id={`${id}-${key}`}
type="button"
role="tab"
aria-selected={on}
aria-controls={`${id}-panel`}
onClick={() => sheet.setTab(key)}
className={
on
? 'inline-flex flex-none items-center gap-[6px] rounded-full bg-m-act px-[13px] py-[7px] text-caption font-bold text-m-actfg'
: 'inline-flex flex-none items-center gap-[6px] rounded-full border border-m-rowbr bg-m-ic px-[13px] py-[7px] text-caption font-semibold text-m-muted'
}
>
{t(PLACE_TAB_LABEL[key])}
{sheet.counts[key] > 0 && <span className="opacity-70">{sheet.counts[key]}</span>}
</button>
);
})}
</div>
<div id={`${id}-panel`} role="tabpanel" aria-labelledby={`${id}-${tab}`} className="flex flex-col gap-3 pt-1">
{sheet.empty[tab] ? (
<div className="flex flex-col items-center gap-2 px-6 py-10 text-center text-body text-m-muted">
<span className="flex h-11 w-11 items-center justify-center rounded-[14px] border border-m-rowbr bg-m-ic">
{createElement(PLACE_TAB_ICON[tab], { size: 22 })}
</span>
{t(PLACE_TAB_EMPTY[tab])}
</div>
) : (
<>
{tab === 'overview' && (
<>
{overview}
<MVisitsView state={sheet.visits} language={language} t={t} />
</>
)}
{tab === 'notes' && <MOriginNotesView state={sheet.notes} t={t} />}
{tab === 'activities' && <MPlaceActivitiesView state={sheet.activities} language={language} t={t} />}
{tab === 'media' && sheet.entry && <MPlaceMediaView state={sheet.media} label={sheet.entry.name} t={t} />}
{tab === 'history' && <MPlaceHistoryView state={sheet.history} language={language} folded={false} t={t} />}
</>
)}
</div>
</>
);
}
@@ -0,0 +1,143 @@
import { Bookmark, Check, Luggage, Plus, Search, Tag, X } from 'lucide-react';
import type { PlaceTagsState, TagGroup } from '../../../components/Collections/usePlaceTags';
import type { TranslationFn } from '../../../types';
import MPlaceCard from './MPlaceCard';
function Dot({ color }: { color: string | null }) {
// 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)' }} />;
}
/** The open group's picker on the phone: search, tick, or make a new tag from the search. */
function MTagPicker({ tags, group, t }: { tags: PlaceTagsState; group: TagGroup; t: TranslationFn }) {
const assigned = new Set(group.assigned.map((x) => x.id));
const name = tags.query.trim();
const row = 'flex w-full items-center gap-[10px] rounded-[10px] px-2 py-[9px] text-start text-body text-m-ink';
return (
<div className="flex flex-col gap-[2px] rounded-[14px] border border-m-inbr bg-m-inner p-[6px]">
<form
className="mb-1 flex h-[38px] items-center gap-2 rounded-[10px] bg-m-ic px-3 text-m-faint"
onSubmit={(e) => {
e.preventDefault();
if (tags.canCreate) void tags.createAndAdd();
}}
>
<Search size={15} aria-hidden="true" />
<input
value={tags.query}
onChange={(e) => tags.setQuery(e.target.value)}
placeholder={t('placeTags.search')}
aria-label={t('placeTags.search')}
className="min-w-0 flex-1 border-0 bg-transparent text-body text-m-ink outline-none placeholder:text-m-faint"
/>
</form>
<div className="flex max-h-[240px] flex-col gap-[2px] overflow-y-auto">
{tags.matches.map((tag) => {
const on = assigned.has(tag.id);
return (
<button
key={tag.id}
type="button"
aria-pressed={on}
disabled={tags.busy}
onClick={() => void tags.toggle(group, tag.id)}
className={on ? `${row} font-semibold` : row}
>
<Dot color={tag.color} />
<span className="min-w-0 flex-1 truncate">{tag.name}</span>
{on && <Check size={15} className="flex-none" />}
</button>
);
})}
{tags.matches.length === 0 && !tags.canCreate && (
<p className="m-0 px-2 py-2 text-caption text-m-muted">{t('placeTags.none')}</p>
)}
</div>
{tags.canCreate && (
<>
{tags.matches.length > 0 && <div className="mx-1 my-1 h-px bg-m-rowbr" />}
<button type="button" onClick={() => void tags.createAndAdd()} disabled={tags.busy} className={row}>
<span className="flex h-[18px] w-[18px] flex-none items-center justify-center rounded-full bg-m-act text-m-actfg">
<Plus size={12} strokeWidth={2.6} />
</span>
<span className="min-w-0 flex-1 truncate text-m-muted">
{t('placeTags.createPrefix')} <strong className="font-bold text-m-ink">{name}</strong>
</span>
</button>
</>
)}
</div>
);
}
/**
* The tags of a place on the phone, the desktop card's twin: per list and trip the
* chips in their colours and a dashed "+ Tag" chip in the same row; the picker
* opens below the row. The source is named only when there is more than one.
*/
export default function MPlaceTagsCard({ tags, t }: { tags: PlaceTagsState; t: TranslationFn }) {
if (tags.groups.length === 0) return null;
const named = tags.groups.length > 1;
return (
<MPlaceCard icon={<Tag size={14} />} title={t('placeTags.title')} count={tags.total}>
{tags.groups.map((group, i) => {
const open = tags.openKey === group.key;
return (
<div
key={group.key}
className={i ? 'flex flex-col gap-2 border-t border-m-rowbr pt-[10px]' : 'flex flex-col gap-2'}
>
{named && (
<span className="inline-flex min-w-0 items-center gap-[6px] text-caption font-semibold text-m-faint">
{group.kind === 'trip' ? <Luggage size={12} /> : <Bookmark size={12} />}
<span className="truncate">{group.source}</span>
</span>
)}
<div className="flex flex-wrap items-center gap-[6px]">
{group.assigned.map((tag) => (
<span
key={tag.id}
className="inline-flex h-[30px] items-center gap-1.5 rounded-full border border-m-rowbr bg-m-ic pe-1 ps-[11px] text-caption font-semibold text-m-ink"
>
<Dot color={tag.color} />
{tag.name}
{group.canEdit ? (
<button
type="button"
onClick={() => void tags.toggle(group, tag.id)}
disabled={tags.busy}
aria-label={t('placeTags.removeFrom', { name: tag.name })}
className="flex h-[22px] w-[22px] items-center justify-center rounded-full text-m-faint"
>
<X size={12} strokeWidth={2.6} />
</button>
) : (
<span className="w-[6px]" />
)}
</span>
))}
{group.canEdit && (
<button
type="button"
onClick={() => tags.openPicker(open ? null : group.key)}
aria-expanded={open}
className={
open
? 'inline-flex h-[30px] items-center gap-[5px] rounded-full border border-m-act bg-m-ic px-[11px] text-caption font-semibold text-m-ink'
: 'inline-flex h-[30px] items-center gap-[5px] rounded-full border border-dashed border-m-rowbr px-[11px] text-caption font-semibold text-m-muted'
}
>
<Plus size={12} strokeWidth={2.6} /> {t('placeTags.add')}
</button>
)}
{!group.canEdit && group.assigned.length === 0 && (
<span className="text-caption text-m-muted">{t('placeTags.noneHere')}</span>
)}
</div>
{open && <MTagPicker tags={tags} group={group} t={t} />}
</div>
);
})}
</MPlaceCard>
);
}
@@ -1,10 +1,4 @@
import type {
CollectionPlace,
CollectionStatus,
PlacesLibraryEntry,
PlacesLibrarySort,
Tag as TagRow,
} from '@trek/shared';
import type { CollectionPlace, CollectionStatus, PlacesLibraryEntry, PlacesLibrarySort } from '@trek/shared';
import {
ArrowDownUp,
Bookmark,
@@ -19,6 +13,7 @@ import {
MapPin,
Search,
Shapes,
Star,
Tag,
} from 'lucide-react';
import { useMemo, useState } from 'react';
@@ -26,7 +21,7 @@ import CollectionMap from '../../../components/Collections/CollectionMap';
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 { ratingBadge } from '../../../components/Collections/ratingLabel';
import { usePlaceDuplicates } from '../../../components/Collections/usePlaceDuplicates';
import { usePlacesLibrary, type LibraryKindFilter } from '../../../components/Collections/usePlacesLibrary';
import VisitedMark from '../../../components/Collections/VisitedMark';
@@ -36,6 +31,7 @@ import { useSaveToCollectionStore } from '../../../store/saveToCollectionStore';
import type { Category, TranslationFn } from '../../../types';
import { placesPath } from '../../../utils/placesRoutes';
import { categoryMeta, STATUS_SPEC, tint, UNCATEGORIZED_META } from './collectionsMobileModel';
import './libraryCover.css';
import { CHIP_IDLE, CHIP_ON, DROP_PANEL, DropRow, EmptyNote, FILTER_CHIP } from './MCollFilterKit';
import MCollTripPickerSheet from './MCollTripPickerSheet';
import MDuplicatesSheet from './MDuplicatesSheet';
@@ -52,7 +48,17 @@ interface MPlacesLibraryProps {
t: TranslationFn;
}
type Drop = 'kind' | 'status' | 'category' | 'tags' | 'sort';
type Drop = 'kind' | 'status' | 'category' | 'tags' | 'rating' | 'sort';
/** The orders of All places and their names. */
const SORT_LABELS: Record<PlacesLibrarySort, string> = {
name: 'collections.sort.nameAsc',
updated: 'collections.library.sortUpdated',
rating: 'collections.library.sortRating',
};
/** The rating floors, as the desktop filter offers them. */
const RATING_FLOORS = ['all', 5, 4, 3, 2, 1] as const;
/** A map point per entry with a position; the map speaks CollectionPlace, keyed by a running id. */
function toMapPlaces(entries: PlacesLibraryEntry[]) {
@@ -92,10 +98,19 @@ function Row({ entry, onOpen, t }: { entry: PlacesLibraryEntry; onOpen: () => vo
className="mt-2 flex w-full items-center gap-[11px] rounded-2xl border border-m-rowbr bg-m-sheetop px-3 py-[11px] text-start"
>
<span
className="flex h-10 w-10 flex-none items-center justify-center rounded-xl"
className="relative flex h-10 w-10 flex-none items-center justify-center rounded-xl"
style={{ background: tint(meta.color, '1f'), color: meta.color }}
>
<Icon size={17} strokeWidth={2.2} />
{ratingBadge(entry.rating?.average) && (
<span
className="m-ratebadge"
role="img"
aria-label={t('collections.ratingBadge', { rating: ratingBadge(entry.rating?.average) })}
>
{ratingBadge(entry.rating?.average)}
</span>
)}
</span>
<span className="min-w-0 flex-1">
<span className="flex min-w-0 items-center gap-1">
@@ -140,7 +155,7 @@ function FilterDrop({
drop,
lib,
categories,
personalTags,
tagOptions,
kindLabel,
pick,
t,
@@ -148,7 +163,7 @@ function FilterDrop({
drop: Drop;
lib: Library;
categories: Category[];
personalTags: readonly TagRow[];
tagOptions: readonly { name: string; color: string | null }[];
kindLabel: (k: LibraryKindFilter) => string;
pick: (fn: () => void) => void;
t: TranslationFn;
@@ -221,9 +236,9 @@ function FilterDrop({
</>
)}
{drop === 'tags' &&
personalTags.map((tag) => (
tagOptions.map((tag) => (
<DropRow
key={tag.id}
key={tag.name}
icon={
// The tag's own colour, the one data-driven value of the row.
<span
@@ -231,17 +246,27 @@ function FilterDrop({
style={{ background: tag.color || 'var(--m-act)' }}
/>
}
label={String(tag.name)}
on={lib.tagIds.includes(tag.id)}
onPick={() => lib.toggleTag(tag.id)}
label={tag.name}
on={lib.tagNames.some((name) => name.toLowerCase() === tag.name.toLowerCase())}
onPick={() => lib.toggleTagName(tag.name)}
/>
))}
{drop === 'rating' &&
RATING_FLOORS.map((floor) => (
<DropRow
key={floor}
icon={<Star size={15} className="flex-none" />}
label={floor === 'all' ? t('collections.status.filterAll') : `${floor}+`}
on={lib.minRating === floor}
onPick={() => pick(() => lib.setMinRating(floor))}
/>
))}
{drop === 'sort' &&
(['name', 'updated'] as PlacesLibrarySort[]).map((s) => (
(Object.keys(SORT_LABELS) as PlacesLibrarySort[]).map((s) => (
<DropRow
key={s}
icon={<ArrowDownUp size={15} className="flex-none" />}
label={t(s === 'name' ? 'collections.sort.nameAsc' : 'collections.library.sortUpdated')}
label={t(SORT_LABELS[s])}
on={lib.sort === s}
onPick={() => pick(() => lib.setSort(s))}
/>
@@ -318,7 +343,6 @@ 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);
@@ -411,18 +435,28 @@ export default function MPlacesLibrary({ categories, language, dark, view, onVie
<ChevronDown size={12} strokeWidth={2} className="flex-none" />
</button>
)}
{personalTags.length > 0 && (
{lib.tagOptions.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`}
className={`${chip(lib.tagNames.length > 0)} !flex-none px-3`}
>
<Tag size={13} strokeWidth={2} className="flex-none" />
{lib.tagIds.length > 0 && <span>{lib.tagIds.length}</span>}
{lib.tagNames.length > 0 && <span>{lib.tagNames.length}</span>}
</button>
)}
<button
type="button"
onClick={() => setDrop((d) => (d === 'rating' ? null : 'rating'))}
aria-expanded={drop === 'rating'}
aria-label={t('places.filterByRating')}
className={`${chip(lib.minRating !== 'all')} !flex-none px-3`}
>
<Star size={13} strokeWidth={2} className="flex-none" />
{lib.minRating !== 'all' && <span>{lib.minRating}+</span>}
</button>
<button
type="button"
onClick={() => setDrop((d) => (d === 'sort' ? null : 'sort'))}
@@ -464,7 +498,7 @@ export default function MPlacesLibrary({ categories, language, dark, view, onVie
drop={drop}
lib={lib}
categories={categories}
personalTags={personalTags}
tagOptions={lib.tagOptions}
kindLabel={kindLabel}
pick={pick}
t={t}
@@ -477,6 +511,7 @@ export default function MPlacesLibrary({ categories, language, dark, view, onVie
<MLibraryPlaceSheet
open={lib.selectedKey != null}
categories={categories}
data={lib.detail}
loading={lib.detailLoading}
onNotesSaved={lib.reload}
@@ -5,15 +5,60 @@ 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';
import MPlaceCard, { M_ICO, M_ROW } from './MPlaceCard';
/**
* 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.
* When the reader was at a place on the phone (PLC-10): every past day of a trip
* it was planned on, as a card. Not there at all without a visit.
*/
export function MVisitsView({
state: v,
language,
t,
}: {
state: ReturnType<typeof usePlaceVisits>;
language: string;
t: TranslationFn;
}) {
const last = visitDate(v.lastVisit, null, language);
if (v.count === 0 || !last) return null;
return (
<MPlaceCard
icon={<CalendarCheck size={14} />}
title={t('visits.title')}
count={v.count}
action={
<span className="truncate text-caption text-m-muted">
{t('visits.summary', { count: v.count, date: last })}
</span>
}
>
{v.visits.map((visit) => (
<div key={`${visit.trip.id}:${visit.day_id}:${visit.place_id}`} className={M_ROW}>
<span className={M_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>
))}
</MPlaceCard>
);
}
export default function MVisitsSection({
entry,
language,
@@ -24,42 +69,7 @@ export default function MVisitsSection({
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>
</>
);
return <MVisitsView state={v} language={language} t={t} />;
}
/** A trip place's visits on the phone's place sheet: how often and when last; not shown before the first one. */
@@ -11,3 +11,36 @@
.m-libcover-name {
color: #fff;
}
/* The average vote on a place's tile in All places, as the lists show it on theirs. */
.m-ratebadge {
position: absolute;
bottom: -5px;
inset-inline-end: -6px;
min-width: 20px;
height: 20px;
padding: 0 4px;
border-radius: 10px;
display: grid;
place-items: center;
background: #f59e0b;
border: 1.5px solid var(--m-sheetop);
box-sizing: border-box;
font-size: 10px;
font-weight: 700;
line-height: 1;
color: #fff;
font-variant-numeric: tabular-nums;
text-shadow: 0 1px 1px rgb(0 0 0 / 0.45);
}
/* The controls on a photo tile in the phone's place view: on the picture, so in a dark glass. */
.m-photo-chip {
border-radius: 999px;
padding: 2px 7px;
font-size: 10.5px;
font-weight: 700;
color: #fff;
background: rgb(0 0 0 / 0.55);
backdrop-filter: blur(6px);
}