feat(ui): dock the chat at the bottom of every page and keep a skeleton while a conversation loads

This commit is contained in:
sam committed 2026-10-19 03:01:12 +11:00
1 parent 0eecc95aac
commit 61ee5fd3a7
16 files changed
+222 -317

No files matched your search

+3 -3
View File
@@ -5,7 +5,7 @@ import { useRoute } from "vue-router";
import AccountEntry from "@/accounts/AccountEntry.vue";
import { useAccountsStore } from "@/accounts/accounts";
import ChatLauncher from "@/chat/ChatLauncher.vue";
import ChatDock from "@/chat/ChatDock.vue";
import Topbar from "@/components/topbar/Topbar.vue";
import SettingsShell from "@/settings/SettingsShell.vue";
import { TooltipProvider } from "@/components/ui/tooltip";
@@ -59,7 +59,7 @@ watch(() => accounts.status?.user, (user) => {
<a href="#main-content" class="sr-only focus:not-sr-only focus:fixed focus:top-2 focus:left-4 focus:z-[60] focus:rounded-md focus:bg-card focus:px-3 focus:py-2">Skip to main content</a>
<Topbar :hidden="hidden" />
<main id="main-content" ref="main" tabindex="-1" class="scroll-mt-16 w-full flex-1 px-6 py-5 max-lg:p-4"
:class="workflowsPage ? 'max-md:flex max-md:min-h-0 max-md:flex-col' : 'max-md:pb-24'">
:class="workflowsPage ? 'max-md:flex max-md:min-h-0 max-md:flex-col' : 'pb-24'">
<!--
Keyed on the path and its parameters but not the query: a query-only
change is an entry state, so the page keeps the operator's filters,
@@ -79,6 +79,6 @@ watch(() => accounts.status?.user, (user) => {
</main>
</div>
<ChatLauncher />
<ChatDock />
</TooltipProvider>
</template>
+2 -2
View File
@@ -11,8 +11,7 @@ import { currentSession, newChat } from "./state";
* One row for everything that is not the conversation: which conversation is
* open, and the controls that are consulted rather than used constantly.
*
* There is no close button. The launcher stays visible while the panel is open
* and is the single control that opens and closes it.
* Whatever the dock adds to the row, such as its hide control, comes after.
*/
</script>
@@ -31,5 +30,6 @@ import { currentSession, newChat } from "./state";
</Button>
<ChatSettings />
<ChatSessionActions v-if="currentSession" />
<slot />
</div>
</template>
+92
View File
@@ -0,0 +1,92 @@
<script setup lang="ts">
import { ChevronDown, ChevronUp } from "@lucide/vue";
import { onUnmounted, ref, watch } from "vue";
import { Button } from "@/components/ui/button";
import ChatBar from "./ChatBar.vue";
import ChatComposer from "./ChatComposer.vue";
import ChatTranscript from "./ChatTranscript.vue";
import { composerText, escapeOwnedByLayer, isSending, useChat } from "./state";
/**
* Chat is a bar docked at the bottom of every page, not a route: the operator
* asks Archie about the page they are already on, so navigating must not reset
* it, and it must not replace the work that prompted the question. The agent
* is told which page that is.
*
* It is the composer alone until the operator focuses it or a turn starts, then
* the conversation opens above it. Hiding the conversation leaves the bar. It is
* deliberately not a modal: no scrim, no scroll lock, no focus trap.
*
* It stays mounted, so the session and any turn in flight survive a navigation.
* It is mounted outside the app shell: `.shell`'s backdrop-filter makes it a
* containing block for `position: fixed`, so a bar nested inside would anchor to
* the shell and ride off the bottom of a long page.
*/
useChat();
const expanded = ref(false);
const composer = ref<InstanceType<typeof ChatComposer> | null>(null);
watch(isSending, (sending) => {
if (sending) expanded.value = true;
});
function onKeydown(event: KeyboardEvent): void {
// A focused control (the composer dismissing its palette, or the topbar
// search) already handled Escape via preventDefault; collapsing too would
// make that menu impossible to dismiss on its own. A popover portalled out
// of the bar owns Escape by being open, which the flag reports.
if (event.defaultPrevented || event.key !== "Escape" || escapeOwnedByLayer()) return;
expanded.value = false;
}
watch(expanded, (open) => {
if (open) document.addEventListener("keydown", onKeydown);
else document.removeEventListener("keydown", onKeydown);
});
onUnmounted(() => document.removeEventListener("keydown", onKeydown));
function usePrompt(text: string): void {
composerText.value = text;
composer.value?.focus();
}
</script>
<template>
<div class="pointer-events-none fixed inset-x-0 bottom-4 z-40 flex justify-center px-3 max-md:bottom-2">
<aside
aria-label="Chat with Archie"
class="pointer-events-auto flex w-full max-w-xl flex-col rounded-lg border bg-popover shadow-[var(--shadow-md)]"
>
<ChatBar v-if="expanded">
<Button
variant="ghost"
size="icon-sm"
class="flex-none"
aria-label="Hide conversation"
title="Hide conversation"
@click="expanded = false"
>
<ChevronDown />
</Button>
</ChatBar>
<div v-if="expanded" class="flex h-[min(28rem,55dvh)] min-h-0 flex-col">
<ChatTranscript @prompt="usePrompt" />
</div>
<div class="relative" @focusin="expanded = true">
<ChatComposer ref="composer" :open="false" :class="!expanded && 'border-t-0!'" />
<Button
v-if="!expanded"
variant="ghost"
size="icon-sm"
class="absolute top-1.5 right-1.5"
aria-label="Show conversation"
title="Show conversation"
@click="expanded = true"
>
<ChevronUp />
</Button>
</div>
</aside>
</div>
</template>
-46
View File
@@ -1,46 +0,0 @@
<script setup lang="ts">
import { MessageCircle, X } from "@lucide/vue";
import { cn } from "@/lib/utils";
import { CHAT_PANEL_ID } from "./state";
/**
* The launcher: the one control that opens and closes the panel, which is why
* there is no close button inside it.
*
* Both glyphs are stacked and cross-faded, so the button keeps one size and the
* swap cannot reflow the dock. It stays visible while the panel is open -- and
* on a phone, where the panel becomes a sheet above it, that visibility is the
* only way out.
*/
defineProps<{ open: boolean }>();
const emit = defineEmits<{ toggle: [] }>();
// Stacked in one cell, so switching glyphs changes opacity and rotation rather
// than layout.
function glyph(visible: boolean): string {
return cn(
"col-start-1 row-start-1 grid place-items-center transition-[opacity,transform] duration-[140ms]",
visible ? "opacity-100" : "-rotate-45 scale-[0.7] opacity-0",
);
}
</script>
<template>
<button
type="button"
class="relative z-10 grid size-14 cursor-pointer place-items-center rounded-full border border-border-strong bg-secondary text-primary shadow-[var(--shadow-md)] transition-transform duration-[140ms] hover:-translate-y-px focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary active:translate-y-0"
:aria-label="open ? 'Close chat' : 'Chat with Archie'"
:title="open ? 'Close chat' : 'Chat with Archie'"
:aria-expanded="open"
:aria-controls="CHAT_PANEL_ID"
@click="emit('toggle')"
>
<span aria-hidden="true" :class="glyph(!open)">
<MessageCircle :size="22" />
</span>
<span aria-hidden="true" :class="glyph(open)">
<X :size="22" />
</span>
</button>
</template>
-67
View File
@@ -1,67 +0,0 @@
<script setup lang="ts">
import { onUnmounted, ref, watch } from "vue";
import ChatFab from "./ChatFab.vue";
import ChatPanel from "./ChatPanel.vue";
import { escapeOwnedByLayer } from "./state";
/**
* Chat is a floating launcher and the panel it opens, not a route: the operator
* asks Archie about the page they are already on, so navigating must not close
* it and opening it must not replace the work that prompted the question.
*
* Deliberately not a modal: no scrim, no body scroll lock, no focus trap. The
* page stays readable, scrollable and clickable while the panel is open, which
* is what "ask about this page" requires.
*
* It hosts a single panel instance, so the session and its stream survive
* navigation rather than being rebuilt per page.
*
* This element is mounted outside the app shell: `.shell`'s backdrop-filter
* makes it a containing block for `position: fixed`, so a launcher nested
* inside it would anchor to the shell and ride off the bottom of a long page.
*/
const open = ref(false);
const fab = ref<{ $el: HTMLButtonElement } | null>(null);
function close(): void {
open.value = false;
// Focus goes back to the control that opened the panel; otherwise a keyboard
// user who dismisses it lands at the top of the document.
fab.value?.$el?.focus();
}
function toggle(): void {
if (open.value) close();
else open.value = true;
}
function onKeydown(event: KeyboardEvent): void {
// A focused control (the composer dismissing its palette, or the topbar
// search) already handled Escape via preventDefault; closing the panel too
// would make that menu impossible to dismiss on its own.
if (event.defaultPrevented || event.key !== "Escape") return;
// The same rule for a layer that owns Escape by being open rather than by
// holding focus: a popover portalled out of the panel listens on document
// too, and the panel registered its own handler first, so the flag is what
// keeps the innermost layer's dismissal from taking the panel with it.
if (escapeOwnedByLayer()) return;
close();
}
watch(open, (isOpen) => {
if (isOpen) document.addEventListener("keydown", onKeydown);
else document.removeEventListener("keydown", onKeydown);
});
onUnmounted(() => document.removeEventListener("keydown", onKeydown));
</script>
<template>
<div
class="fixed right-6 bottom-6 z-40 max-md:right-4 max-md:bottom-4"
>
<ChatPanel :open="open" />
<ChatFab ref="fab" :open="open" @toggle="toggle" />
</div>
</template>
-86
View File
@@ -1,86 +0,0 @@
<script setup lang="ts">
import { computed, ref } from "vue";
import ChatBar from "./ChatBar.vue";
import ChatComposer from "./ChatComposer.vue";
import ChatTranscript from "./ChatTranscript.vue";
import { CHAT_PANEL_ID, composerText, useChat } from "./state";
/**
* The panel: the shape that grows out of the launcher, holding the
* conversation. It composes the bar, the transcript and the composer,
* and owns nothing but the morph and the composer's focus.
*
* It stays mounted while closed, so the session and any turn in flight survive
* a navigation. `inert` is what keeps an invisible panel out of the tab order
* and out of the pointer's way.
*/
const props = defineProps<{ open: boolean }>();
useChat();
const composer = ref<InstanceType<typeof ChatComposer> | null>(null);
/**
* The panel's shape.
*
* Closed, it is collapsed to a small round shape sitting exactly over the
* button; open, it is the full panel beside it. Scaling from the bottom-right
* corner and translating by the launcher's own width is what makes the button
* appear to become the panel, rather than a panel merely fading in next to it:
* scale, border-radius and position interpolate together. The contents fade in
* separately, below, once the shape has arrived.
*
* On a phone the sheet rises from the launcher instead of opening beside it, so
* the closed shape travels down toward the button rather than sideways. Those
* two values (56px launcher, 0.75rem gap) are the dock's own geometry; the
* launcher and every offset here are built from them.
*/
const panelShape = computed(() =>
props.open
? "pointer-events-auto rounded-lg opacity-100 [transform:none] [transition:opacity_160ms_cubic-bezier(0.4,0,0.2,1),transform_260ms_cubic-bezier(0.22,1,0.36,1),border-radius_260ms_cubic-bezier(0.22,1,0.36,1)]"
: "pointer-events-none rounded-full opacity-0 [transform:translateX(calc(56px_+_0.75rem))_scale(0.16)] max-md:[transform:translateY(calc(56px_+_0.75rem))_scale(0.16)] [transition:opacity_140ms_cubic-bezier(0.4,0,0.2,1),transform_200ms_cubic-bezier(0.4,0,1,1),border-radius_200ms_cubic-bezier(0.4,0,1,1)]",
);
// The contents follow the shape rather than stretching with it: they fade in
// once the panel is most of the way open, so the morph reads as a container
// opening instead of a page being scaled up.
const contentFade = computed(() =>
props.open
? "opacity-100 transition-opacity duration-[160ms] ease-linear delay-[120ms]"
: "opacity-0 transition-opacity duration-[120ms] ease-linear",
);
function usePrompt(text: string): void {
composerText.value = text;
composer.value?.focus();
}
</script>
<template>
<aside
:id="CHAT_PANEL_ID"
aria-label="Chat with Archie"
:aria-hidden="open ? undefined : 'true'"
class="pointer-events-none absolute bottom-0 right-[calc(56px_+_0.75rem)] h-[min(640px,calc(100vh_-_3rem))] w-[min(440px,calc(100vw_-_56px_-_0.75rem_-_3rem))] max-md:fixed max-md:bottom-[calc(1rem_+_56px_+_0.75rem)] max-md:left-4 max-md:right-4 max-md:h-[min(72vh,calc(100vh_-_2rem_-_56px_-_0.75rem))] max-md:w-auto"
>
<div
:class="
panelShape +
' h-full w-full overflow-hidden border bg-popover shadow-[var(--shadow-md)] origin-bottom-right'
"
:inert="open ? undefined : true"
>
<!-- The conversation takes the rest of the column: without `min-h-0` on
the transcript it sizes to its content instead, and the composer
floats above dead space. -->
<div
:class="contentFade + ' flex h-full min-h-0 flex-col overflow-hidden'"
>
<ChatBar />
<ChatTranscript @prompt="usePrompt" />
<ChatComposer ref="composer" :open="open" />
</div>
</div>
</aside>
</template>
+1 -1
View File
@@ -68,7 +68,7 @@ function clear(value: unknown): string {
</Button>
</PopoverTrigger>
<PopoverContent align="end" class="grid w-64 gap-3">
<span class="text-xs text-fg-subtle">{{ statusText }}</span>
<span v-if="statusText !== 'Ready'" class="text-xs text-fg-subtle">{{ statusText }}</span>
<Field v-if="(selectorData.providers || []).length" class="gap-1">
<FieldLabel class="text-xs text-fg-muted">Provider</FieldLabel>
+9 -1
View File
@@ -15,7 +15,9 @@ import ChatBubble from "./ChatBubble.vue";
import ChatChooseCard from "./ChatChooseCard.vue";
import ChatUpdateCard from "./ChatUpdateCard.vue";
import ChatEmptyState from "./ChatEmptyState.vue";
import { Skeleton } from "@/components/ui/skeleton";
import {
isLoadingSession,
messages,
sendMessage,
streamingTurn,
@@ -56,8 +58,14 @@ const bubbles = computed(() => messages.value.map(parts));
<MessageScroller class="min-h-0 flex-1">
<MessageScrollerViewport>
<MessageScrollerContent class="gap-4 p-4">
<template v-if="isLoadingSession && !bubbles.length">
<Skeleton class="h-14 w-3/5 self-end rounded-xl" />
<Skeleton class="h-24 w-4/5 rounded-xl" />
<Skeleton class="h-10 w-2/5 self-end rounded-xl" />
</template>
<ChatEmptyState
v-if="!bubbles.length && !streamingTurn"
v-else-if="!bubbles.length && !streamingTurn"
@prompt="emit('prompt', $event)"
/>
+10 -6
View File
@@ -135,12 +135,6 @@ export interface ChatSelectorData {
voice_available?: boolean;
}
/**
* The id the launcher points its `aria-controls` at and the panel answers to.
* Both read it here so the pair cannot drift apart.
*/
export const CHAT_PANEL_ID = "chat-panel";
/**
* One `data: {...}` frame of the chat stream. The server always emits `text`,
* empty or not: the browser concatenates it, so a missing key would put the
@@ -172,6 +166,7 @@ export const messages = ref<ChatMessage[]>([]);
export const composerText = ref("");
export const statusText = ref("Ready");
export const isSending = ref(false);
export const isLoadingSession = ref(false);
export const streamingTurn = ref<StreamingTurn | null>(null);
export const selectorData = ref<ChatSelectorData>({});
@@ -253,6 +248,7 @@ export async function selectSession(id: string): Promise<void> {
currentSession.value = id;
messages.value = [];
streamingTurn.value = null;
isLoadingSession.value = true;
try {
@@ -280,9 +276,17 @@ export async function selectSession(id: string): Promise<void> {
} catch (err) {
statusText.value =
(err as Error).message || "Could not load session messages";
} finally {
if (isCurrentSession(id)) isLoadingSession.value = false;
}
}
// A later selection owns the loading flag: a slow read for an earlier one must
// not clear it.
function isCurrentSession(id: string): boolean {
return currentSession.value === id;
}
/** One recorded turn, as GET /api/chat/sessions/{id}/turns returns it. */
interface ChatTurnView {
assistant_message_id?: string;