mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-25 22:27:32 +00:00
feat(assistant): collection list and saved place cards
This commit is contained in:
@@ -0,0 +1,147 @@
|
||||
/**
|
||||
* FE-AI-COLL-010 to FE-AI-COLL-017
|
||||
*
|
||||
* 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
|
||||
* (status, labels, rating, the trip having them), the rest as a way to the
|
||||
* list, the map pin a row lights and where a click takes it, the phone
|
||||
* without hover, and the lists card with invites and where a place is saved.
|
||||
*/
|
||||
import type { AssistantMessage, TrekCard } from '@trek/shared';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { listRow, listsCard, placesCard, savedPlace } from '../../../../../tests/helpers/collectionCards';
|
||||
import { fireEvent, render, screen, within } from '../../../../../tests/helpers/render';
|
||||
import { useAssistantStore } from '../../../../store/assistantStore';
|
||||
import type { CardsBlock } from '../../assistantParts';
|
||||
import { type AssistantView, AssistantViewContext } from '../../assistantViewContext';
|
||||
import AssistantCardBlock from '../AssistantCardBlock';
|
||||
|
||||
const INITIAL = useAssistantStore.getState();
|
||||
|
||||
afterEach(() => {
|
||||
useAssistantStore.setState(INITIAL, true);
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
const spots = (count: number) =>
|
||||
Array.from({ length: count }, (_, i) => savedPlace({ id: 100 + i, name: `Spot ${i}`, labelIds: [] }));
|
||||
|
||||
function draw(cards: TrekCard[], view: Partial<AssistantView> = {}) {
|
||||
const value: AssistantView = { tripId: 4, variant: 'window', density: 'compact', onOpen: vi.fn(), ...view };
|
||||
const block: CardsBlock = {
|
||||
kind: 'cards',
|
||||
key: 'cards-1',
|
||||
group: cards[0]?.kind ?? 'none',
|
||||
entries: cards.map((card, index) => ({ toolCallId: `call_${index}`, card })),
|
||||
};
|
||||
const message = { id: 'msg-1', role: 'assistant', parts: [] } as unknown as AssistantMessage;
|
||||
render(
|
||||
<AssistantViewContext.Provider value={value}>
|
||||
<AssistantCardBlock block={block} message={message} />
|
||||
</AssistantViewContext.Provider>
|
||||
);
|
||||
return value;
|
||||
}
|
||||
|
||||
describe('collection answer cards', () => {
|
||||
it('FE-AI-COLL-010: a list heads its card with its size, its people, its places per status and the way to it', () => {
|
||||
const view = draw([placesCard()]);
|
||||
const card = screen.getByRole('region', { name: 'Saved places in Paris food' });
|
||||
expect(within(card).getByText('Paris food')).toBeInTheDocument();
|
||||
expect(within(card).getByText('12 places')).toBeInTheDocument();
|
||||
expect(within(card).getByText('1 member')).toBeInTheDocument();
|
||||
expect(within(card).getByText('Idea')).toBeInTheDocument();
|
||||
expect(within(card).getByText('3')).toBeInTheDocument();
|
||||
fireEvent.click(within(card).getByRole('button', { name: /Open list/ }));
|
||||
expect(view.onOpen).toHaveBeenCalledWith({ kind: 'page', path: '/collections/12' });
|
||||
});
|
||||
|
||||
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();
|
||||
expect(screen.getByText('80 Rue de Charonne')).toBeInTheDocument();
|
||||
expect(screen.getAllByText('Want to go').length).toBeGreaterThan(0);
|
||||
expect(screen.getByText('Dinner')).toBeInTheDocument();
|
||||
expect(screen.getByText('Late')).toBeInTheDocument();
|
||||
expect(screen.queryByText('Terrace')).toBeNull();
|
||||
expect(screen.getByText('+1')).toBeInTheDocument();
|
||||
expect(screen.getByText('4.5')).toBeInTheDocument();
|
||||
expect(screen.getByText('Already in your trip')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-AI-COLL-012: a narrow chat shows five rows and counts the rest as a way to the list; a roomy one eight', () => {
|
||||
const view = draw([placesCard({ places: spots(8), more: 4 })]);
|
||||
expect(screen.getByText('Spot 4')).toBeInTheDocument();
|
||||
expect(screen.queryByText('Spot 5')).toBeNull();
|
||||
fireEvent.click(screen.getByRole('button', { name: '7 more in this list' }));
|
||||
expect(view.onOpen).toHaveBeenCalledWith({ kind: 'page', path: '/collections/12' });
|
||||
});
|
||||
|
||||
it('FE-AI-COLL-013: a roomy chat shows eight rows', () => {
|
||||
draw([placesCard({ places: spots(8) })], { density: 'roomy' });
|
||||
expect(screen.getByText('Spot 7')).toBeInTheDocument();
|
||||
expect(screen.queryByText(/more in this list/)).toBeNull();
|
||||
});
|
||||
|
||||
it('FE-AI-COLL-014: resting on a row pins it on the map; a click selects the trip place or moves the map to the saved one', () => {
|
||||
const requestCamera = vi.fn();
|
||||
useAssistantStore.setState({ requestCamera });
|
||||
const onRevealMap = vi.fn();
|
||||
const inTrip = savedPlace({ id: 34, name: 'Septime', inTripPlaceId: 6, labelIds: [] });
|
||||
const elsewhere = savedPlace({ id: 35, name: 'Le Comptoir', lat: 48.85, lng: 2.33, labelIds: [] });
|
||||
const view = draw([placesCard({ places: [inTrip, elsewhere] })], { onRevealMap });
|
||||
const row = screen.getByRole('button', { name: /Septime/ });
|
||||
fireEvent.mouseEnter(row);
|
||||
expect(useAssistantStore.getState().preview).toMatchObject({ ref: 'col:34', placeId: 6, lat: 48.853 });
|
||||
fireEvent.mouseLeave(row);
|
||||
expect(useAssistantStore.getState().preview).toBeNull();
|
||||
fireEvent.click(row);
|
||||
expect(view.onOpen).toHaveBeenCalledWith({ kind: 'map', placeId: 6, dayId: null });
|
||||
fireEvent.click(screen.getByRole('button', { name: /Le Comptoir/ }));
|
||||
expect(onRevealMap).toHaveBeenCalled();
|
||||
expect(requestCamera).toHaveBeenCalledWith(4, [[48.85, 2.33]], 'pan', 'user');
|
||||
});
|
||||
|
||||
it('FE-AI-COLL-015: on the phone a row does not pin on hover, and a place without a position is no button', () => {
|
||||
draw([placesCard({ places: [savedPlace({ lat: null, lng: null, labelIds: [] })] })], { variant: 'fullscreen' });
|
||||
expect(screen.queryByRole('button', { name: /Septime/ })).toBeNull();
|
||||
fireEvent.mouseEnter(screen.getByText('Septime'));
|
||||
expect(useAssistantStore.getState().preview).toBeNull();
|
||||
});
|
||||
|
||||
it('FE-AI-COLL-016: two lists read in one answer share one card, each under its head; one read twice shows once', () => {
|
||||
const list = { id: 13, name: 'Rome', color: null, placeCount: 2, memberCount: 0, counts: null };
|
||||
const rome = placesCard({ list });
|
||||
const again = placesCard({ places: [savedPlace({ name: 'Septime again', labelIds: [] })] });
|
||||
draw([placesCard(), rome, again]);
|
||||
const card = screen.getByRole('region', { name: 'Saved places' });
|
||||
expect(within(card).getByText('Paris food')).toBeInTheDocument();
|
||||
expect(within(card).getByText('Rome')).toBeInTheDocument();
|
||||
expect(within(card).getByText('Septime again')).toBeInTheDocument();
|
||||
expect(within(card).getAllByText('Paris food')).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('FE-AI-COLL-017: the lists card names each list with its size, an invite with who sent it, and where a place is saved', () => {
|
||||
const person = { id: 4, name: 'Maya', avatarKey: null };
|
||||
const view = draw([
|
||||
listsCard({ lists: [listRow(), listRow({ id: 40, name: 'Rome', invite: true, person })] }),
|
||||
listsCard({ lists: [listRow({ name: 'Paris eats' })] }),
|
||||
]);
|
||||
expect(screen.getByText('Your lists')).toBeInTheDocument();
|
||||
expect(screen.getByText('Paris eats')).toBeInTheDocument();
|
||||
expect(screen.queryByText('Paris food')).toBeNull();
|
||||
expect(screen.getByText('Invite from Maya')).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole('button', { name: /Rome/ }));
|
||||
expect(view.onOpen).toHaveBeenCalledWith({ kind: 'page', path: '/collections/40' });
|
||||
});
|
||||
|
||||
it('FE-AI-COLL-018: where a place is saved reads as its lists with its status in each', () => {
|
||||
const lists = [listRow({ status: 'visited' }), listRow({ id: 13, name: 'Later', status: 'idea' })];
|
||||
draw([listsCard({ place: 'Septime', lists })]);
|
||||
expect(screen.getByText('Septime')).toBeInTheDocument();
|
||||
expect(screen.getByText('Saved in 2 lists')).toBeInTheDocument();
|
||||
expect(screen.getByText('Visited')).toBeInTheDocument();
|
||||
expect(screen.getByText('Idea')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,117 @@
|
||||
import type { CollectionListsCard, CollectionPlacesCard } from '@trek/shared';
|
||||
import { Bookmark } from 'lucide-react';
|
||||
|
||||
import { useTranslation } from '../../../../i18n';
|
||||
import { SoftPill, WhiteBadge } from '../../../Planner/planParts';
|
||||
import { useAssistantView } from '../../assistantViewContext';
|
||||
import type { CardEntry } from '../cardTypes';
|
||||
import { CardFacts } from '../parts/CardFacts';
|
||||
import CardFrame from '../parts/CardFrame';
|
||||
import CardHeader from '../parts/CardHeader';
|
||||
import { CardMore, CardRow, CardRows } from '../parts/CardRows';
|
||||
import { labelsById, listTarget, mergeListRows, mergePlacesCards, rowsShown } from './collectionCardModel';
|
||||
import { ListHead, ListLead, SavedPlaceRow, StatusPill } from './collectionCardParts';
|
||||
|
||||
/**
|
||||
* The answer cards of the collections: saved places under their list's head
|
||||
* (two lists read in one answer sit in one card, one head each), and the
|
||||
* user's lists with the invites waiting or the lists a place is saved in.
|
||||
* Window and phone draw the same; the phone has taller rows and no hover.
|
||||
*/
|
||||
|
||||
function PlacesSection({ card, first }: { card: CollectionPlacesCard; first: boolean }) {
|
||||
const { density } = useAssistantView();
|
||||
const shown = card.places.slice(0, rowsShown(density));
|
||||
const labels = labelsById(card.labels);
|
||||
const more = card.more + card.places.length - shown.length;
|
||||
return (
|
||||
<div className={first ? '' : 'mt-2 border-t border-edge-faint pt-2.5'}>
|
||||
{card.list && <ListHead list={card.list} first={first} />}
|
||||
<CardRows>
|
||||
{shown.map((place, index) => (
|
||||
<SavedPlaceRow
|
||||
key={place.id ?? `new-${index}`}
|
||||
place={place}
|
||||
fallbackId={-(index + 1)}
|
||||
labels={place.labelIds.flatMap((id) => labels.get(id) ?? [])}
|
||||
/>
|
||||
))}
|
||||
</CardRows>
|
||||
<CardMore
|
||||
count={more}
|
||||
labelKey="assistant.card.collection.moreInList"
|
||||
target={listTarget(card.list?.id ?? null)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function CollectionPlacesBlock({ cards }: { cards: readonly CardEntry[] }) {
|
||||
const { t } = useTranslation();
|
||||
const placesCards = mergePlacesCards(
|
||||
cards.flatMap((entry) => (entry.card.kind === 'collectionPlaces' ? [entry.card] : []))
|
||||
);
|
||||
const [only] = placesCards;
|
||||
if (!only) return null;
|
||||
const label =
|
||||
placesCards.length === 1 && only.list
|
||||
? t('assistant.card.collection.places', { name: only.list.name })
|
||||
: t('assistant.card.collection.saved');
|
||||
return (
|
||||
<CardFrame label={label}>
|
||||
{placesCards.map((card, index) => (
|
||||
<PlacesSection key={card.list?.id ?? `places-${index}`} card={card} first={index === 0} />
|
||||
))}
|
||||
</CardFrame>
|
||||
);
|
||||
}
|
||||
|
||||
export function CollectionListsBlock({ cards }: { cards: readonly CardEntry[] }) {
|
||||
const { t } = useTranslation();
|
||||
const { onOpen } = useAssistantView();
|
||||
const listsCards = cards.flatMap((entry) => (entry.card.kind === 'collectionLists' ? [entry.card] : []));
|
||||
const { rows, more } = mergeListRows(listsCards);
|
||||
if (rows.length === 0) return null;
|
||||
const place = listsCards.reduce<CollectionListsCard['place']>((found, card) => card.place ?? found, null);
|
||||
const title = place ?? t('assistant.card.collection.lists');
|
||||
return (
|
||||
<CardFrame label={title}>
|
||||
<CardHeader
|
||||
icon={Bookmark}
|
||||
tone="info"
|
||||
title={title}
|
||||
count={place ? undefined : rows.length + more}
|
||||
meta={place ? t('assistant.card.collection.savedIn', { count: rows.length + more }) : undefined}
|
||||
/>
|
||||
<CardRows>
|
||||
{rows.map((row, index) => (
|
||||
<CardRow
|
||||
key={row.id ?? `list-${index}`}
|
||||
lead={<ListLead color={row.color} />}
|
||||
title={
|
||||
<bdi title={row.name} className="block truncate">
|
||||
{row.name}
|
||||
</bdi>
|
||||
}
|
||||
aside={row.status ? <StatusPill status={row.status} /> : undefined}
|
||||
onActivate={row.id !== null && onOpen ? () => onOpen(listTarget(row.id)) : undefined}
|
||||
facts={
|
||||
<CardFacts>
|
||||
{row.invite && row.person && (
|
||||
<SoftPill tone="info">{t('assistant.card.collection.invite', { name: row.person.name })}</SoftPill>
|
||||
)}
|
||||
{row.placeCount !== null && (
|
||||
<WhiteBadge>{t('collections.placeCount', { count: row.placeCount })}</WhiteBadge>
|
||||
)}
|
||||
{row.memberCount > 0 && (
|
||||
<WhiteBadge>{t('assistant.card.collection.members', { count: row.memberCount })}</WhiteBadge>
|
||||
)}
|
||||
</CardFacts>
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</CardRows>
|
||||
<CardMore count={more} target={listTarget(null)} />
|
||||
</CardFrame>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
/**
|
||||
* FE-AI-COLL-020 to FE-AI-COLL-031
|
||||
*
|
||||
* The collections inside the change card: a held save with its list, its
|
||||
* status and the lists that hold the place already; a change of status, of
|
||||
* labels and of fields; an applied save opened in Collections, a duplicate
|
||||
* named, a copy into the trip with its map pin and its count; a list deleted
|
||||
* with what goes; a label renamed; the facts past four counted; trip places
|
||||
* saved to a list without a warning; and a new order of the lists.
|
||||
*/
|
||||
import type { AssistantApplied, AssistantChangePreview, TrekCard } from '@trek/shared';
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { emptyDelta, listRow, listsCard, placesCard, savedPlace } from '../../../../../tests/helpers/collectionCards';
|
||||
import { fireEvent, render, screen } from '../../../../../tests/helpers/render';
|
||||
import { chatOf, useAssistantStore } from '../../../../store/assistantStore';
|
||||
import AssistantChangeCard from '../../AssistantChangeCard';
|
||||
import type { ChangeItem } from '../../assistantParts';
|
||||
import { type AssistantView, AssistantViewContext } from '../../assistantViewContext';
|
||||
|
||||
const TRIP = 4;
|
||||
const INITIAL = useAssistantStore.getState();
|
||||
|
||||
type Verb = AssistantChangePreview['verbKey'];
|
||||
|
||||
function preview(tool: string, subject: string, verbKey: Verb = 'genericCreate'): AssistantChangePreview {
|
||||
return { toolCallId: 'c1', verbKey, subject, rows: [], dayId: null, placeIds: [], undoable: false, tool };
|
||||
}
|
||||
|
||||
function pending(tool: string, subject: string, card: TrekCard, verbKey?: Verb): ChangeItem {
|
||||
return { toolCallId: 'c1', preview: preview(tool, subject, verbKey), applied: null, state: 'pending', card };
|
||||
}
|
||||
|
||||
function applied(item: ChangeItem, entity: AssistantApplied['entity'], ids: number[]): ChangeItem {
|
||||
return { ...item, state: 'applied', applied: { toolCallId: 'c1', entity, ids, dayId: null, undoUntil: null } };
|
||||
}
|
||||
|
||||
function draw(items: ChangeItem[], view: Partial<AssistantView> = {}) {
|
||||
const value: AssistantView = { tripId: TRIP, variant: 'window', onOpen: vi.fn(), ...view };
|
||||
render(
|
||||
<AssistantViewContext.Provider value={value}>
|
||||
<AssistantChangeCard items={items} />
|
||||
</AssistantViewContext.Provider>
|
||||
);
|
||||
return value;
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
useAssistantStore.setState({
|
||||
decide: vi.fn(async () => {}),
|
||||
byTrip: { [TRIP]: { ...chatOf(useAssistantStore.getState(), TRIP), threadId: 1 } },
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
useAssistantStore.setState(INITIAL, true);
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
const SAVE = placesCard({
|
||||
places: [savedPlace({ id: null, labelIds: [], savedIn: [{ listId: 13, name: 'Later', status: 'idea' }] })],
|
||||
labels: [],
|
||||
});
|
||||
|
||||
describe('collection change cards', () => {
|
||||
it('FE-AI-COLL-020: a held save names its list, the status it gets and the list that holds the place already', () => {
|
||||
draw([pending('save_place_to_collection', 'Septime', SAVE)]);
|
||||
expect(screen.getByText('Septime')).toBeInTheDocument();
|
||||
expect(screen.getByText('Save to a list')).toBeInTheDocument();
|
||||
expect(screen.getByText('Paris food')).toBeInTheDocument();
|
||||
expect(screen.getByText('Want to go')).toBeInTheDocument();
|
||||
expect(screen.getByText('Already in Later')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-AI-COLL-021: a change reads its status from old to new, labels added and taken away, and the fields it touches', () => {
|
||||
const delta = emptyDelta({
|
||||
status: { from: 'idea', to: 'visited' },
|
||||
labelsAdded: [53],
|
||||
labelsRemoved: [52],
|
||||
fields: ['photo'],
|
||||
});
|
||||
const card = placesCard({ list: null, places: [savedPlace({ labelIds: [51, 52], delta })] });
|
||||
draw([pending('update_collection_place', 'Septime', card, 'genericUpdate')]);
|
||||
expect(screen.getByText('Change the saved place')).toBeInTheDocument();
|
||||
expect(screen.getByText('Idea')).toHaveClass('line-through');
|
||||
expect(screen.getByText('Visited')).toBeInTheDocument();
|
||||
expect(screen.getByText('Terrace')).not.toHaveClass('line-through');
|
||||
expect(screen.getByText('Late')).toHaveClass('line-through');
|
||||
expect(screen.getByText('Photo')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-AI-COLL-022: an applied save opens the saved place in its list', () => {
|
||||
const card = placesCard({ places: [savedPlace({ id: 77 })] });
|
||||
const view = draw([applied(pending('save_place_to_collection', 'Septime', card), 'collection_place', [77])]);
|
||||
expect(screen.queryByRole('button', { name: 'Show on map' })).toBeNull();
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Open in Collections' }));
|
||||
expect(view.onOpen).toHaveBeenCalledWith({ kind: 'page', path: '/collections/12?place=77' });
|
||||
});
|
||||
|
||||
it('FE-AI-COLL-023: a save the place matched already says where it is saved', () => {
|
||||
const card = { ...SAVE, outcome: { type: 'duplicate' as const, name: 'Rodin museum' } };
|
||||
draw([applied(pending('save_place_to_collection', 'Septime', card), 'collection_place', [])]);
|
||||
expect(screen.getByText('Already in Rodin museum')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-AI-COLL-024: a copy into the trip shows its new trip place on the map and says how many went in', () => {
|
||||
const card = placesCard({
|
||||
places: [savedPlace(), savedPlace({ id: 35, name: 'Le Comptoir', inTripPlaceId: 6 })],
|
||||
outcome: { type: 'copied', copied: 1, skipped: 1, skippedNames: ['Le Comptoir'] },
|
||||
});
|
||||
const copy = pending('copy_collection_places_to_trip', 'Septime, Le Comptoir', card);
|
||||
const view = draw([applied(copy, 'place', [900])]);
|
||||
expect(screen.getByText('1 added')).toBeInTheDocument();
|
||||
expect(screen.getByText('1 already there')).toBeInTheDocument();
|
||||
// The held copy's warning gives way to what the copy did.
|
||||
expect(screen.queryByText('1 already in the trip')).toBeNull();
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Show on map' }));
|
||||
expect(view.onOpen).toHaveBeenCalledWith({ kind: 'map', placeId: 900, dayId: null });
|
||||
});
|
||||
|
||||
it('FE-AI-COLL-025: a held copy warns of the places the trip has, and a copy into another trip says so', () => {
|
||||
const card = placesCard({
|
||||
places: [savedPlace(), savedPlace({ id: 35, name: 'Le Comptoir', inTripPlaceId: 6 })],
|
||||
});
|
||||
draw([pending('copy_collection_places_to_trip', 'Septime, Le Comptoir', card)]);
|
||||
expect(screen.getByText('2 places')).toBeInTheDocument();
|
||||
expect(screen.getByText('1 already in the trip')).toBeInTheDocument();
|
||||
expect(screen.queryByText('Into another trip')).toBeNull();
|
||||
});
|
||||
|
||||
it('FE-AI-COLL-031: a copy into another trip carries no mark of this trip, only the flag', () => {
|
||||
const card = placesCard({ places: [savedPlace(), savedPlace({ id: 35, name: 'Le Comptoir' })], otherTrip: true });
|
||||
draw([pending('copy_collection_places_to_trip', 'Septime, Le Comptoir', card)]);
|
||||
expect(screen.getByText('Into another trip')).toBeInTheDocument();
|
||||
expect(screen.queryByText(/already in the trip/)).toBeNull();
|
||||
});
|
||||
|
||||
it('FE-AI-COLL-026: a list to delete shows what goes; a renamed label reads from its old name to its new one', () => {
|
||||
const removal = listsCard({ lists: [listRow({ placeCount: 12, memberCount: 2, change: 'remove' })] });
|
||||
draw([pending('delete_collection', 'Paris food', removal, 'genericRemove')]);
|
||||
expect(screen.getByText('Will be deleted')).toBeInTheDocument();
|
||||
expect(screen.getByText('12 places')).toBeInTheDocument();
|
||||
expect(screen.getByText('2 members')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-AI-COLL-027: a renamed label reads from its old name to its new one with the places that carry it', () => {
|
||||
const label = {
|
||||
id: 51,
|
||||
name: 'Supper',
|
||||
color: '#2563eb',
|
||||
places: 3,
|
||||
change: 'rename' as const,
|
||||
before: { name: 'Dinner', color: '#2563eb' },
|
||||
};
|
||||
draw([pending('update_collection_label', 'Supper', placesCard({ places: [], labels: [label] }), 'genericUpdate')]);
|
||||
expect(screen.getByText('Dinner')).toHaveClass('line-through');
|
||||
expect(screen.getAllByText('Supper').length).toBeGreaterThan(0);
|
||||
expect(screen.getByText('On 3 places')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-AI-COLL-028: past four facts the rest is counted', () => {
|
||||
const delta = emptyDelta({ fields: ['name', 'address', 'notes', 'link', 'photo'] });
|
||||
const card = placesCard({ places: [savedPlace({ delta })] });
|
||||
draw([pending('update_collection_place', 'Septime', card, 'genericUpdate')]);
|
||||
expect(screen.getByText('+2')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-AI-COLL-029: trip places saved to a list are trip places by nature, so no warning is given', () => {
|
||||
const louvre = savedPlace({ id: null, name: 'Louvre', inTripPlaceId: 6 });
|
||||
const card = placesCard({ places: [savedPlace({ id: null, inTripPlaceId: 5 }), louvre] });
|
||||
draw([pending('save_trip_places_to_collection', 'Septime, Louvre', card)]);
|
||||
expect(screen.getByText('2 places')).toBeInTheDocument();
|
||||
expect(screen.queryByText(/already in the trip/)).toBeNull();
|
||||
});
|
||||
|
||||
it('FE-AI-COLL-030: a new order of the lists numbers them in turn', () => {
|
||||
const rome = listRow({ id: 13, name: 'Rome', change: 'order' });
|
||||
const order = listsCard({ lists: [rome, listRow({ id: 12, name: 'Paris food', change: 'order' })] });
|
||||
draw([pending('reorder_collections', 'Rome, Paris food', order, 'genericUpdate')]);
|
||||
expect(screen.getByText('1 Rome')).toBeInTheDocument();
|
||||
expect(screen.getByText('2 Paris food')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,285 @@
|
||||
import type {
|
||||
CollectionCardDelta,
|
||||
CollectionCardLabel,
|
||||
CollectionCardList,
|
||||
CollectionCardPlace,
|
||||
CollectionListsCard,
|
||||
CollectionPlacesCard,
|
||||
} from '@trek/shared';
|
||||
import { Bookmark, Info, Tag } from 'lucide-react';
|
||||
import type { ReactNode } from 'react';
|
||||
|
||||
import { useTranslation } from '../../../../i18n';
|
||||
import { STATUS_META } from '../../../Collections/collectionStatus';
|
||||
import { type PillTone, SoftPill, WhiteBadge } from '../../../Planner/planParts';
|
||||
import PlaceAvatar from '../../../shared/PlaceAvatar';
|
||||
import type { ChangeItem } from '../../assistantParts';
|
||||
import { verbLookOf } from '../cardLooks';
|
||||
import { ChangeMark, FactChange } from '../parts/CardFacts';
|
||||
import KindTile from '../parts/KindTile';
|
||||
import { avatarCategory, avatarPlace, labelsById, MAX_FACTS } from './collectionCardModel';
|
||||
import { LabelChip, ListDot, RatingPill, StatusPill } from './collectionCardParts';
|
||||
|
||||
/**
|
||||
* The collections inside a change card: the saved place in front, with the
|
||||
* tile of what happens on its corner (an overlapping stack for several), and
|
||||
* on the faint line what the change does in small pills (its list, the
|
||||
* status from and to, labels added or taken away, a vote, the fields it
|
||||
* touches, a move), with warnings where a place is saved or in the trip
|
||||
* already. An applied change says what it did instead: saved, a duplicate,
|
||||
* how many went in.
|
||||
*/
|
||||
|
||||
type T = (key: string, params?: Record<string, string | number>) => string;
|
||||
|
||||
const COPY_TOOL = 'copy_collection_places_to_trip';
|
||||
|
||||
/** The fields a change touches, each by the label the other change cards name it with. */
|
||||
const FIELD_LOOK: Record<CollectionCardDelta['fields'][number], { labelKey: string }> = {
|
||||
name: { labelKey: 'assistant.change.label.name' },
|
||||
address: { labelKey: 'assistant.change.label.address' },
|
||||
coordinates: { labelKey: 'assistant.change.label.coordinates' },
|
||||
description: { labelKey: 'assistant.change.label.description' },
|
||||
notes: { labelKey: 'assistant.change.label.notes' },
|
||||
category: { labelKey: 'assistant.change.label.category' },
|
||||
link: { labelKey: 'assistant.change.label.link' },
|
||||
photo: { labelKey: 'assistant.card.collection.photo' },
|
||||
};
|
||||
|
||||
/** The verb's tile, as the row shows it without a place. */
|
||||
function VerbTile({ item, size }: { item: ChangeItem; size: 'xs' | 'sm' }) {
|
||||
const look = item.preview ? verbLookOf(item.preview.verbKey) : null;
|
||||
return <KindTile icon={look?.Icon ?? null} tone={look?.tone ?? 'info'} size={size} />;
|
||||
}
|
||||
|
||||
export function CollectionPlaceLead({ card, item }: { card: CollectionPlacesCard; item: ChangeItem }) {
|
||||
const [single] = card.places;
|
||||
if (!single) return <VerbTile item={item} size="sm" />;
|
||||
if (card.places.length === 1) {
|
||||
return (
|
||||
<span className="relative flex-none">
|
||||
<PlaceAvatar place={avatarPlace(single, -1)} size={28} category={avatarCategory(single)} />
|
||||
<span className="absolute -bottom-0.5 -end-0.5 flex">
|
||||
<VerbTile item={item} size="xs" />
|
||||
</span>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
const stacked = card.places.slice(0, 4);
|
||||
const extra = card.places.length - stacked.length + card.more;
|
||||
return (
|
||||
<span className="flex flex-none items-center">
|
||||
{stacked.map((place, index) => (
|
||||
<span key={place.id ?? `new-${index}`} className={index === 0 ? 'flex' : '-ms-1.5 flex'}>
|
||||
<PlaceAvatar place={avatarPlace(place, -(index + 1))} size={20} category={avatarCategory(place)} />
|
||||
</span>
|
||||
))}
|
||||
{extra > 0 && <WhiteBadge className="ms-1">+{extra}</WhiteBadge>}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
/** One small fact in words. */
|
||||
function Pill({ tone, text }: { tone?: PillTone; text: string }) {
|
||||
return (
|
||||
<SoftPill tone={tone}>
|
||||
<bdi className="truncate">{text}</bdi>
|
||||
</SoftPill>
|
||||
);
|
||||
}
|
||||
|
||||
/** At most MAX_FACTS pills, the rest counted. */
|
||||
function Capped({ pills }: { pills: ReactNode[] }) {
|
||||
const rest = pills.length - MAX_FACTS;
|
||||
return (
|
||||
<>
|
||||
{pills.slice(0, MAX_FACTS)}
|
||||
{rest > 0 && <WhiteBadge>+{rest}</WhiteBadge>}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function ListChip({ list }: { list: CollectionCardList }) {
|
||||
return (
|
||||
<SoftPill icon={<ListDot color={list.color} size={8} />}>
|
||||
<bdi className="truncate">{list.name}</bdi>
|
||||
</SoftPill>
|
||||
);
|
||||
}
|
||||
|
||||
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';
|
||||
return <FactChange key="status" icon={to.icon} before={before} after={t(to.labelKey)} tone={tone} />;
|
||||
}
|
||||
|
||||
/** What an applied change did, from the tool's answer. */
|
||||
function outcomePills(card: CollectionPlacesCard, t: T): ReactNode[] {
|
||||
const outcome = card.outcome;
|
||||
if (!outcome) return [];
|
||||
if (outcome.type === 'duplicate') {
|
||||
const text = t('assistant.card.collection.alreadySaved', { name: outcome.name });
|
||||
return [<FactChange key="duplicate" icon={Info} before={null} after={text} tone="info" />];
|
||||
}
|
||||
if (outcome.type === 'statusSet') {
|
||||
const text = t('assistant.card.collection.statusSet', { count: outcome.updated });
|
||||
return [<Pill key="set" tone="success" text={text} />];
|
||||
}
|
||||
const copied = t('assistant.card.collection.copied', { count: outcome.copied });
|
||||
const pills: ReactNode[] = [<Pill key="copied" tone="success" text={copied} />];
|
||||
if (outcome.skipped > 0) {
|
||||
const skipped = t('assistant.card.collection.skipped', { count: outcome.skipped });
|
||||
pills.push(<Pill key="skipped" text={skipped} />);
|
||||
}
|
||||
return pills;
|
||||
}
|
||||
|
||||
/** Labels a change adds and takes away, as chips in their colours. */
|
||||
function labelPills(added: number[], removed: number[], labels: Map<number, CollectionCardLabel>): ReactNode[] {
|
||||
const chip = (id: number, mark: 'add' | 'remove') => {
|
||||
const label = labels.get(id);
|
||||
return label ? [<LabelChip key={`${mark}-${id}`} label={label} mark={mark} />] : [];
|
||||
};
|
||||
return [...added.flatMap((id) => chip(id, 'add')), ...removed.flatMap((id) => chip(id, 'remove'))];
|
||||
}
|
||||
|
||||
/** What a held change does to a saved place: its status, labels, vote, fields, list, removal. */
|
||||
function deltaPills(delta: CollectionCardDelta, card: CollectionPlacesCard, t: T): ReactNode[] {
|
||||
const pills: ReactNode[] = [];
|
||||
if (delta.status) pills.push(statusChange(delta.status, t));
|
||||
pills.push(...labelPills(delta.labelsAdded, delta.labelsRemoved, labelsById(card.labels)));
|
||||
if (delta.rating) {
|
||||
const to = delta.rating.to;
|
||||
const cleared = t('assistant.card.collection.ratingCleared');
|
||||
pills.push(to === null ? <Pill key="rating" text={cleared} /> : <RatingPill key="rating" rating={to} />);
|
||||
}
|
||||
for (const field of delta.fields) pills.push(<Pill key={field} text={t(FIELD_LOOK[field].labelKey)} />);
|
||||
if (delta.movedTo) {
|
||||
const text = t('assistant.card.collection.moveTo', { name: delta.movedTo.name });
|
||||
pills.push(<Pill key="move" tone="info" text={text} />);
|
||||
}
|
||||
if (delta.removed) pills.push(<Pill key="removed" tone="danger" text={t('assistant.card.collection.removed')} />);
|
||||
return pills;
|
||||
}
|
||||
|
||||
/** What a change does to its one saved place; a place to save shows the status it gets. */
|
||||
function placePills(place: CollectionCardPlace, card: CollectionPlacesCard, tool: string | null, t: T): ReactNode[] {
|
||||
const pills: ReactNode[] = place.delta
|
||||
? deltaPills(place.delta, card, t)
|
||||
: [<StatusPill key="status" status={place.status} />];
|
||||
for (const saved of place.savedIn) {
|
||||
const text = t('assistant.card.collection.alreadySaved', { name: saved.name });
|
||||
pills.push(<Pill key={`saved-${saved.listId}`} tone="warning" text={text} />);
|
||||
}
|
||||
// Once a copy ran, its outcome names what it skipped; the warning is for the held copy.
|
||||
if (place.inTripPlaceId !== null && !(tool === COPY_TOOL && card.outcome)) {
|
||||
const skipped = tool === COPY_TOOL;
|
||||
const text = skipped ? t('assistant.card.collection.willSkip', { count: 1 }) : t('assistant.place.inTrip');
|
||||
pills.push(<Pill key="trip" tone={skipped ? 'warning' : 'info'} text={text} />);
|
||||
}
|
||||
return pills;
|
||||
}
|
||||
|
||||
/**
|
||||
* What a change does to several saved places at once. Only a held copy into
|
||||
* the trip warns of the places the trip has: a save from the trip names trip
|
||||
* places by nature, and a copy that ran says what it skipped.
|
||||
*/
|
||||
function manyPills(card: CollectionPlacesCard, tool: string | null, t: T): ReactNode[] {
|
||||
const status = card.places.find((place) => place.delta?.status)?.delta?.status ?? null;
|
||||
const added = [...new Set(card.places.flatMap((place) => place.delta?.labelsAdded ?? []))];
|
||||
const removed = [...new Set(card.places.flatMap((place) => place.delta?.labelsRemoved ?? []))];
|
||||
const warns = tool === COPY_TOOL && !card.outcome;
|
||||
const inTrip = warns ? card.places.filter((place) => place.inTripPlaceId !== null).length : 0;
|
||||
const pills: ReactNode[] = [
|
||||
<Pill key="count" text={t('collections.placeCount', { count: card.places.length + card.more })} />,
|
||||
];
|
||||
if (status) pills.push(statusChange(status, t));
|
||||
if (card.everyList) pills.push(<Pill key="every" tone="info" text={t('assistant.card.collection.everyList')} />);
|
||||
pills.push(...labelPills(added, removed, labelsById(card.labels)));
|
||||
if (inTrip > 0) {
|
||||
const text = t('assistant.card.collection.willSkip', { count: inTrip });
|
||||
pills.push(<Pill key="trip" tone="warning" text={text} />);
|
||||
}
|
||||
return pills;
|
||||
}
|
||||
|
||||
/** A label a change makes, renames or deletes, with how many places carry it. */
|
||||
function labelChangePills(card: CollectionPlacesCard, t: T): ReactNode[] {
|
||||
return card.labels.flatMap((label) => {
|
||||
const mark = label.change === 'add' ? 'add' : label.change === 'remove' ? 'remove' : undefined;
|
||||
const renamed = label.before !== null && label.before.name !== label.name;
|
||||
const pills: ReactNode[] = [
|
||||
renamed ? (
|
||||
<FactChange key={`label-${label.name}`} icon={Tag} before={label.before?.name ?? null} after={label.name} />
|
||||
) : (
|
||||
<LabelChip key={`label-${label.name}`} label={label} mark={mark} />
|
||||
),
|
||||
];
|
||||
if (label.places !== null && label.change !== 'add') {
|
||||
const text = t('assistant.card.collection.labelUsedBy', { count: label.places });
|
||||
pills.push(<Pill key={`used-${label.name}`} text={text} />);
|
||||
}
|
||||
return pills;
|
||||
});
|
||||
}
|
||||
|
||||
export function CollectionPlaceFacts({ card, item }: { card: CollectionPlacesCard; item: ChangeItem }) {
|
||||
const { t } = useTranslation();
|
||||
const [single] = card.places;
|
||||
const tool = item.preview?.tool ?? null;
|
||||
const pills = outcomePills(card, t);
|
||||
if (card.list) pills.push(<ListChip key="list" list={card.list} />);
|
||||
if (!single) pills.push(...labelChangePills(card, t));
|
||||
else if (card.places.length === 1) pills.push(...placePills(single, card, tool, t));
|
||||
else pills.push(...manyPills(card, tool, t));
|
||||
if (card.otherTrip) {
|
||||
pills.push(<Pill key="other" tone="warning" text={t('assistant.card.collection.otherTrip')} />);
|
||||
}
|
||||
return <Capped pills={pills} />;
|
||||
}
|
||||
|
||||
/** What a change does to a list: new, renamed, deleted with what goes, an invite answered or withdrawn, a new order. */
|
||||
function listPills(card: CollectionListsCard, t: T, locale: string): ReactNode[] {
|
||||
const [row] = card.lists;
|
||||
if (!row) return [];
|
||||
const person = row.person?.name ?? '';
|
||||
switch (row.change) {
|
||||
case 'add':
|
||||
return [<ChangeMark key="mark" change="new" />];
|
||||
case 'update':
|
||||
return row.before && row.before.name !== row.name
|
||||
? [<FactChange key="name" icon={Bookmark} before={row.before.name} after={row.name} />]
|
||||
: [<ChangeMark key="mark" change="changed" />];
|
||||
case 'remove': {
|
||||
const pills: ReactNode[] = [<ChangeMark key="mark" change="willDelete" />];
|
||||
if (row.placeCount !== null) {
|
||||
pills.push(<Pill key="places" text={t('collections.placeCount', { count: row.placeCount })} />);
|
||||
}
|
||||
if (row.memberCount > 0) {
|
||||
const members = t('assistant.card.collection.members', { count: row.memberCount });
|
||||
pills.push(<Pill key="members" text={members} />);
|
||||
}
|
||||
return pills;
|
||||
}
|
||||
case 'join':
|
||||
case 'decline': {
|
||||
const tone = row.change === 'join' ? 'info' : 'neutral';
|
||||
return [<Pill key="invite" tone={tone} text={t('assistant.card.collection.invite', { name: person })} />];
|
||||
}
|
||||
case 'withdraw':
|
||||
return [<Pill key="withdraw" tone="warning" text={t('assistant.card.collection.withdraw', { name: person })} />];
|
||||
case 'order':
|
||||
return card.lists.map((list, index) => (
|
||||
<Pill key={list.id ?? index} text={`${(index + 1).toLocaleString(locale)} ${list.name}`} />
|
||||
));
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export function CollectionListFacts({ card }: { card: CollectionListsCard }) {
|
||||
const { t, locale } = useTranslation();
|
||||
return <Capped pills={listPills(card, t, locale)} />;
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
import type {
|
||||
AssistantApplied,
|
||||
CollectionCardLabel,
|
||||
CollectionCardPlace,
|
||||
CollectionListRow,
|
||||
CollectionListsCard,
|
||||
CollectionPlacesCard,
|
||||
TrekCard,
|
||||
} from '@trek/shared';
|
||||
|
||||
import type { EntityTarget } from '../cardTypes';
|
||||
|
||||
/**
|
||||
* The pure side of the collections' cards: where a list and a saved place
|
||||
* open, the saved place a card is about, how cards of several reads lay out
|
||||
* as one, and how many rows a card shows. No components here, so the look
|
||||
* (and the main chunk with it) reads it without pulling in a card.
|
||||
*/
|
||||
|
||||
/** Rows a places card shows in a narrow chat and in a roomy one; the server sends at most the second. */
|
||||
const ROWS_COMPACT = 5;
|
||||
const ROWS_ROOMY = 8;
|
||||
|
||||
/** Pills a change row shows before it counts the rest. */
|
||||
export const MAX_FACTS = 4;
|
||||
|
||||
/** Where a list opens in Collections. */
|
||||
export function listTarget(listId: number | null): EntityTarget {
|
||||
return { kind: 'page', path: listId === null ? '/collections' : `/collections/${listId}` };
|
||||
}
|
||||
|
||||
/** Where a saved place opens: its list, with the place selected. */
|
||||
function placeTarget(listId: number, placeId: number | null): EntityTarget {
|
||||
const path = `/collections/${listId}`;
|
||||
return { kind: 'page', path: placeId === null ? path : `${path}?place=${placeId}` };
|
||||
}
|
||||
|
||||
function placesCardOf(card: TrekCard | null): CollectionPlacesCard | null {
|
||||
return card?.kind === 'collectionPlaces' ? card : null;
|
||||
}
|
||||
|
||||
/** The saved place a change card is about: its only one. */
|
||||
export function firstPlace(card: TrekCard | null): CollectionCardPlace | null {
|
||||
const places = placesCardOf(card)?.places ?? [];
|
||||
return places.length === 1 ? (places[0] ?? null) : null;
|
||||
}
|
||||
|
||||
/** The list an applied change of a list opens; none for a list it deleted or an invite it declined. */
|
||||
export function appliedListTarget(applied: AssistantApplied, card: TrekCard | null): EntityTarget | null {
|
||||
const row = card?.kind === 'collectionLists' ? card.lists[0] : undefined;
|
||||
if (row && (row.change === 'remove' || row.change === 'decline')) return null;
|
||||
const id = applied.ids[0] ?? row?.id ?? placesCardOf(card)?.list?.id ?? null;
|
||||
return id === null ? null : listTarget(id);
|
||||
}
|
||||
|
||||
/** The saved place an applied change opens; its list once the change removed it. */
|
||||
export function appliedPlaceTarget(applied: AssistantApplied, card: TrekCard | null): EntityTarget | null {
|
||||
const place = firstPlace(card);
|
||||
const listId = place?.listId ?? placesCardOf(card)?.list?.id ?? null;
|
||||
if (listId === null) return null;
|
||||
if (place?.delta?.removed) return listTarget(listId);
|
||||
return placeTarget(listId, applied.ids[0] ?? place?.id ?? null);
|
||||
}
|
||||
|
||||
/** The trip place an applied change of a saved place is, for "Show on map". */
|
||||
export function appliedPlaceOnMap(card: TrekCard | null): { placeId: number; dayId: null } | null {
|
||||
const placeId = firstPlace(card)?.inTripPlaceId ?? null;
|
||||
return placeId === null ? null : { placeId, dayId: null };
|
||||
}
|
||||
|
||||
/** How many rows a places card shows at this density. */
|
||||
export function rowsShown(density: 'compact' | 'roomy' | undefined): number {
|
||||
return density === 'roomy' ? ROWS_ROOMY : ROWS_COMPACT;
|
||||
}
|
||||
|
||||
/**
|
||||
* The places cards of one answer as one: a list read twice shows once (the
|
||||
* later read wins, in the place of the first), places of several lists each
|
||||
* under their own head.
|
||||
*/
|
||||
export function mergePlacesCards(cards: readonly CollectionPlacesCard[]): CollectionPlacesCard[] {
|
||||
const merged: CollectionPlacesCard[] = [];
|
||||
for (const card of cards) {
|
||||
const id = card.list?.id ?? null;
|
||||
const at = id === null ? -1 : merged.findIndex((seen) => seen.list?.id === id);
|
||||
if (at >= 0) merged[at] = card;
|
||||
else merged.push(card);
|
||||
}
|
||||
return merged;
|
||||
}
|
||||
|
||||
/** The rows of several lists cards as one: a list twice shows once, as the later card has it. */
|
||||
export function mergeListRows(cards: readonly CollectionListsCard[]): { rows: CollectionListRow[]; more: number } {
|
||||
const rows: CollectionListRow[] = [];
|
||||
let more = 0;
|
||||
for (const card of cards) {
|
||||
more += card.more;
|
||||
for (const row of card.lists) {
|
||||
const at = row.id === null ? -1 : rows.findIndex((seen) => seen.id === row.id);
|
||||
if (at >= 0) rows[at] = row;
|
||||
else rows.push(row);
|
||||
}
|
||||
}
|
||||
return { rows, more };
|
||||
}
|
||||
|
||||
/** The labels a card names, by id. */
|
||||
export function labelsById(labels: readonly CollectionCardLabel[]): Map<number, CollectionCardLabel> {
|
||||
return new Map(labels.flatMap((label) => (label.id === null ? [] : [[label.id, label] as const])));
|
||||
}
|
||||
|
||||
/** A saved place as the shared place avatar takes it: its own photo by TREK's address, else its provider ids. */
|
||||
export function avatarPlace(place: CollectionCardPlace, fallbackId: number) {
|
||||
return {
|
||||
id: place.id ?? fallbackId,
|
||||
name: place.name,
|
||||
image_url: place.imageKey ? `/uploads/places/${place.imageKey}` : null,
|
||||
google_place_id: place.googlePlaceId,
|
||||
osm_id: place.osmId,
|
||||
lat: place.lat,
|
||||
lng: place.lng,
|
||||
};
|
||||
}
|
||||
|
||||
/** The category colour and icon the avatar falls back to without a photo. */
|
||||
export function avatarCategory(place: CollectionCardPlace): { color?: string; icon?: string } | null {
|
||||
const category = place.category;
|
||||
if (!category) return null;
|
||||
return { color: category.color ?? undefined, icon: category.icon ?? undefined };
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
import type { CollectionCardLabel, CollectionCardList, CollectionCardPlace, CollectionStatus } 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 { SoftPill, tintOf, WhiteBadge } from '../../../Planner/planParts';
|
||||
import PlaceAvatar from '../../../shared/PlaceAvatar';
|
||||
import { Tooltip } from '../../../shared/Tooltip';
|
||||
import { useAssistantView } from '../../assistantViewContext';
|
||||
import { CardFacts } from '../parts/CardFacts';
|
||||
import { CardOpenButton } from '../parts/CardOpen';
|
||||
import { CardRow } from '../parts/CardRows';
|
||||
import { useCardPoint } from '../parts/useCardPoint';
|
||||
import { avatarCategory, avatarPlace, listTarget } from './collectionCardModel';
|
||||
|
||||
/**
|
||||
* The pieces the collections' cards are drawn with, the way the Collections
|
||||
* page draws them: a list's colour dot and head, a saved place as a row with
|
||||
* its photo, status, labels and rating, and a label as a chip in its colour.
|
||||
* Every fact is a small pill, as on the planner's rows.
|
||||
*/
|
||||
|
||||
/** A list's colour as a dot; the accent where the list has none. */
|
||||
export function ListDot({ color, size = 10 }: { color: string | null; size?: 8 | 10 }) {
|
||||
return (
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className={`flex-none rounded-full ${size === 8 ? 'h-2 w-2' : 'h-2.5 w-2.5'}`}
|
||||
style={{ background: safeHexColor(color, 'var(--accent)') }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
/** A list's dot in front of its row, where a place shows its photo. */
|
||||
export function ListLead({ color }: { color: string | null }) {
|
||||
return (
|
||||
<span className="grid h-7 w-7 flex-none place-items-center">
|
||||
<ListDot color={color} />
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
/** A label as a chip in its colour; one a change adds or takes away says so. */
|
||||
export function LabelChip({
|
||||
label,
|
||||
mark,
|
||||
}: {
|
||||
label: Pick<CollectionCardLabel, 'name' | 'color'>;
|
||||
mark?: 'add' | 'remove';
|
||||
}) {
|
||||
const dot = { '--label': safeHexColor(label.color, 'var(--accent)') } as CSSProperties;
|
||||
return (
|
||||
<span style={dot} className="inline-flex min-w-0">
|
||||
<SoftPill
|
||||
tone={mark === 'add' ? 'success' : mark === 'remove' ? 'danger' : 'neutral'}
|
||||
icon={<span aria-hidden="true" className="h-2 w-2 flex-none rounded-full bg-[var(--label)]" />}
|
||||
>
|
||||
{mark === 'add' && <span aria-hidden="true">+</span>}
|
||||
{mark === 'remove' && <span aria-hidden="true">−</span>}
|
||||
<bdi className={`truncate ${mark === 'remove' ? 'line-through' : ''}`}>{label.name}</bdi>
|
||||
</SoftPill>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
/** The first two labels of a place as chips, the rest counted; their names in the count's tooltip. */
|
||||
function LabelChips({ labels }: { labels: readonly CollectionCardLabel[] }) {
|
||||
const rest = labels.slice(2);
|
||||
return (
|
||||
<>
|
||||
{labels.slice(0, 2).map((label) => (
|
||||
<LabelChip key={label.id ?? label.name} label={label} />
|
||||
))}
|
||||
{rest.length > 0 && (
|
||||
<Tooltip label={rest.map((label) => label.name).join(', ')} placement="top">
|
||||
<span tabIndex={0} className="rounded-full outline-none focus-visible:ring-2 focus-visible:ring-accent">
|
||||
<WhiteBadge>+{rest.length}</WhiteBadge>
|
||||
</span>
|
||||
</Tooltip>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/** A status with its icon in its colour, as the Collections page shows it; a count beside it on a list head. */
|
||||
export function StatusPill({ status, count }: { status: CollectionStatus; count?: number }) {
|
||||
const { t } = useTranslation();
|
||||
const meta = STATUS_META[status];
|
||||
const Icon = meta.icon;
|
||||
const icon = (
|
||||
<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}>
|
||||
{count !== undefined && <span className="tabular-nums">{count}</span>}
|
||||
<span>{t(meta.labelKey)}</span>
|
||||
</SoftPill>
|
||||
);
|
||||
}
|
||||
|
||||
/** The members' average vote, to a tenth. */
|
||||
export function RatingPill({ rating }: { rating: number }) {
|
||||
const { locale } = useTranslation();
|
||||
return (
|
||||
<SoftPill icon={<Star size={10} aria-hidden="true" className="flex-none fill-current text-warning" />}>
|
||||
<span className="tabular-nums">{rating.toLocaleString(locale, { maximumFractionDigits: 1 })}</span>
|
||||
</SoftPill>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A list's head, tinted in its colour like a planner card's head: its dot and
|
||||
* name, its size and the people sharing it, the way to open it, and where
|
||||
* the whole list was read, its places per status.
|
||||
*/
|
||||
export function ListHead({ list, first = true }: { list: CollectionCardList; first?: boolean }) {
|
||||
const { t } = useTranslation();
|
||||
const color = safeHexColor(list.color, 'var(--accent)');
|
||||
const counts = list.counts;
|
||||
const size = list.placeCount === null ? null : t('collections.placeCount', { count: list.placeCount });
|
||||
return (
|
||||
<div
|
||||
className={`-mx-3 -mt-2.5 px-3 pb-2 pt-2.5 ${first ? 'rounded-t-xl' : ''}`}
|
||||
style={{ background: tintOf(color) }}
|
||||
>
|
||||
<div className="flex min-w-0 items-center gap-2">
|
||||
<ListDot color={list.color} />
|
||||
<bdi title={list.name} className="min-w-0 flex-1 truncate text-body font-semibold leading-tight text-content">
|
||||
{list.name}
|
||||
</bdi>
|
||||
{size && <WhiteBadge>{size}</WhiteBadge>}
|
||||
{list.memberCount > 0 && (
|
||||
<WhiteBadge>{t('assistant.card.collection.members', { count: list.memberCount })}</WhiteBadge>
|
||||
)}
|
||||
{list.id !== null && (
|
||||
<CardOpenButton target={listTarget(list.id)} labelKey="assistant.card.collection.openList" />
|
||||
)}
|
||||
</div>
|
||||
{counts && (
|
||||
<CardFacts>
|
||||
{(['idea', 'want', 'visited'] as const).map((status) => (
|
||||
<StatusPill key={status} status={status} count={counts[status]} />
|
||||
))}
|
||||
</CardFacts>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A saved place as a row: its photo, its name, its status at the end, and on
|
||||
* the line under it its address, labels, rating and whether the trip has it.
|
||||
* Resting on a row with a position shows it on the map; a click selects the
|
||||
* trip's own place, or moves the map to the saved one.
|
||||
*/
|
||||
export function SavedPlaceRow({
|
||||
place,
|
||||
labels,
|
||||
fallbackId,
|
||||
}: {
|
||||
place: CollectionCardPlace;
|
||||
labels: readonly CollectionCardLabel[];
|
||||
fallbackId: number;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const { variant, onOpen } = useAssistantView();
|
||||
const { hover, show } = useCardPoint();
|
||||
const { lat, lng, inTripPlaceId } = place;
|
||||
const point = lat !== null && lng !== null ? { lat, lng } : null;
|
||||
const ref = `col:${place.id ?? fallbackId}`;
|
||||
const activate =
|
||||
inTripPlaceId !== null && onOpen
|
||||
? () => onOpen({ kind: 'map', placeId: inTripPlaceId, dayId: null })
|
||||
: point
|
||||
? () => show(point)
|
||||
: undefined;
|
||||
const onHover =
|
||||
point && variant !== 'fullscreen'
|
||||
? (on: boolean) => hover(on ? { ref, ...point, name: place.name, placeId: inTripPlaceId ?? undefined } : null)
|
||||
: undefined;
|
||||
return (
|
||||
<CardRow
|
||||
lead={<PlaceAvatar place={avatarPlace(place, fallbackId)} size={28} category={avatarCategory(place)} />}
|
||||
title={
|
||||
<bdi title={place.name} className="block truncate">
|
||||
{place.name}
|
||||
</bdi>
|
||||
}
|
||||
aside={<StatusPill status={place.status} />}
|
||||
onActivate={activate}
|
||||
onHover={onHover}
|
||||
facts={
|
||||
<CardFacts>
|
||||
{place.address && (
|
||||
<bdi
|
||||
title={place.address}
|
||||
className="min-w-0 max-w-full truncate text-caption font-normal text-content-faint"
|
||||
>
|
||||
{place.address}
|
||||
</bdi>
|
||||
)}
|
||||
<LabelChips labels={labels} />
|
||||
{place.rating !== null && <RatingPill rating={place.rating} />}
|
||||
{inTripPlaceId !== null && <SoftPill tone="info">{t('assistant.place.inTrip')}</SoftPill>}
|
||||
</CardFacts>
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
* FE-AI-COLL-001 to FE-AI-COLL-006
|
||||
*
|
||||
* The pure look of the collections in the chat: each write named by its
|
||||
* own action, what an applied change opens (a list, a saved place selected
|
||||
* in it, the trip place of a copy on the map), the reading steps, the
|
||||
* follow-ups only an editor is offered, and how cards of several reads lay
|
||||
* out as one.
|
||||
*/
|
||||
import type { AssistantApplied } from '@trek/shared';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import {
|
||||
emptyDelta,
|
||||
LIST,
|
||||
listRow,
|
||||
listsCard,
|
||||
placesCard,
|
||||
savedPlace,
|
||||
} from '../../../../../tests/helpers/collectionCards';
|
||||
import { CARD_LOOKS, ENTITY_LOOK, STEP_LOOKS, TOOL_LABELS } from '../cardLooks';
|
||||
import { avatarPlace, mergeListRows, mergePlacesCards, rowsShown } from './collectionCardModel';
|
||||
|
||||
const applied = (entity: AssistantApplied['entity'], ids: number[]): AssistantApplied => ({
|
||||
toolCallId: 'c1',
|
||||
entity,
|
||||
ids,
|
||||
dayId: null,
|
||||
undoUntil: null,
|
||||
});
|
||||
|
||||
const WRITES = [
|
||||
'create_collection',
|
||||
'update_collection',
|
||||
'delete_collection',
|
||||
'reorder_collections',
|
||||
'save_place_to_collection',
|
||||
'save_trip_places_to_collection',
|
||||
'update_collection_place',
|
||||
'set_collection_place_status',
|
||||
'set_collection_place_status_from_trip',
|
||||
'rate_collection_place',
|
||||
'delete_collection_place',
|
||||
'copy_collection_places_to_trip',
|
||||
'create_collection_label',
|
||||
'update_collection_label',
|
||||
'delete_collection_label',
|
||||
'assign_collection_labels',
|
||||
'accept_collection_invite',
|
||||
'decline_collection_invite',
|
||||
'cancel_collection_invite',
|
||||
];
|
||||
|
||||
describe('collection look', () => {
|
||||
it('FE-AI-COLL-001: every write of the collections is named by its own action', () => {
|
||||
for (const tool of WRITES) expect(TOOL_LABELS[tool]?.labelKey).toBe(`assistant.tool.${tool}`);
|
||||
expect(STEP_LOOKS.get_collection?.stepKey).toBe('assistant.step.readingList');
|
||||
expect(STEP_LOOKS.list_collections?.stepKey).toBe('assistant.step.lookingAtLists');
|
||||
expect(STEP_LOOKS.find_place_in_collections?.stepKey).toBe('assistant.step.checkingLists');
|
||||
});
|
||||
|
||||
it('FE-AI-COLL-002: an applied list opens in Collections, unless the change deleted it or declined its invite', () => {
|
||||
const look = ENTITY_LOOK.collection;
|
||||
expect(look.openLabelKey).toBe('assistant.card.collection.openList');
|
||||
expect(look.open?.(applied('collection', [12]), null)).toEqual({ kind: 'page', path: '/collections/12' });
|
||||
const card = listsCard({ lists: [listRow({ id: 13 })] });
|
||||
expect(look.open?.(applied('collection', []), card)).toEqual({ kind: 'page', path: '/collections/13' });
|
||||
for (const change of ['remove', 'decline'] as const) {
|
||||
expect(look.open?.(applied('collection', [12]), listsCard({ lists: [listRow({ change })] }))).toBeNull();
|
||||
}
|
||||
expect(look.open?.(applied('collection', []), null)).toBeNull();
|
||||
});
|
||||
|
||||
it('FE-AI-COLL-003: an applied saved place opens selected in its list; a removed one opens the list', () => {
|
||||
const look = ENTITY_LOOK.collection_place;
|
||||
const card = placesCard();
|
||||
expect(look.open?.(applied('collection_place', [34]), card)).toEqual({
|
||||
kind: 'page',
|
||||
path: '/collections/12?place=34',
|
||||
});
|
||||
const removed = placesCard({ places: [savedPlace({ delta: emptyDelta({ removed: true }) })] });
|
||||
expect(look.open?.(applied('collection_place', [34]), removed)).toEqual({ kind: 'page', path: '/collections/12' });
|
||||
expect(look.open?.(applied('collection_place', [34]), null)).toBeNull();
|
||||
});
|
||||
|
||||
it('FE-AI-COLL-004: a saved place that is in the trip shows its trip place on the map; one that is not, nothing', () => {
|
||||
const look = ENTITY_LOOK.collection_place;
|
||||
const inTrip = placesCard({ places: [savedPlace({ inTripPlaceId: 6 })] });
|
||||
expect(look.onMap?.(applied('collection_place', [34]), inTrip)).toEqual({ placeId: 6, dayId: null });
|
||||
expect(look.onMap?.(applied('collection_place', [34]), placesCard())).toBeNull();
|
||||
});
|
||||
|
||||
it('FE-AI-COLL-005: a list of saved places offers to plan with it, to editors only', () => {
|
||||
const followUps = CARD_LOOKS.collectionPlaces.followUps ?? [];
|
||||
expect(followUps.map((followUp) => [followUp.labelKey, followUp.edits])).toEqual([
|
||||
['assistant.followUp.collectionToTrip', true],
|
||||
['assistant.followUp.collectionDay', true],
|
||||
]);
|
||||
expect(CARD_LOOKS.collectionLists.followUps).toBeUndefined();
|
||||
});
|
||||
|
||||
it('FE-AI-COLL-006: a list read twice shows once, as read last; lists cards merge their rows by id', () => {
|
||||
const first = placesCard({ places: [savedPlace({ name: 'Old' })] });
|
||||
const other = placesCard({ list: { ...LIST, id: 13, name: 'Rome' } });
|
||||
const again = placesCard({ places: [savedPlace({ name: 'New' })] });
|
||||
const spread = placesCard({ list: null });
|
||||
const merged = mergePlacesCards([first, other, again, spread, spread]);
|
||||
expect(merged.map((card) => [card.list?.id ?? null, card.places[0]?.name])).toEqual([
|
||||
[12, 'New'],
|
||||
[13, 'Septime'],
|
||||
[null, 'Septime'],
|
||||
[null, 'Septime'],
|
||||
]);
|
||||
const rows = mergeListRows([
|
||||
listsCard({ lists: [listRow({ id: 1, name: 'A' }), listRow({ id: 2, name: 'B' })], more: 2 }),
|
||||
listsCard({ lists: [listRow({ id: 2, name: 'B2' }), listRow({ id: 3, name: 'C' })], more: 1 }),
|
||||
]);
|
||||
expect(rows.rows.map((row) => row.name)).toEqual(['A', 'B2', 'C']);
|
||||
expect(rows.more).toBe(3);
|
||||
expect([rowsShown('compact'), rowsShown('roomy'), rowsShown(undefined)]).toEqual([5, 8, 5]);
|
||||
expect(avatarPlace(savedPlace({ id: null, imageKey: 'a.jpg' }), -2)).toMatchObject({
|
||||
id: -2,
|
||||
image_url: '/uploads/places/a.jpg',
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,19 +1,66 @@
|
||||
import { Bookmark, BookmarkCheck } from 'lucide-react';
|
||||
|
||||
import type { PackLook } from '../cardTypes';
|
||||
import { appliedListTarget, appliedPlaceOnMap, appliedPlaceTarget } from './collectionCardModel';
|
||||
|
||||
/**
|
||||
* What the collections bring to the chat's pure look: the verbs, tool names and
|
||||
* steps they add, what an applied change of theirs opens, and the look of each
|
||||
* of their kinds. Empty until the collections cards fill it. A look stays pure,
|
||||
* icons and literals only: the chat's main chunk reads every look, so whatever
|
||||
* a look imports ships with it.
|
||||
* What the collections bring to the chat's pure look: the name of each of
|
||||
* their writes, the words their reads run under, where an applied change of
|
||||
* theirs opens (a list, or a saved place selected in it; a copy into the trip
|
||||
* is a trip place and shows on the map), and what a list of saved places
|
||||
* offers to ask next. A look stays pure, icons and literals only: the chat's
|
||||
* main chunk reads every look, so whatever a look imports ships with it.
|
||||
*/
|
||||
export const COLLECTION_LOOK = {
|
||||
verbs: {},
|
||||
tools: {},
|
||||
steps: {},
|
||||
entities: {},
|
||||
tools: {
|
||||
create_collection: { labelKey: 'assistant.tool.create_collection' },
|
||||
update_collection: { labelKey: 'assistant.tool.update_collection' },
|
||||
delete_collection: { labelKey: 'assistant.tool.delete_collection' },
|
||||
reorder_collections: { labelKey: 'assistant.tool.reorder_collections' },
|
||||
save_place_to_collection: { labelKey: 'assistant.tool.save_place_to_collection' },
|
||||
save_trip_places_to_collection: { labelKey: 'assistant.tool.save_trip_places_to_collection' },
|
||||
update_collection_place: { labelKey: 'assistant.tool.update_collection_place' },
|
||||
set_collection_place_status: { labelKey: 'assistant.tool.set_collection_place_status' },
|
||||
set_collection_place_status_from_trip: { labelKey: 'assistant.tool.set_collection_place_status_from_trip' },
|
||||
rate_collection_place: { labelKey: 'assistant.tool.rate_collection_place' },
|
||||
delete_collection_place: { labelKey: 'assistant.tool.delete_collection_place' },
|
||||
copy_collection_places_to_trip: { labelKey: 'assistant.tool.copy_collection_places_to_trip' },
|
||||
create_collection_label: { labelKey: 'assistant.tool.create_collection_label' },
|
||||
update_collection_label: { labelKey: 'assistant.tool.update_collection_label' },
|
||||
delete_collection_label: { labelKey: 'assistant.tool.delete_collection_label' },
|
||||
assign_collection_labels: { labelKey: 'assistant.tool.assign_collection_labels' },
|
||||
accept_collection_invite: { labelKey: 'assistant.tool.accept_collection_invite' },
|
||||
decline_collection_invite: { labelKey: 'assistant.tool.decline_collection_invite' },
|
||||
cancel_collection_invite: { labelKey: 'assistant.tool.cancel_collection_invite' },
|
||||
},
|
||||
steps: {
|
||||
get_collection: { stepKey: 'assistant.step.readingList' },
|
||||
get_collection_items: { stepKey: 'assistant.step.readingList' },
|
||||
list_collections: { stepKey: 'assistant.step.lookingAtLists' },
|
||||
available_collection_users: { stepKey: 'assistant.step.lookingAtLists' },
|
||||
find_place_in_collections: { stepKey: 'assistant.step.checkingLists' },
|
||||
},
|
||||
entities: {
|
||||
collection: {
|
||||
Icon: Bookmark,
|
||||
openLabelKey: 'assistant.card.collection.openList',
|
||||
open: appliedListTarget,
|
||||
},
|
||||
collection_place: {
|
||||
Icon: BookmarkCheck,
|
||||
openLabelKey: 'assistant.card.collection.openPlace',
|
||||
onMap: (_applied, card) => appliedPlaceOnMap(card),
|
||||
open: appliedPlaceTarget,
|
||||
},
|
||||
},
|
||||
cards: {
|
||||
collectionPlaces: {},
|
||||
collectionPlaces: {
|
||||
followUps: [
|
||||
{ id: 'collectionToTrip', labelKey: 'assistant.followUp.collectionToTrip', edits: true },
|
||||
{ id: 'collectionDay', labelKey: 'assistant.followUp.collectionDay', edits: true },
|
||||
],
|
||||
},
|
||||
collectionLists: {},
|
||||
},
|
||||
} satisfies PackLook<'collectionPlaces' | 'collectionLists'>;
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
import { type CardView, PENDING_VIEW } from '../cardTypes';
|
||||
import type { CardView } from '../cardTypes';
|
||||
import { CollectionListsBlock, CollectionPlacesBlock } from './CollectionCardBlocks';
|
||||
import { CollectionListFacts, CollectionPlaceFacts, CollectionPlaceLead } from './CollectionChangeSlots';
|
||||
|
||||
/**
|
||||
* How the kinds of the collections draw in the chat; each one draws nothing
|
||||
* until its cards are built. This file only maps each kind to its view: the
|
||||
* components live in sibling files, since a file that exports anything besides
|
||||
* components breaks fast refresh, and lint:warnings holds
|
||||
* react-refresh/only-export-components at zero for a new file.
|
||||
* How the kinds of the collections draw in the chat: saved places under their
|
||||
* list's head beside an answer, and in a change card their photo in front and
|
||||
* what the change does on the faint line; the lists the same way. This file
|
||||
* only maps each kind to its view: the components live in sibling files, since
|
||||
* a file that exports anything besides components breaks fast refresh, and
|
||||
* lint:warnings holds react-refresh/only-export-components at zero for a new
|
||||
* file.
|
||||
*/
|
||||
export const COLLECTION_VIEWS = {
|
||||
collectionPlaces: PENDING_VIEW,
|
||||
collectionLists: PENDING_VIEW,
|
||||
collectionPlaces: { Block: CollectionPlacesBlock, Lead: CollectionPlaceLead, Facts: CollectionPlaceFacts },
|
||||
collectionLists: { Block: CollectionListsBlock, Facts: CollectionListFacts },
|
||||
} satisfies { [K in 'collectionPlaces' | 'collectionLists']: CardView<K> };
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from 'react'
|
||||
import type { CollectionStatus } from '@trek/shared'
|
||||
import type { TranslationFn } from '../../types'
|
||||
import { STATUS_META, nextStatus } from '../../pages/collections/collectionsModel'
|
||||
import { STATUS_META, nextStatus } from './collectionStatus'
|
||||
|
||||
interface StatusBadgeProps {
|
||||
status: CollectionStatus
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { COLLECTION_STATUSES, type CollectionStatus } from '@trek/shared';
|
||||
import { Bookmark, CheckCircle2, Circle, type LucideIcon } from 'lucide-react';
|
||||
|
||||
/**
|
||||
* How a saved place's status looks wherever it shows: its icon, its name and
|
||||
* its colour, on the Collections page, on the phone and in the assistant's
|
||||
* cards alike. Pure presentation data, so a component of any layer reads it.
|
||||
*/
|
||||
|
||||
interface StatusMeta {
|
||||
icon: LucideIcon;
|
||||
/** i18n key for the human label. */
|
||||
labelKey: string;
|
||||
/** CSS colour token for the badge on a light/surface background. */
|
||||
color: string;
|
||||
/** Brighter variant for a pill sitting over a photo cover / the hero scrim. */
|
||||
coverColor: string;
|
||||
}
|
||||
|
||||
export const STATUS_META: Record<CollectionStatus, StatusMeta> = {
|
||||
idea: { icon: Circle, labelKey: 'collections.status.idea', color: 'var(--text-muted)', coverColor: '#e5e7eb' },
|
||||
want: { icon: Bookmark, labelKey: 'collections.status.want', color: 'var(--accent)', coverColor: '#c7d2fe' },
|
||||
visited: {
|
||||
icon: CheckCircle2,
|
||||
labelKey: 'collections.status.visited',
|
||||
color: 'var(--success)',
|
||||
coverColor: '#6ee7b7',
|
||||
},
|
||||
};
|
||||
|
||||
/** Stable order for the filter chips + the one-tap cycle. */
|
||||
export const STATUS_ORDER: CollectionStatus[] = [...COLLECTION_STATUSES];
|
||||
|
||||
/** idea → want → visited → idea */
|
||||
export function nextStatus(status: CollectionStatus): CollectionStatus {
|
||||
const i = STATUS_ORDER.indexOf(status);
|
||||
return STATUS_ORDER[(i + 1) % STATUS_ORDER.length];
|
||||
}
|
||||
Reference in New Issue
Block a user