feat(assistant): a card framework every addon package plugs into

This commit is contained in:
Maurice
2026-10-22 12:14:24 +02:00
parent d2a2728cde
commit 3967ca2790
514 changed files with 9868 additions and 1274 deletions
@@ -1,4 +1,7 @@
import type { AssistantApplied } from '@trek/shared';
import type { AssistantApplied, TrekCard } from '@trek/shared';
import { entityLookOf } from './cards/cardLooks';
import type { EntityTarget } from './cards/cardTypes';
interface ShowOnMapTarget {
/** The place the change made or changed. */
@@ -7,16 +10,23 @@ interface ShowOnMapTarget {
dayId: number | null;
}
/** Where "Show on map" takes an applied change: the place when it is one, else its day; nothing for the rest. */
export function showOnMapTarget(applied: AssistantApplied): ShowOnMapTarget {
const placeId = applied.entity === 'place' ? (applied.ids[0] ?? null) : null;
return { placeId, dayId: placeId === null ? applied.dayId : null };
/**
* Where "Show on map" takes an applied change, as its entity's look says: a
* place shows itself, a stop or a note its day. Null for what has no place on
* the map (a kept note, a to-do), which then shows no map button at all.
*/
export function showOnMapTarget(applied: AssistantApplied, card: TrekCard | null = null): ShowOnMapTarget | null {
return entityLookOf(applied.entity).onMap?.(applied, card) ?? null;
}
/** The planner's query for it: `?place=` opens the place, `?day=` selects the day. */
export function showOnMapSearch(applied: AssistantApplied): string {
const { placeId, dayId } = showOnMapTarget(applied);
if (placeId !== null) return `?place=${placeId}`;
if (dayId !== null) return `?day=${dayId}`;
/**
* The planner's query for a target on the trip: `?place=` opens the place,
* `?day=` selects the day, and a tab goes as `?tab=` with whatever the tab
* reads beside it (`?tab=finanzplan&expense=7`).
*/
export function plannerSearchOf(target: Exclude<EntityTarget, { kind: 'page' }>): string {
if (target.kind === 'tab') return `?${new URLSearchParams({ tab: target.tab, ...target.params }).toString()}`;
if (target.placeId !== null) return `?place=${target.placeId}`;
if (target.dayId !== null) return `?day=${target.dayId}`;
return '';
}