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;
@@ -119,7 +119,8 @@ export default function MCollAddSheet({ open, collectionId, collectionName, list
<MCollCategoryPicker categories={categories} value={categoryId} onChange={setCategoryId} t={t} />
<Eyebrow className="mb-[6px] mt-[14px]">{t('mobileCollections.status').toUpperCase()}</Eyebrow>
<div className="flex gap-[6px]">
{/* Two by two on a phone, so every status label keeps its room */}
<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
@@ -127,8 +127,8 @@ export default function MCollPlaceSheet({
</div>
)}
{/* Status cycle */}
<div className="mt-3 flex gap-[6px]">
{/* 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
@@ -1,6 +1,6 @@
import {
BedDouble, Bike, Bookmark, Camera, CheckCircle2, Circle, CircleSlash, Coffee,
Landmark, MapPin, ShoppingBag, TrainFront, Trees, Umbrella, Utensils,
Landmark, MapPin, RotateCcw, ShoppingBag, TrainFront, Trees, Umbrella, Utensils,
} from 'lucide-react'
import type { LucideIcon } from 'lucide-react'
import type { CollectionStatus } from '@trek/shared'
@@ -61,11 +61,12 @@ export interface MStatusMeta {
labelKey: string
}
/** Status canon: Idea → Want to go → Visited. */
/** Status canon: Idea → Want to go → Visited → Want to revisit. */
export const STATUS_SPEC: Record<CollectionStatus, MStatusMeta> = {
idea: { color: '#9A9AA1', icon: Circle, labelKey: 'collections.status.idea' }, // theme-lint-disable
want: { color: '#4A7DDB', icon: Bookmark, labelKey: 'collections.status.want' }, // theme-lint-disable
visited: { color: '#2FA37A', icon: CheckCircle2, labelKey: 'collections.status.visited' }, // theme-lint-disable
revisit: { color: 'var(--m-st-pending)', icon: RotateCcw, labelKey: 'collections.status.revisit' },
}
/** Hex + alpha-suffix tints the design uses for tiles/pills (e.g. #4A7DDB1f). */
@@ -241,11 +241,11 @@ describe('collectionsModel', () => {
cp({ id: 5, name: 'E', status: 'visited' }),
cp({ id: 6, name: 'F', status: 'visited' }),
];
expect(statusCounts(places)).toEqual({ all: 6, idea: 2, want: 1, visited: 3 });
expect(statusCounts(places)).toEqual({ all: 6, idea: 2, want: 1, visited: 3, revisit: 0 });
});
it('FE-COLLECTIONS-MODEL-015: empty input yields all zeros', () => {
expect(statusCounts([])).toEqual({ all: 0, idea: 0, want: 0, visited: 0 });
expect(statusCounts([])).toEqual({ all: 0, idea: 0, want: 0, visited: 0, revisit: 0 });
});
it('FE-COLLECTIONS-MODEL-016: undefined entries are skipped from every count', () => {
@@ -255,7 +255,12 @@ describe('collectionsModel', () => {
cp({ id: 2, name: 'B', status: 'want' }),
];
expect(() => statusCounts(places)).not.toThrow();
expect(statusCounts(places)).toEqual({ all: 2, idea: 1, want: 1, visited: 0 });
expect(statusCounts(places)).toEqual({ all: 2, idea: 1, want: 1, visited: 0, revisit: 0 });
});
it('FE-COLLECTIONS-MODEL-046: a place to revisit counts under its own status (#2567)', () => {
const places = [cp({ id: 1, name: 'A', status: 'revisit' }), cp({ id: 2, name: 'B', status: 'visited' })];
expect(statusCounts(places)).toEqual({ all: 2, idea: 0, want: 0, visited: 1, revisit: 1 });
});
});
@@ -352,14 +357,15 @@ describe('collectionsModel', () => {
// ── status metadata + cycle ─────────────────────────────────────────────────
describe('status metadata', () => {
it('FE-COLLECTIONS-MODEL-040: nextStatus cycles idea → want → visited → idea', () => {
it('FE-COLLECTIONS-MODEL-040: nextStatus cycles idea → want → visited → revisit → idea', () => {
expect(nextStatus('idea')).toBe('want');
expect(nextStatus('want')).toBe('visited');
expect(nextStatus('visited')).toBe('idea');
expect(nextStatus('visited')).toBe('revisit');
expect(nextStatus('revisit')).toBe('idea');
});
it('FE-COLLECTIONS-MODEL-041: STATUS_ORDER holds every status exactly once', () => {
expect(STATUS_ORDER).toEqual(['idea', 'want', 'visited']);
expect(STATUS_ORDER).toEqual(['idea', 'want', 'visited', 'revisit']);
});
it('FE-COLLECTIONS-MODEL-042: every status has a label key, an icon and both colours', () => {
@@ -50,7 +50,7 @@ export function filterPlaces(
/** Count places per status for the filter chips. */
export function statusCounts(places: CollectionPlace[]): Record<StatusFilter, number> {
const counts: Record<StatusFilter, number> = { all: 0, idea: 0, want: 0, visited: 0 }
const counts: Record<StatusFilter, number> = { all: 0, idea: 0, want: 0, visited: 0, revisit: 0 }
for (const p of places) { if (!p) continue; counts.all += 1; counts[p.status] += 1 }
return counts
}
+3 -1
View File
@@ -546,7 +546,7 @@
the link chips below — it is an action on the place, not a piece of it. */
/* status segmented control */
.trek-dash .col-detail-seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-2); }
.trek-dash .col-detail-seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-2); }
.trek-dash .col-detail-seg button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 6px; border-radius: 9px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); transition: background .12s, color .12s, box-shadow .12s; }
.trek-dash .col-detail-seg button:hover { color: var(--ink); }
.trek-dash .col-detail-seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--sh-xs); }
@@ -595,6 +595,8 @@
@media (max-width: 720px) {
.trek-dash .col-detail { inset-inline: 0; bottom: 0; transform: none; width: 100%; max-height: 84dvh; border-radius: var(--r-xl) var(--r-xl) 0 0; }
/* four statuses side by side leave a label no room at this width: two by two */
.trek-dash .col-detail-seg { grid-template-columns: repeat(2, 1fr); }
/* the read-mode footer (Edit · Copy · Remove) would otherwise clip its last
button — let it wrap, drop the growing spacer, and clear the home indicator */
.trek-dash .col-detail-footer { flex-wrap: wrap; padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }