12 } from '@lucide/svelte';
13 import { DropdownMenuActions } from '$lib/components/app';
14 import * as Tooltip from '$lib/components/ui/tooltip';
15 import { FORK_TREE_DEPTH_PADDING } from '$lib/constants';
16 import { RouterService } from '$lib/services/router.service';
17 import { getAllLoadingChats } from '$lib/stores/chat.svelte';
18 import { conversationsStore } from '$lib/stores/conversations.svelte';
19 import { TruncatedText } from '$lib/components/app';
20 import { onMount } from 'svelte';
25 conversation: DatabaseConversation;
26 onDelete?: (id: string) => void;
27 onEdit?: (id: string) => void;
28 onSelect?: (id: string) => void;
29 onStop?: (id: string) => void;
42 let dropdownOpen = $state(false);
44 let isLoading = $derived(getAllLoadingChats().includes(conversation.id));
46 function handleEdit(event: Event) {
47 event.stopPropagation();
48 onEdit?.(conversation.id);
51 function handleDelete(event: Event) {
52 event.stopPropagation();
53 onDelete?.(conversation.id);
56 function handleStop(event: Event) {
57 event.stopPropagation();
58 onStop?.(conversation.id);
61 function handleTogglePin() {
62 conversationsStore.toggleConversationPin(conversation.id);
65 function handleGlobalEditEvent(event: Event) {
66 const customEvent = event as CustomEvent<{ conversationId: string }>;
68 if (customEvent.detail.conversationId === conversation.id && isActive) {
73 function handleSelect() {
74 onSelect?.(conversation.id);
78 document.addEventListener('edit-active-conversation', handleGlobalEditEvent as EventListener);
81 document.removeEventListener(
82 'edit-active-conversation',
83 handleGlobalEditEvent as EventListener
90 class="conversation-item group relative flex min-h-9 w-full items-center justify-between space-x-3 rounded-lg py-1.5 transition-colors hover:bg-foreground/10 {isActive
91 ? 'bg-foreground/5 text-accent-foreground'
95 class="absolute inset-0 z-0 cursor-pointer rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-ring"
96 onclick={handleSelect}
97 aria-label={conversation.name}
101 class="pointer-events-none relative z-10 flex min-w-0 flex-1 items-center gap-2"
102 style:padding-left="{depth * FORK_TREE_DEPTH_PADDING}px"
107 <!-- prevent another nested button element -->
108 {#snippet child({ props })}
111 href={RouterService.chat(conversation.forkedFromConversationId)}
112 class="pointer-events-auto flex shrink-0 items-center text-muted-foreground transition-colors hover:text-foreground"
114 <GitBranch class="h-3.5 w-3.5" />
120 <p>See parent conversation</p>
129 class="stop-button pointer-events-auto flex h-4 w-4 shrink-0 cursor-pointer items-center justify-center rounded text-muted-foreground transition-colors hover:text-foreground"
131 aria-label="Stop generation"
133 <Loader2 class="loading-icon h-3.5 w-3.5 animate-spin" />
135 <Square class="stop-icon hidden h-3 w-3 fill-current text-destructive" />
140 <p>Stop generation</p>
145 <TruncatedText text={conversation.name} class="text-sm font-medium" showTooltip={false} />
148 <div class="actions pointer-events-auto relative z-20 flex items-center">
150 triggerIcon={MoreHorizontal}
151 triggerTooltip="More actions"
152 bind:open={dropdownOpen}
155 icon: conversation.pinned ? PinOff : Pin,
156 label: conversation.pinned ? 'Unpin' : 'Pin',
157 onclick: (e: Event) => {
166 shortcut: ['shift', 'cmd', 'e']
171 onclick: (e: Event) => {
173 conversationsStore.downloadConversation(conversation.id);
175 shortcut: ['shift', 'cmd', 's']
180 onclick: handleDelete,
181 variant: 'destructive',
182 shortcut: ['shift', 'cmd', 'd'],
192 :global([data-slot='dropdown-menu-trigger']:not([data-state='open'])) {
196 &:is(:hover) :global([data-slot='dropdown-menu-trigger']),
197 &:focus-within :global([data-slot='dropdown-menu-trigger']) {
200 @media (max-width: 768px) {
201 :global([data-slot='dropdown-menu-trigger']) {
202 opacity: 1 !important;
207 :global(.stop-icon) {
211 :global(.loading-icon) {
216 &:is(:hover) .stop-button,
217 &:focus-within .stop-button {
218 :global(.stop-icon) {
222 :global(.loading-icon) {