Files
archie/ui/src/chat/ChatSessionList.vue
T

71 lines
2.4 KiB
Vue

<script setup lang="ts">
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { Check, History, SquarePen, X } from "@lucide/vue";
import { onMounted, ref } from "vue";
import { Button } from "@/components/ui/button";
import { sessionTitle } from "./session";
import { currentSession, newChat, selectSession, sessions } from "./state";
/**
* The conversation drawer the bar's menu button opens over the panel: a new
* conversation first, then every conversation to switch to. It covers the
* panel rather than dropping down, so long titles get the panel's width.
*/
const emit = defineEmits<{ close: [] }>();
// Focus moves into the drawer, so Escape and Tab act on it straight away. The
// drawer itself takes it, not its first button, whose tooltip would open.
const nav = ref<HTMLElement | null>(null);
onMounted(() => nav.value?.focus());
function choose(id: string): void {
selectSession(id);
emit("close");
}
function start(): void {
newChat();
emit("close");
}
</script>
<template>
<nav
ref="nav"
tabindex="-1"
aria-label="Conversations"
class="outline-none absolute inset-0 z-20 flex flex-col gap-0.5 overflow-y-auto rounded-[inherit] bg-popover p-2"
@pointerdown.stop
@dblclick.stop
@keydown.esc.stop.prevent="emit('close')"
>
<Tooltip>
<TooltipTrigger as-child>
<Button variant="ghost" size="icon-sm" class="mb-1" aria-label="Close conversations" @click="emit('close')">
<X />
</Button>
</TooltipTrigger>
<TooltipContent>Close</TooltipContent>
</Tooltip>
<Button variant="ghost" size="sm" class="justify-start" @click="start">
<SquarePen data-icon="inline-start" />New chat
</Button>
<div class="mt-2 flex items-center gap-2 px-2 py-1 text-caption text-fg-muted">
<History class="size-3.5" aria-hidden="true" />Chats
</div>
<Button
v-for="session in sessions"
:key="session.session_id"
variant="ghost"
size="sm"
class="justify-start pl-7 font-normal"
:aria-current="session.session_id === currentSession ? 'true' : undefined"
@click="choose(session.session_id)"
>
<span class="min-w-0 flex-1 truncate text-left">{{ sessionTitle(session) }}</span>
<Check v-if="session.session_id === currentSession" class="flex-none" aria-hidden="true" />
</Button>
</nav>
</template>