Files
TREK/client/src/components/Collections/PlaceActivitiesSection.tsx
T
Maurice d758f4c592 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.
2026-11-29 23:36:43 +00:00

142 lines
5.2 KiB
TypeScript

import type { PlaceActivity, PlacesLibraryEntry } from '@trek/shared';
import { Link2, Plus, Route, Ticket, X } from 'lucide-react';
import React from 'react';
import { useNavigate } from 'react-router';
import type { TranslationFn } from '../../types';
import { Tooltip } from '../shared/Tooltip';
import PlaceCard from './PlaceCard';
import { activityLine } from './placeExtrasText';
import { activityHref, usePlaceActivities } from './usePlaceActivities';
const ICON_BTN =
'grid h-7 w-7 flex-none place-items-center rounded-lg text-content-muted hover:bg-surface-secondary hover:text-content disabled:opacity-50';
function ActivityIcon({ type }: { type: PlaceActivity['type'] }) {
return type === 'booking' ? <Ticket size={16} /> : <Route size={16} />;
}
/**
* The tours and bookings of a place of All places in the desktop sheet (PLC-18):
* each one opens where it lives, a said link can be taken off again, and "+ Link"
* offers the bookings and tours of the trips and lists the reader may link in.
* Not there at all while there is nothing linked and nothing to link.
*/
export function PlaceActivitiesView({
state: a,
language,
t,
}: {
state: ReturnType<typeof usePlaceActivities>;
language: string;
t: TranslationFn;
}): React.ReactElement | null {
const navigate = useNavigate();
if (a.activities.length === 0 && !a.canLink) return null;
return (
<PlaceCard
icon={Ticket}
title={t('placeActivities.title')}
count={a.activities.length}
action={
a.canLink &&
!a.picking && (
<button type="button" onClick={() => void a.openPicker()} disabled={a.busy} className="col-detail-action">
<Plus size={13} /> {t('placeActivities.link')}
</button>
)
}
rows={a.activities.length > 0}
>
{a.activities.map((act) => (
<div key={`${act.key}:${act.source.kind}`} className="col-origin">
<span className="col-origin-head">
<span className="col-origin-ico">
<ActivityIcon type={act.type} />
</span>
<button
type="button"
onClick={() => void navigate(activityHref(act))}
className="col-origin-title text-start"
>
<span className="nm">{act.title}</span>
<span className="sub">{activityLine(act, language, t)}</span>
</button>
{act.can_unlink ? (
<Tooltip label={t('placeActivities.unlink')}>
<button
type="button"
onClick={() => void a.unlink(act)}
disabled={a.busy}
aria-label={t('placeActivities.unlink')}
className={ICON_BTN}
>
<X size={15} />
</button>
</Tooltip>
) : (
<span className="col-origin-tag">{t('placeActivities.atThisPlace')}</span>
)}
</span>
</div>
))}
{a.activities.length === 0 && !a.picking && (
<button
type="button"
onClick={() => void a.openPicker()}
disabled={!a.canLink || a.busy}
className="place-composer"
>
<Link2 size={15} />
{t('placeActivities.none')}
</button>
)}
{a.picking && (
<div className="col-origin cursor-default">
<span className="place-pick-head">
<Link2 size={13} /> <span className="flex-1">{t('placeActivities.pickTitle')}</span>
<button type="button" onClick={a.closePicker} aria-label={t('common.close')} className={ICON_BTN}>
<X size={14} />
</button>
</span>
{a.picking.every((g) => g.candidates.length === 0) && (
<span className="col-origin-sub">{t('placeActivities.nothingToLink')}</span>
)}
{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 items-center gap-2.5 rounded-lg px-1 py-1.5 text-start hover:bg-surface-secondary disabled:opacity-50"
>
<span className="grid h-7 w-7 flex-none place-items-center rounded-lg bg-surface-secondary text-content-muted">
<ActivityIcon type={c.type} />
</span>
<span className="min-w-0 flex-1">
<span className="block truncate text-body font-semibold text-content">{c.title}</span>
<span className="block truncate text-caption text-content-faint">{activityLine(c, language, t)}</span>
</span>
<Plus size={15} className="flex-none text-content-muted" />
</button>
))
)}
</div>
)}
</PlaceCard>
);
}
export default function PlaceActivitiesSection({
entry,
language,
t,
}: {
entry: PlacesLibraryEntry;
language: string;
t: TranslationFn;
}): React.ReactElement | null {
const a = usePlaceActivities({ entry, t });
return <PlaceActivitiesView state={a} language={language} t={t} />;
}