feat(collections): "want to revisit" status for saved places (#2567)

A fourth status after visited, for a place already seen that the user wants
to go back to. It joins the one-tap cycle, the filters, the pickers, the
assistant cards and the MCP status tool, and counts as visited wherever
visits are counted (isVisitedCollectionStatus), so "visited everywhere"
keeps it. The status pickers go two by two where four would not fit.
This commit is contained in:
Maurice
2026-11-13 09:28:17 +01:00
parent 73ac4b29ad
commit 72e8b1f8d9
56 changed files with 178 additions and 51 deletions
@@ -1,5 +1,5 @@
/**
* FE-AI-COLL-010 to FE-AI-COLL-017
* FE-AI-COLL-010 to FE-AI-COLL-017, FE-AI-COLL-040
*
* The answer cards of the collections as the chat draws them: a list's head
* with its size, people and places per status, its saved places as rows
@@ -57,6 +57,14 @@ describe('collection answer cards', () => {
expect(view.onOpen).toHaveBeenCalledWith({ kind: 'page', path: '/collections/12' });
});
it('FE-AI-COLL-040: the places to revisit have a pill of their own in the head, in the visited tone (#2567)', () => {
draw([placesCard({ list: { ...placesCard().list, counts: { idea: 3, want: 5, visited: 4, revisit: 7 } } })]);
const card = screen.getByRole('region', { name: 'Saved places in Paris food' });
const pill = within(card).getByText('Want to revisit').parentElement as HTMLElement;
expect(within(pill).getByText('7')).toBeInTheDocument();
expect(within(card).getByText('Visited').parentElement?.className).toBe(pill.className);
});
it('FE-AI-COLL-011: a saved place shows its status, two labels and the rest counted, its rating and the trip having it', () => {
draw([placesCard({ places: [savedPlace({ inTripPlaceId: 6 })] })]);
expect(screen.getByText('Septime')).toBeInTheDocument();
@@ -1,10 +1,11 @@
import type {
CollectionCardDelta,
CollectionCardLabel,
CollectionCardList,
CollectionCardPlace,
CollectionListsCard,
CollectionPlacesCard,
import {
type CollectionCardDelta,
type CollectionCardLabel,
type CollectionCardList,
type CollectionCardPlace,
type CollectionListsCard,
type CollectionPlacesCard,
isVisitedCollectionStatus,
} from '@trek/shared';
import { Bookmark, Info, Tag } from 'lucide-react';
import type { ReactNode } from 'react';
@@ -110,7 +111,7 @@ function ListChip({ list }: { list: CollectionCardList }) {
function statusChange(status: NonNullable<CollectionCardDelta['status']>, t: T): ReactNode {
const to = STATUS_META[status.to];
const before = status.from ? t(STATUS_META[status.from].labelKey) : null;
const tone = status.to === 'visited' ? 'success' : 'neutral';
const tone = isVisitedCollectionStatus(status.to) ? 'success' : 'neutral';
return <FactChange key="status" icon={to.icon} before={before} after={t(to.labelKey)} tone={tone} />;
}
@@ -1,10 +1,16 @@
import type { CollectionCardLabel, CollectionCardList, CollectionCardPlace, CollectionStatus } from '@trek/shared';
import {
type CollectionCardLabel,
type CollectionCardList,
type CollectionCardPlace,
type CollectionStatus,
isVisitedCollectionStatus,
} from '@trek/shared';
import { Star } from 'lucide-react';
import type { CSSProperties } from 'react';
import { useTranslation } from '../../../../i18n';
import { safeHexColor } from '../../../../utils/safeColor';
import { STATUS_META } from '../../../Collections/collectionStatus';
import { STATUS_META, STATUS_ORDER } from '../../../Collections/collectionStatus';
import { SoftPill, tintOf, WhiteBadge } from '../../../Planner/planParts';
import PlaceAvatar from '../../../shared/PlaceAvatar';
import { Tooltip } from '../../../shared/Tooltip';
@@ -93,7 +99,7 @@ export function StatusPill({ status, count }: { status: CollectionStatus; count?
<Icon size={10} strokeWidth={2.4} aria-hidden="true" className="flex-none" style={{ color: meta.color }} />
);
return (
<SoftPill tone={status === 'visited' ? 'success' : 'neutral'} icon={icon}>
<SoftPill tone={isVisitedCollectionStatus(status) ? 'success' : 'neutral'} icon={icon}>
{count !== undefined && <span className="tabular-nums">{count}</span>}
<span>{t(meta.labelKey)}</span>
</SoftPill>
@@ -140,7 +146,7 @@ export function ListHead({ list, first = true }: { list: CollectionCardList; fir
</div>
{counts && (
<CardFacts>
{(['idea', 'want', 'visited'] as const).map((status) => (
{STATUS_ORDER.map((status) => (
<StatusPill key={status} status={status} count={counts[status]} />
))}
</CardFacts>
@@ -1,4 +1,4 @@
// FE-COMP-STATUSBADGE-001 to FE-COMP-STATUSBADGE-013
// FE-COMP-STATUSBADGE-001 to FE-COMP-STATUSBADGE-014
import { render, screen } from '../../../tests/helpers/render';
import userEvent from '@testing-library/user-event';
import type { CollectionStatus } from '@trek/shared';
@@ -49,7 +49,7 @@ describe('StatusBadge', () => {
expect(screen.queryByText('Idea')).not.toBeInTheDocument();
});
// ── One-tap cycle: idea → want → visited → idea ──────────────────────────────
// ── One-tap cycle: idea → want → visited → revisit → idea ────────────────────
it('FE-COMP-STATUSBADGE-005: exposes a button role when onChange is supplied', () => {
render(<Badge status="idea" onChange={vi.fn()} />);
@@ -73,11 +73,19 @@ describe('StatusBadge', () => {
expect(onChange).toHaveBeenCalledWith('visited');
});
it('FE-COMP-STATUSBADGE-008: clicking a visited badge wraps around to "idea"', async () => {
it('FE-COMP-STATUSBADGE-008: clicking a visited badge moves on to "revisit"', async () => {
const user = userEvent.setup();
const onChange = vi.fn();
render(<Badge status="visited" onChange={onChange} />);
await user.click(screen.getByRole('button', { name: 'Visited' }));
expect(onChange).toHaveBeenCalledWith('revisit');
});
it('FE-COMP-STATUSBADGE-014: clicking a revisit badge wraps around to "idea" (#2567)', async () => {
const user = userEvent.setup();
const onChange = vi.fn();
render(<Badge status="revisit" onChange={onChange} />);
await user.click(screen.getByRole('button', { name: 'Want to revisit' }));
expect(onChange).toHaveBeenCalledWith('idea');
});
@@ -5,7 +5,7 @@ import { STATUS_META, nextStatus } from './collectionStatus'
interface StatusBadgeProps {
status: CollectionStatus
/** One-tap cycle: idea → want → visited → idea. Omit for a read-only badge. */
/** One-tap cycle: idea → want → visited → revisit → idea. Omit for a read-only badge. */
onChange?: (next: CollectionStatus) => void
showLabel?: boolean
size?: number
@@ -15,7 +15,7 @@ interface StatusBadgeProps {
}
/**
* Coloured per-place status pill (idea / want-to-go / visited). When `onChange`
* Coloured per-place status pill (idea / want-to-go / visited / revisit). When `onChange`
* is supplied a single tap cycles the status optimistically; otherwise it is a
* static badge. Two skins: the default surface pill (list / inspector) and the
* `onCover` dark-glass pill that stays legible on top of a photo cover. Styled
@@ -1,5 +1,5 @@
import { COLLECTION_STATUSES, type CollectionStatus } from '@trek/shared';
import { Bookmark, CheckCircle2, Circle, type LucideIcon } from 'lucide-react';
import { Bookmark, CheckCircle2, Circle, RotateCcw, type LucideIcon } from 'lucide-react';
/**
* How a saved place's status looks wherever it shows: its icon, its name and
@@ -26,12 +26,13 @@ export const STATUS_META: Record<CollectionStatus, StatusMeta> = {
color: 'var(--success)',
coverColor: '#6ee7b7',
},
revisit: { icon: RotateCcw, labelKey: 'collections.status.revisit', color: 'var(--warning)', coverColor: '#fcd34d' },
};
/** Stable order for the filter chips + the one-tap cycle. */
export const STATUS_ORDER: CollectionStatus[] = [...COLLECTION_STATUSES];
/** idea → want → visited → idea */
/** idea → want → visited → revisit → idea */
export function nextStatus(status: CollectionStatus): CollectionStatus {
const i = STATUS_ORDER.indexOf(status);
return STATUS_ORDER[(i + 1) % STATUS_ORDER.length];
@@ -108,17 +108,19 @@ describe('useSaveToCollection', () => {
expect(result.current.unvisited).toEqual([]);
});
it('FE-COMP-SAVETOCOLHOOK-004: unvisited leaves out visited and read-only lists', async () => {
it('FE-COMP-SAVETOCOLHOOK-004: unvisited leaves out visited, to-revisit and read-only lists', async () => {
vi.spyOn(collectionsApi, 'membership').mockResolvedValue({
saved: true,
lists: [
{ collection_id: 1, name: 'Favorites', place_id: 900, status: 'visited', can_edit: true },
{ collection_id: 2, name: 'Wishlist', place_id: 901, status: 'idea', can_edit: false },
{ collection_id: 3, name: 'Team', place_id: 902, status: 'want', can_edit: true },
// #2567: a place to revisit was visited already, "visited everywhere" keeps the wish.
{ collection_id: 4, name: 'Again', place_id: 903, status: 'revisit', can_edit: true },
],
});
const { result } = await loaded();
await waitFor(() => expect(result.current.savedByCollection.size).toBe(3));
await waitFor(() => expect(result.current.savedByCollection.size).toBe(4));
expect(result.current.unvisited.map((l) => l.place_id)).toEqual([902]);
});
@@ -1,4 +1,9 @@
import type { Collection, CollectionMembership, CollectionStatus } from '@trek/shared';
import {
type Collection,
type CollectionMembership,
type CollectionStatus,
isVisitedCollectionStatus,
} from '@trek/shared';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { useNavigate } from 'react-router';
@@ -110,8 +115,8 @@ export function useSaveToCollection() {
const savedByCollection = new Map<number, MembershipEntry>();
for (const l of membership?.lists ?? []) savedByCollection.set(l.collection_id, l);
/** Lists holding this place that the viewer may edit and that are not visited yet. */
const unvisited = (membership?.lists ?? []).filter((l) => l.can_edit && l.status !== 'visited');
/** Lists holding this place that the viewer may edit and that are not visited yet; one to revisit already was. */
const unvisited = (membership?.lists ?? []).filter((l) => l.can_edit && !isVisitedCollectionStatus(l.status));
const handleStatus = async (entry: MembershipEntry, next: CollectionStatus) => {
if (busyId != null) return;