mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 13:10:29 +00:00
feat(mobile): the assistant is an entry of the dock, sorted like the pages
The home assistant sat behind the More button on every page outside a trip, so a dock with free slots showed "..." for a single entry. It is now an entry of the dock list while its addon is on and it can run for the user: an account that never sorted its dock gets it in a slot the addons leave free, and Settings > Appearance > Mobile can move it between the bar and More like any page.
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
// FE-W4NAVH-001 to FE-W4NAVH-005
|
||||
// FE-W4NAVH-001 to FE-W4NAVH-008
|
||||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import { CalendarDays, Globe, LayoutGrid } from 'lucide-react'
|
||||
import { CalendarDays, Globe, LayoutGrid, Sparkles } from 'lucide-react'
|
||||
import { renderHook } from '@testing-library/react'
|
||||
import { TranslationProvider } from '../../i18n/TranslationContext'
|
||||
import { useAddonStore } from '../../store/addonStore'
|
||||
import { usePluginStore } from '../../store/pluginStore'
|
||||
import { useNavItems } from './navItems'
|
||||
import { useAssistantStore } from '../../store/assistantStore'
|
||||
import type { AiStatusResponse } from '@trek/shared'
|
||||
import { useDockNavItems, useNavItems } from './navItems'
|
||||
|
||||
function wrapper({ children }: { children: React.ReactNode }) {
|
||||
return <TranslationProvider>{children}</TranslationProvider>
|
||||
@@ -16,6 +18,7 @@ const render = () => renderHook(() => useNavItems(), { wrapper })
|
||||
beforeEach(() => {
|
||||
useAddonStore.setState({ addons: [] })
|
||||
usePluginStore.setState({ plugins: [] })
|
||||
useAssistantStore.setState({ status: null })
|
||||
})
|
||||
|
||||
describe('useNavItems', () => {
|
||||
@@ -77,3 +80,33 @@ describe('useNavItems', () => {
|
||||
expect(result.current).toBe(first)
|
||||
})
|
||||
})
|
||||
|
||||
describe('useDockNavItems', () => {
|
||||
const renderDock = () => renderHook(() => useDockNavItems(), { wrapper })
|
||||
const assistantAddon = (enabled: boolean) =>
|
||||
useAddonStore.setState({ addons: [{ id: 'ai_assistant', name: 'AI assistant', icon: 'Sparkles', type: 'integration', enabled }] as never })
|
||||
|
||||
it('FE-W4NAVH-006: adds the assistant after the pages while its addon is on and it can run', () => {
|
||||
assistantAddon(true)
|
||||
useAssistantStore.setState({ status: { available: true } as AiStatusResponse })
|
||||
|
||||
const { result } = renderDock()
|
||||
|
||||
expect(result.current.map(i => i.id)).toEqual(['dashboard', 'assistant'])
|
||||
expect(result.current[1]).toMatchObject({ to: '', label: 'Assistant', icon: Sparkles })
|
||||
})
|
||||
|
||||
it('FE-W4NAVH-007: leaves it out while the addon is off', () => {
|
||||
assistantAddon(false)
|
||||
useAssistantStore.setState({ status: { available: true } as AiStatusResponse })
|
||||
|
||||
expect(renderDock().result.current.map(i => i.id)).toEqual(['dashboard'])
|
||||
})
|
||||
|
||||
it('FE-W4NAVH-008: leaves it out while it cannot run for this user', () => {
|
||||
assistantAddon(true)
|
||||
useAssistantStore.setState({ status: { available: false } as AiStatusResponse })
|
||||
|
||||
expect(renderDock().result.current.map(i => i.id)).toEqual(['dashboard'])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { useMemo } from 'react'
|
||||
import { LayoutGrid, CalendarDays, Globe, Compass, Bookmark, type LucideIcon } from 'lucide-react'
|
||||
import { LayoutGrid, CalendarDays, Globe, Compass, Bookmark, Sparkles, type LucideIcon } from 'lucide-react'
|
||||
import { useTranslation } from '../../i18n'
|
||||
import { useAddonStore } from '../../store/addonStore'
|
||||
import { useAssistantStore } from '../../store/assistantStore'
|
||||
import { usePluginStore } from '../../store/pluginStore'
|
||||
import { resolvePluginIcon } from '../shared/PluginIcon'
|
||||
|
||||
@@ -12,16 +13,21 @@ import { resolvePluginIcon } from '../shared/PluginIcon'
|
||||
*
|
||||
* Stable ids used for persistence: `'dashboard'` (pinned), an enabled global
|
||||
* addon's id (vacay|atlas|journey|collections|future), or `'plugin:<id>'` for a
|
||||
* page plugin. Dashboard is always first and immovable.
|
||||
* page plugin. Dashboard is always first and immovable. The mobile dock adds
|
||||
* `'assistant'` (see useDockNavItems).
|
||||
*/
|
||||
export interface NavItemDef {
|
||||
id: string
|
||||
/** The page it opens; empty for the assistant, which opens the home chat instead. */
|
||||
to: string
|
||||
label: string
|
||||
icon: LucideIcon
|
||||
pinned?: boolean
|
||||
}
|
||||
|
||||
/** The home assistant's entry in the mobile dock: a chat it opens, not a page. */
|
||||
export const ASSISTANT_NAV_ID = 'assistant'
|
||||
|
||||
// Signature glyphs for the four catalog global addons, keyed by id so the known
|
||||
// nav items keep their icon regardless of the (string) icon the addon row ships;
|
||||
// any future/unknown global addon resolves through its manifest icon name.
|
||||
@@ -33,7 +39,7 @@ const ADDON_ICONS: Record<string, LucideIcon> = {
|
||||
}
|
||||
|
||||
/** The bar holds Dashboard + at most this many custom items; the rest go to More.
|
||||
* Two keeps the dock at 3 destinations (Dashboard + 2) so the More slot still fits. */
|
||||
* Two keeps the dock at 3 entries (Dashboard + 2) so the More slot still fits. */
|
||||
export const MOBILE_NAV_MAX_BAR = 2
|
||||
/**
|
||||
* The built-in dock next to Dashboard for an un-customised account, in priority
|
||||
@@ -44,9 +50,11 @@ export const MOBILE_NAV_MAX_BAR = 2
|
||||
* to every day, not the map of countries it already visited. Journey ships
|
||||
* disabled though, so an instance that never turned it on keeps the Vacay/Atlas
|
||||
* dock it has today. Listing all four known global addons rather than just the
|
||||
* top two also keeps the dock filled when one of them is switched off.
|
||||
* top two also keeps the dock filled when one of them is switched off. The
|
||||
* assistant comes last: it takes a slot only one of the addons left free, rather
|
||||
* than sitting alone behind the More button.
|
||||
*/
|
||||
export const DEFAULT_DOCK_IDS = ['vacay', 'journey', 'atlas', 'collections']
|
||||
export const DEFAULT_DOCK_IDS = ['vacay', 'journey', 'atlas', 'collections', ASSISTANT_NAV_ID]
|
||||
|
||||
export function buildNavItems(
|
||||
globalAddons: { id: string; name: string; icon: string }[],
|
||||
@@ -90,6 +98,26 @@ export function useNavItems(): NavItemDef[] {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* The entries the mobile dock arranges: the nav items, and the home assistant
|
||||
* while its addon is on and it can run for this user. The settings customizer
|
||||
* sorts the same list, so the assistant can go into the bar or under More.
|
||||
*/
|
||||
export function useDockNavItems(): NavItemDef[] {
|
||||
const { t } = useTranslation()
|
||||
const items = useNavItems()
|
||||
const addonOn = useAddonStore((s) => s.isEnabled('ai_assistant'))
|
||||
const available = useAssistantStore((s) => s.status?.available === true)
|
||||
const withAssistant = addonOn && available
|
||||
return useMemo(
|
||||
() =>
|
||||
withAssistant
|
||||
? [...items, { id: ASSISTANT_NAV_ID, to: '', label: t('assistant.launcher.tooltip'), icon: Sparkles }]
|
||||
: items,
|
||||
[items, withAssistant, t],
|
||||
)
|
||||
}
|
||||
|
||||
export interface MobileNavSplit {
|
||||
/** Items shown directly in the dock, Dashboard first. */
|
||||
bar: NavItemDef[]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useNavItems, splitMobileNav, MOBILE_NAV_MAX_BAR, type NavItemDef } from '../Layout/navItems'
|
||||
import { useDockNavItems, splitMobileNav, MOBILE_NAV_MAX_BAR, type NavItemDef } from '../Layout/navItems'
|
||||
|
||||
export interface MobileNavValue {
|
||||
bar: string[]
|
||||
@@ -36,7 +36,7 @@ export function useMobileNavEditor(
|
||||
value: MobileNavValue,
|
||||
onChange: (next: MobileNavValue) => void,
|
||||
): MobileNavEditor {
|
||||
const items = useNavItems()
|
||||
const items = useDockNavItems()
|
||||
const split = splitMobileNav(items, value)
|
||||
const dashboard = split.bar.find((i) => i.id === 'dashboard')
|
||||
const barItems = split.bar.filter((i) => i.id !== 'dashboard')
|
||||
|
||||
Reference in New Issue
Block a user