mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 05:21:15 +00:00
feat(assistant): the assistant opens outside a trip, as a home chat about all trips
A third scope, home, next to trip and journey: threads that name neither a trip nor a journey (the CHECK now only forbids both), reached under /api/assistant by their owner only. A home turn reads the user's trips through list_trips into a short card (under way, next, later, behind, undated), offers every read (a trip's on the id the model names, checked by the tool with the user's rights) and only the writes that take no trip or journey (atlas, vacation planner, collections, tour library, settings), all held as change cards. open_trip_chat answers with a card that goes on in that trip's own chat with the question waiting in its composer. On the desktop the window opens on the home chat outside a trip; its head lists the trips to switch into and a switched trip chat has the way back. On the phone the home chat opens full screen from the dashboard head and the dock's More list, and the card opens the trip with its chat. Both run on useAssistantHome.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// FE-COMP-MBOTTOMNAV-001 to FE-COMP-MBOTTOMNAV-007
|
||||
// FE-COMP-MBOTTOMNAV-001 to FE-COMP-MBOTTOMNAV-008
|
||||
|
||||
vi.mock('../../api/websocket', () => ({
|
||||
connect: vi.fn(),
|
||||
@@ -22,6 +22,8 @@ import { useAuthStore } from '../../store/authStore';
|
||||
import { useAddonStore } from '../../store/addonStore';
|
||||
import { resetAllStores, seedStore } from '../../../tests/helpers/store';
|
||||
import { buildUser } from '../../../tests/helpers/factories';
|
||||
import { useAssistantStore } from '../../store/assistantStore';
|
||||
import type { AiStatusResponse } from '@trek/shared';
|
||||
import MBottomNav from './MBottomNav';
|
||||
|
||||
const currentUser = buildUser({ id: 1, username: 'testuser', email: 'test@example.com' });
|
||||
@@ -97,4 +99,15 @@ describe('MBottomNav', () => {
|
||||
render(<MBottomNav />, { initialEntries: ['/vacay'] });
|
||||
expect(screen.queryByRole('button', { name: 'New Trip' })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-COMP-MBOTTOMNAV-008: the More list leads with the assistant while it can run, and opens the home chat', async () => {
|
||||
const user = userEvent.setup();
|
||||
useAssistantStore.setState({ status: { available: true } as AiStatusResponse, window: { open: false, minimized: false } });
|
||||
render(<MBottomNav />, { initialEntries: ['/atlas'] });
|
||||
await user.click(screen.getByRole('button', { name: 'More' }));
|
||||
await user.click(screen.getByRole('button', { name: 'Assistant' }));
|
||||
expect(useAssistantStore.getState().window).toEqual({ open: true, minimized: false });
|
||||
expect(mockNavigate).not.toHaveBeenCalled();
|
||||
useAssistantStore.setState({ status: null, window: { open: false, minimized: false } });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,12 +2,13 @@ import { useEffect, useState } from 'react'
|
||||
import { useNavigate, useLocation } from 'react-router'
|
||||
import { useSettingsStore } from '../../store/settingsStore'
|
||||
import { useTranslation } from '../../i18n'
|
||||
import { ChevronRight, MoreHorizontal, Plus, Search, Upload } from 'lucide-react'
|
||||
import { ChevronRight, MoreHorizontal, Plus, Search, Sparkles, Upload } from 'lucide-react'
|
||||
import type { LucideIcon } from 'lucide-react'
|
||||
import { normalizeAppearance } from '@trek/shared'
|
||||
import { useNavItems, splitMobileNav } from '../../components/Layout/navItems'
|
||||
import { isNavItemActive, useCreateAction } from '../../components/Layout/useCreateAction'
|
||||
import MFab from './MFab'
|
||||
import { useAssistantHomeLauncher } from '../../components/Assistant/useAssistantHome'
|
||||
|
||||
interface NavItem { to: string; label: string; icon: LucideIcon }
|
||||
|
||||
@@ -26,6 +27,8 @@ export default function MBottomNav() {
|
||||
// the dock yields the slot instead (see screenFabSlot below, #1811).
|
||||
const create = useCreateAction(true)
|
||||
const [moreOpen, setMoreOpen] = useState(false)
|
||||
// The home chat leads the More list on every page outside a trip, as the assistant tile leads a trip's.
|
||||
const assistant = useAssistantHomeLauncher()
|
||||
|
||||
// Close the popover when the route changes underneath it (browser back etc.).
|
||||
useEffect(() => setMoreOpen(false), [location.pathname])
|
||||
@@ -42,6 +45,11 @@ export default function MBottomNav() {
|
||||
|
||||
const isActive = (to: string) => isNavItemActive(location.pathname, to)
|
||||
const moreActive = moreItems.some(item => isActive(item.to))
|
||||
const moreRows = [
|
||||
...(assistant.available ? [{ key: 'assistant', label: t('assistant.launcher.tooltip'), icon: Sparkles, go: assistant.open }] : []),
|
||||
...moreItems.map(({ to, label, icon }) => ({ key: to, label, icon, go: () => navigate(to) })),
|
||||
]
|
||||
const hasMore = moreRows.length > 0
|
||||
|
||||
// The FAB gives way to a decorative logo slot on screens without an add
|
||||
// action (settings/admin, demo Z. 1372/1429).
|
||||
@@ -55,7 +63,7 @@ export default function MBottomNav() {
|
||||
|
||||
// Split so the raised centre slot sits dead centre; the More slot always
|
||||
// closes the right group.
|
||||
const slotCount = dockItems.length + (moreItems.length > 0 ? 1 : 0)
|
||||
const slotCount = dockItems.length + (hasMore ? 1 : 0)
|
||||
const splitAt = Math.ceil(slotCount / 2)
|
||||
const left = dockItems.slice(0, splitAt)
|
||||
const right = dockItems.slice(splitAt)
|
||||
@@ -94,11 +102,11 @@ export default function MBottomNav() {
|
||||
role="presentation"
|
||||
onClick={e => e.stopPropagation()}
|
||||
>
|
||||
{moreItems.map(({ to, label, icon: Icon }) => (
|
||||
{moreRows.map(({ key, label, icon: Icon, go }) => (
|
||||
<button
|
||||
key={to}
|
||||
key={key}
|
||||
type="button"
|
||||
onClick={() => { setMoreOpen(false); navigate(to) }}
|
||||
onClick={() => { setMoreOpen(false); go() }}
|
||||
className="flex items-center gap-[13px] rounded-[18px] bg-[color:var(--m-ic)] px-4 py-[14px] text-start"
|
||||
>
|
||||
<span className="flex h-10 w-10 flex-none items-center justify-center rounded-xl bg-[color:var(--m-ic)] text-m-ink">
|
||||
@@ -136,7 +144,7 @@ export default function MBottomNav() {
|
||||
|
||||
<div className="flex min-w-0 flex-1 items-center justify-around">
|
||||
{right.map(renderItem)}
|
||||
{moreItems.length > 0 && (
|
||||
{hasMore && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setMoreOpen(v => !v)}
|
||||
|
||||
Reference in New Issue
Block a user