mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-23 07:26:30 +00:00
214984f398
Adds an in-app assistant that reads and plans the open trip. Users connect their own provider (Sign in with ChatGPT, or an Anthropic, OpenAI, Gemini or OpenRouter key) or use the one the admin set up, including a custom OpenAI-compatible server. It is an addon and only shows while a connection is usable. The chat runs on the existing MCP tools, pinned to the trip. Every change is held as a change card the user applies or discards, and applied changes can be undone. On the desktop it is a floating window that can be moved and resized; on the phone it is fullscreen. Search results show as place cards that can go onto a day, weather lookups as a strip, proposed places as ghost markers on the map with a before/after switch, and an answer can be shared into the trip chat. Booking files can be dropped in and are read into change cards.
49 lines
1.8 KiB
TypeScript
49 lines
1.8 KiB
TypeScript
import { type PointerEvent, useCallback, useEffect } from 'react';
|
|
|
|
import { useAssistantStore } from '../../store/assistantStore';
|
|
|
|
/**
|
|
* Ties one change in the card to its pin on the map: resting on the row (or
|
|
* tapping it on a touch screen) lights the pin, and resting on the pin lights
|
|
* the row. Each row reads only whether it is the one lit, so a hover renders
|
|
* the row it enters and the one it leaves, not the whole card.
|
|
*/
|
|
export function useChangeHover(tripId: number, toolCallId: string | null) {
|
|
const hovered = useAssistantStore((s) =>
|
|
toolCallId !== null && s.mapLink?.tripId === tripId && s.mapLink.hoveredId === toolCallId
|
|
? s.mapLink.source
|
|
: null
|
|
);
|
|
const setMapHover = useAssistantStore((s) => s.setMapHover);
|
|
|
|
const enter = useCallback(() => {
|
|
if (toolCallId !== null) setMapHover(tripId, toolCallId, 'card');
|
|
}, [setMapHover, tripId, toolCallId]);
|
|
|
|
const leave = useCallback(() => {
|
|
const link = useAssistantStore.getState().mapLink;
|
|
// Only the row that lit the pin puts it out; the pointer may already rest on another.
|
|
if (toolCallId !== null && link?.tripId === tripId && link.hoveredId === toolCallId) {
|
|
setMapHover(tripId, null, 'card');
|
|
}
|
|
}, [setMapHover, tripId, toolCallId]);
|
|
|
|
// A row that goes (the change was decided, the chat closed) takes its light with it.
|
|
useEffect(() => leave, [leave]);
|
|
|
|
const onPointerDown = useCallback(
|
|
(e: PointerEvent) => {
|
|
if (e.pointerType === 'touch') enter();
|
|
},
|
|
[enter]
|
|
);
|
|
|
|
return {
|
|
/** Lit from anywhere: the card, the map, a found place. */
|
|
lit: hovered !== null,
|
|
/** Lit from its pin on the map, where the card shows it itself. */
|
|
litFromMap: hovered === 'map',
|
|
handlers: { onMouseEnter: enter, onMouseLeave: leave, onFocus: enter, onBlur: leave, onPointerDown },
|
|
};
|
|
}
|