This commit is contained in:
Timothy Jaeryang Baek committed 2026-11-25 12:45:27 +04:00
1 parent 9cb24a5306
commit fbf99c5762
1 file changed
+71 -15
@@ -1,6 +1,9 @@
<script lang="ts">
import { getContext } from 'svelte';
import { chatId } from '$lib/stores';
import { getContext, tick } from 'svelte';
import { toast } from 'svelte-sonner';
import { chatId, chatTitle } from '$lib/stores';
import { updateChatById } from '$lib/apis/chats';
import { refreshChatList, setChatTitle } from '$lib/stores/chatList';
import type { AppLayoutContext } from '$lib/types';
import { openFolderChat } from './folderChat';
import type { Readable } from 'svelte/store';
@@ -19,6 +22,7 @@
import Plus from '$lib/components/icons/Plus.svelte';
import ChevronRight from '$lib/components/icons/ChevronRight.svelte';
import FolderTags from './FolderTags.svelte';
import FolderChatMenu from './FolderChatMenu.svelte';
import FolderChatLink from './FolderChatLink.svelte';
import Icon from '$lib/components/chat/FileNav/Icon.svelte';
import FolderStatusControl from './FolderStatus.svelte';
@@ -66,6 +70,35 @@
let over = '';
let collapsed: Record<string, boolean> = {};
// Inline rename, like the list rows.
let renaming = '';
let renameValue = '';
let renameInput: HTMLInputElement;
async function startRename(chat: WorkspaceChat) {
renaming = chat.id;
renameValue = chat.title;
await tick();
renameInput?.focus();
renameInput?.select();
}
async function saveRename(chat: WorkspaceChat) {
if (renaming !== chat.id) return;
const title = renameValue.trim();
renaming = '';
if (!title || title === chat.title) return;
try {
await updateChatById(localStorage.token, chat.id, { title });
setChatTitle(chat.id, title);
if (chat.id === $chatId) chatTitle.set(title);
await Promise.all([
refreshChatList(localStorage.token, { refreshPinned: true }),
onTagsChange()
]);
} catch (error) {
toast.error(`${error}`);
}
}
const cellKey = (column: string, row: string | null) => `${column}\u0000${row ?? ''}`;
const valueOf = (chat: WorkspaceChat, field: Field): string =>
field === 'status' ? statusKey(chat.status) : priorityKey(chat.priority);
@@ -168,7 +201,7 @@
chat.id || dragged?.id === chat.id
? 'opacity-40'
: ''}"
draggable={draggableBoard && $canEdit?.(chat) && !saving && !loading}
draggable={draggableBoard && $canEdit?.(chat) && !saving && !loading && renaming !== chat.id}
on:click={(event) => open(event, chat)}
on:dragstart={(event) => {
dragged = chat;
@@ -215,16 +248,31 @@
{/if}
</span>
{/if}
<FolderChatLink
chatId={chat.id}
title={chat.title}
side="right"
disabled={!!dragged}
className="min-w-0 flex-1 line-clamp-2 text-[0.8125rem] leading-5 outline-none focus-visible:underline {unread
? 'text-base-900 dark:text-base-0'
: 'text-base-700 dark:text-base-200'}"
onclick={(event) => openFolderChat(chat, appLayout, event)}
/>
{#if renaming === chat.id}
<input
bind:this={renameInput}
class="min-w-0 flex-1 bg-transparent text-[0.8125rem] leading-5 text-base-900 outline-none dark:text-base-0"
aria-label={$i18n.t('Rename')}
bind:value={renameValue}
on:blur={() => saveRename(chat)}
on:keydown={(event) => {
if (event.isComposing || event.keyCode === 229) return;
if (event.key === 'Enter') void saveRename(chat);
else if (event.key === 'Escape') renaming = '';
}}
/>
{:else}
<FolderChatLink
chatId={chat.id}
title={chat.title}
side="right"
disabled={!!dragged}
className="min-w-0 flex-1 line-clamp-2 text-[0.8125rem] leading-5 outline-none focus-visible:underline {unread
? 'text-base-900 dark:text-base-0'
: 'text-base-700 dark:text-base-200'}"
onclick={(event) => openFolderChat(chat, appLayout, event)}
/>
{/if}
{#if chat.automation_id}
<span
class="mt-1 flex shrink-0 text-base-400 dark:text-base-500"
@@ -245,7 +293,7 @@
{/if}
<!-- Lines up with the title, past the status and priority icons. -->
<div class="mt-2 flex min-h-5 items-center gap-2 {showPriority ? 'pl-11.5' : 'pl-6'}">
<div class="relative mt-2 flex min-h-5 items-center gap-2 {showPriority ? 'pl-11.5' : 'pl-6'}">
<div class="flex min-w-0 flex-1">
<FolderTags {chat} onChange={onTagsChange} />
</div>
@@ -260,11 +308,19 @@
content={formatDateDetails(chat.updated_at, $i18n.language)}
>
<time
class="shrink-0 text-[0.6875rem] tabular-nums text-base-400 dark:text-base-500"
class="w-14 text-right text-[0.6875rem] tabular-nums text-base-400 dark:text-base-500"
datetime={new Date(chat.updated_at * 1000).toISOString()}
>{formatShortDate(chat.updated_at, $i18n.language)}</time
>
</Tooltip>
{#if $canEdit?.(chat)}
<!-- Covers the date on hover, focus, or while open; touch always shows the menu. -->
<div
class="absolute inset-y-0 right-0 flex w-14 items-center justify-end bg-base-0 group-hover:opacity-100 group-focus-within:opacity-100 has-[[aria-expanded=true]]:opacity-100 dark:bg-base-900 [@media(hover:hover)]:opacity-0"
>
<FolderChatMenu {chat} onRename={() => startRename(chat)} onChange={onTagsChange} />
</div>
{/if}
</div>
</article>
{/snippet}