feat: 对话列表支持分页、收藏、置顶
收藏(is_favorite)/置顶(is_pinned)作为布尔标记存入对话已有 metadata,
复用现有 PATCH /api/threads/{id} 与 search 往返,无需后端改动与迁移。
- hooks: 新增 useUpdateThreadMetadata + useToggleThreadPin/Favorite
- utils: 新增 isThreadPinned/isThreadFavorite/sortThreadsPinnedFirst
- 侧边栏: 置顶优先排序 + 下拉菜单收藏/置顶项 + 置顶图标
- 对话页: 置顶区 + 全部/收藏过滤 + 页码翻页(每页20) + 行内收藏/置顶按钮
- i18n: zh-CN/en-US/types 新增相关文案
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
80d2db6315
commit
50d70a5050
7 files changed
+489
-139
No files matched your search
@@ -7,7 +7,10 @@ import {
|
|||||||
FileText,
|
FileText,
|
||||||
MoreHorizontal,
|
MoreHorizontal,
|
||||||
Pencil,
|
Pencil,
|
||||||
|
Pin,
|
||||||
|
PinOff,
|
||||||
Share2,
|
Share2,
|
||||||
|
Star,
|
||||||
Trash2,
|
Trash2,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
@@ -54,9 +57,17 @@ import {
|
|||||||
useDeleteThread,
|
useDeleteThread,
|
||||||
useRenameThread,
|
useRenameThread,
|
||||||
useThreads,
|
useThreads,
|
||||||
|
useToggleThreadFavorite,
|
||||||
|
useToggleThreadPin,
|
||||||
} from "@/core/threads/hooks";
|
} from "@/core/threads/hooks";
|
||||||
import type { AgentThread, AgentThreadState } from "@/core/threads/types";
|
import type { AgentThread, AgentThreadState } from "@/core/threads/types";
|
||||||
import { pathOfThread, titleOfThread } from "@/core/threads/utils";
|
import {
|
||||||
|
isThreadFavorite,
|
||||||
|
isThreadPinned,
|
||||||
|
pathOfThread,
|
||||||
|
sortThreadsPinnedFirst,
|
||||||
|
titleOfThread,
|
||||||
|
} from "@/core/threads/utils";
|
||||||
import { env } from "@/env";
|
import { env } from "@/env";
|
||||||
import { desensitize } from "@/lib/desensitize";
|
import { desensitize } from "@/lib/desensitize";
|
||||||
import { isIMEComposing } from "@/lib/ime";
|
import { isIMEComposing } from "@/lib/ime";
|
||||||
@@ -82,6 +93,8 @@ export function RecentChatList() {
|
|||||||
const { data: threads = [] } = useThreads();
|
const { data: threads = [] } = useThreads();
|
||||||
const { mutate: deleteThread } = useDeleteThread();
|
const { mutate: deleteThread } = useDeleteThread();
|
||||||
const { mutate: renameThread } = useRenameThread();
|
const { mutate: renameThread } = useRenameThread();
|
||||||
|
const { toggle: togglePin } = useToggleThreadPin();
|
||||||
|
const { toggle: toggleFavorite } = useToggleThreadFavorite();
|
||||||
|
|
||||||
// Rename dialog state
|
// Rename dialog state
|
||||||
const [renameDialogOpen, setRenameDialogOpen] = useState(false);
|
const [renameDialogOpen, setRenameDialogOpen] = useState(false);
|
||||||
@@ -160,11 +173,13 @@ export function RecentChatList() {
|
|||||||
[t],
|
[t],
|
||||||
);
|
);
|
||||||
|
|
||||||
const visibleThreads = threads.filter(
|
const visibleThreads = sortThreadsPinnedFirst(
|
||||||
(thread) =>
|
threads.filter(
|
||||||
thread.metadata?.thread_type !== "scheduler" &&
|
(thread) =>
|
||||||
thread.metadata?.thread_type !== "bootstrap" &&
|
thread.metadata?.thread_type !== "scheduler" &&
|
||||||
thread.metadata?.thread_type !== "roundtable",
|
thread.metadata?.thread_type !== "bootstrap" &&
|
||||||
|
thread.metadata?.thread_type !== "roundtable",
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (visibleThreads.length === 0) {
|
if (visibleThreads.length === 0) {
|
||||||
@@ -195,6 +210,8 @@ export function RecentChatList() {
|
|||||||
<div className="flex w-full flex-col gap-0.5">
|
<div className="flex w-full flex-col gap-0.5">
|
||||||
{visibleThreads.map((thread) => {
|
{visibleThreads.map((thread) => {
|
||||||
const isActive = pathOfThread(thread) === pathname;
|
const isActive = pathOfThread(thread) === pathname;
|
||||||
|
const pinned = isThreadPinned(thread);
|
||||||
|
const favorited = isThreadFavorite(thread);
|
||||||
return (
|
return (
|
||||||
<SidebarMenuItem
|
<SidebarMenuItem
|
||||||
key={thread.thread_id}
|
key={thread.thread_id}
|
||||||
@@ -210,10 +227,15 @@ export function RecentChatList() {
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Link
|
<Link
|
||||||
className="block w-full whitespace-nowrap group-hover/side-menu-item:overflow-hidden"
|
className="flex w-full items-center gap-1 whitespace-nowrap group-hover/side-menu-item:overflow-hidden"
|
||||||
href={pathOfThread(thread)}
|
href={pathOfThread(thread)}
|
||||||
>
|
>
|
||||||
{desensitize(titleOfThread(thread, t.pages.newChat))}
|
{pinned && (
|
||||||
|
<Pin className="size-3 shrink-0 text-muted-foreground/70" />
|
||||||
|
)}
|
||||||
|
<span className="truncate">
|
||||||
|
{desensitize(titleOfThread(thread, t.pages.newChat))}
|
||||||
|
</span>
|
||||||
</Link>
|
</Link>
|
||||||
</SidebarMenuButton>
|
</SidebarMenuButton>
|
||||||
{env.NEXT_PUBLIC_STATIC_WEBSITE_ONLY !== "true" && (
|
{env.NEXT_PUBLIC_STATIC_WEBSITE_ONLY !== "true" && (
|
||||||
@@ -243,6 +265,36 @@ export function RecentChatList() {
|
|||||||
<Pencil className="text-muted-foreground" />
|
<Pencil className="text-muted-foreground" />
|
||||||
<span>{t.common.rename}</span>
|
<span>{t.common.rename}</span>
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem
|
||||||
|
onSelect={() =>
|
||||||
|
togglePin(thread.thread_id, !pinned)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{pinned ? (
|
||||||
|
<PinOff className="text-muted-foreground" />
|
||||||
|
) : (
|
||||||
|
<Pin className="text-muted-foreground" />
|
||||||
|
)}
|
||||||
|
<span>{pinned ? t.common.unpin : t.common.pin}</span>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem
|
||||||
|
onSelect={() =>
|
||||||
|
toggleFavorite(thread.thread_id, !favorited)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Star
|
||||||
|
className={
|
||||||
|
favorited
|
||||||
|
? "fill-amber-400 text-amber-400"
|
||||||
|
: "text-muted-foreground"
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<span>
|
||||||
|
{favorited
|
||||||
|
? t.common.unfavorite
|
||||||
|
: t.common.favorite}
|
||||||
|
</span>
|
||||||
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onSelect={() => handleShare(thread)}
|
onSelect={() => handleShare(thread)}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -25,6 +25,10 @@ export const enUS: Translations = {
|
|||||||
edit: "Edit",
|
edit: "Edit",
|
||||||
rename: "Rename",
|
rename: "Rename",
|
||||||
share: "Share",
|
share: "Share",
|
||||||
|
pin: "Pin",
|
||||||
|
unpin: "Unpin",
|
||||||
|
favorite: "Favorite",
|
||||||
|
unfavorite: "Unfavorite",
|
||||||
openInNewWindow: "Open in new window",
|
openInNewWindow: "Open in new window",
|
||||||
close: "Close",
|
close: "Close",
|
||||||
more: "More",
|
more: "More",
|
||||||
@@ -255,6 +259,14 @@ export const enUS: Translations = {
|
|||||||
// Chats
|
// Chats
|
||||||
chats: {
|
chats: {
|
||||||
searchChats: "Search chats",
|
searchChats: "Search chats",
|
||||||
|
pinnedSection: "Pinned",
|
||||||
|
allChats: "All",
|
||||||
|
favorites: "Favorites",
|
||||||
|
onlyFavorites: "Favorites only",
|
||||||
|
prevPage: "Previous",
|
||||||
|
nextPage: "Next",
|
||||||
|
noChats: "No conversations yet",
|
||||||
|
noFavorites: "No favorited conversations yet",
|
||||||
},
|
},
|
||||||
|
|
||||||
// Conversation sharing
|
// Conversation sharing
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ export interface Translations {
|
|||||||
edit: string;
|
edit: string;
|
||||||
rename: string;
|
rename: string;
|
||||||
share: string;
|
share: string;
|
||||||
|
pin: string;
|
||||||
|
unpin: string;
|
||||||
|
favorite: string;
|
||||||
|
unfavorite: string;
|
||||||
openInNewWindow: string;
|
openInNewWindow: string;
|
||||||
close: string;
|
close: string;
|
||||||
more: string;
|
more: string;
|
||||||
@@ -198,6 +202,14 @@ export interface Translations {
|
|||||||
// Chats
|
// Chats
|
||||||
chats: {
|
chats: {
|
||||||
searchChats: string;
|
searchChats: string;
|
||||||
|
pinnedSection: string;
|
||||||
|
allChats: string;
|
||||||
|
favorites: string;
|
||||||
|
onlyFavorites: string;
|
||||||
|
prevPage: string;
|
||||||
|
nextPage: string;
|
||||||
|
noChats: string;
|
||||||
|
noFavorites: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Conversation sharing
|
// Conversation sharing
|
||||||
|
|||||||
@@ -25,6 +25,10 @@ export const zhCN: Translations = {
|
|||||||
edit: "编辑",
|
edit: "编辑",
|
||||||
rename: "重命名",
|
rename: "重命名",
|
||||||
share: "分享",
|
share: "分享",
|
||||||
|
pin: "置顶",
|
||||||
|
unpin: "取消置顶",
|
||||||
|
favorite: "收藏",
|
||||||
|
unfavorite: "取消收藏",
|
||||||
openInNewWindow: "在新窗口打开",
|
openInNewWindow: "在新窗口打开",
|
||||||
close: "关闭",
|
close: "关闭",
|
||||||
more: "更多",
|
more: "更多",
|
||||||
@@ -242,6 +246,14 @@ export const zhCN: Translations = {
|
|||||||
// Chats
|
// Chats
|
||||||
chats: {
|
chats: {
|
||||||
searchChats: "搜索对话",
|
searchChats: "搜索对话",
|
||||||
|
pinnedSection: "置顶",
|
||||||
|
allChats: "全部",
|
||||||
|
favorites: "收藏",
|
||||||
|
onlyFavorites: "只看收藏",
|
||||||
|
prevPage: "上一页",
|
||||||
|
nextPage: "下一页",
|
||||||
|
noChats: "暂无对话",
|
||||||
|
noFavorites: "暂无收藏的对话",
|
||||||
},
|
},
|
||||||
|
|
||||||
// Conversation sharing
|
// Conversation sharing
|
||||||
|
|||||||
@@ -621,15 +621,15 @@ export function useThreadStream({
|
|||||||
lockThreadRagMode(threadId);
|
lockThreadRagMode(threadId);
|
||||||
}
|
}
|
||||||
|
|
||||||
const mergedContext = {
|
const mergedContext = {
|
||||||
...context,
|
...context,
|
||||||
...extraContext,
|
...extraContext,
|
||||||
};
|
};
|
||||||
|
|
||||||
await thread.submit(
|
await thread.submit(
|
||||||
{
|
{
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
type: "human",
|
type: "human",
|
||||||
content: [
|
content: [
|
||||||
{
|
{
|
||||||
@@ -647,33 +647,33 @@ export function useThreadStream({
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
threadId: threadId,
|
threadId: threadId,
|
||||||
streamSubgraphs: true,
|
streamSubgraphs: true,
|
||||||
streamResumable: true,
|
streamResumable: true,
|
||||||
config: {
|
config: {
|
||||||
recursion_limit: 1000,
|
recursion_limit: 1000,
|
||||||
},
|
},
|
||||||
context: {
|
context: {
|
||||||
...mergedContext,
|
...mergedContext,
|
||||||
thinking_enabled: mergedContext.mode !== "flash",
|
thinking_enabled: mergedContext.mode !== "flash",
|
||||||
is_plan_mode:
|
is_plan_mode:
|
||||||
mergedContext.mode === "pro" || mergedContext.mode === "ultra",
|
mergedContext.mode === "pro" || mergedContext.mode === "ultra",
|
||||||
subagent_enabled: mergedContext.mode === "ultra",
|
subagent_enabled: mergedContext.mode === "ultra",
|
||||||
reasoning_effort:
|
reasoning_effort:
|
||||||
mergedContext.reasoning_effort ??
|
mergedContext.reasoning_effort ??
|
||||||
(mergedContext.mode === "ultra"
|
(mergedContext.mode === "ultra"
|
||||||
? "high"
|
? "high"
|
||||||
: mergedContext.mode === "pro"
|
: mergedContext.mode === "pro"
|
||||||
? "medium"
|
? "medium"
|
||||||
: mergedContext.mode === "thinking"
|
: mergedContext.mode === "thinking"
|
||||||
? "low"
|
? "low"
|
||||||
: undefined),
|
: undefined),
|
||||||
memory_injection_enabled:
|
memory_injection_enabled:
|
||||||
mergedContext.memory_injection_enabled ?? true,
|
mergedContext.memory_injection_enabled ?? true,
|
||||||
rag_mode_enabled: ragModeEnabled,
|
rag_mode_enabled: ragModeEnabled,
|
||||||
thread_id: threadId,
|
thread_id: threadId,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
void queryClient.invalidateQueries({ queryKey: ["threads", "search"] });
|
void queryClient.invalidateQueries({ queryKey: ["threads", "search"] });
|
||||||
@@ -853,6 +853,86 @@ export function useDeleteMessage() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merge metadata into a conversation's record via the Gateway
|
||||||
|
* `PATCH /api/threads/{id}` route. Used to persist per-conversation flags such
|
||||||
|
* as `is_pinned` (置顶) and `is_favorite` (收藏) — a conversation belongs to a
|
||||||
|
* single user, so these live directly on the thread metadata (no join table).
|
||||||
|
* Updates the `["threads", "search"]` cache optimistically so the UI reflects
|
||||||
|
* the toggle immediately, mirroring `useRenameThread`.
|
||||||
|
*/
|
||||||
|
export function useUpdateThreadMetadata() {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: async ({
|
||||||
|
threadId,
|
||||||
|
metadata,
|
||||||
|
}: {
|
||||||
|
threadId: string;
|
||||||
|
metadata: Record<string, unknown>;
|
||||||
|
}) => {
|
||||||
|
const response = await apiFetch(
|
||||||
|
`${getBackendBaseURL()}/api/threads/${encodeURIComponent(threadId)}`,
|
||||||
|
{
|
||||||
|
method: "PATCH",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ metadata }),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (!response.ok) {
|
||||||
|
const error = await response
|
||||||
|
.json()
|
||||||
|
.catch(() => ({ detail: "更新对话失败。" }));
|
||||||
|
throw new Error(error.detail ?? "更新对话失败。");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onSuccess(_, { threadId, metadata }) {
|
||||||
|
queryClient.setQueriesData(
|
||||||
|
{
|
||||||
|
queryKey: ["threads", "search"],
|
||||||
|
exact: false,
|
||||||
|
},
|
||||||
|
(oldData: Array<AgentThread> | undefined) => {
|
||||||
|
if (oldData == null) {
|
||||||
|
return oldData;
|
||||||
|
}
|
||||||
|
return oldData.map((t) =>
|
||||||
|
t.thread_id === threadId
|
||||||
|
? {
|
||||||
|
...t,
|
||||||
|
metadata: {
|
||||||
|
...(t.metadata as Record<string, unknown> | null),
|
||||||
|
...metadata,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: t,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Toggle a conversation's pinned (置顶) flag. */
|
||||||
|
export function useToggleThreadPin() {
|
||||||
|
const { mutate, ...rest } = useUpdateThreadMetadata();
|
||||||
|
return {
|
||||||
|
...rest,
|
||||||
|
toggle: (threadId: string, pinned: boolean) =>
|
||||||
|
mutate({ threadId, metadata: { is_pinned: pinned } }),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Toggle a conversation's favorite (收藏) flag. */
|
||||||
|
export function useToggleThreadFavorite() {
|
||||||
|
const { mutate, ...rest } = useUpdateThreadMetadata();
|
||||||
|
return {
|
||||||
|
...rest,
|
||||||
|
toggle: (threadId: string, favorite: boolean) =>
|
||||||
|
mutate({ threadId, metadata: { is_favorite: favorite } }),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function useRenameThread() {
|
export function useRenameThread() {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const apiClient = getAPIClient();
|
const apiClient = getAPIClient();
|
||||||
|
|||||||
@@ -81,6 +81,28 @@ export function titleOfThread(thread: AgentThread, fallback = "Untitled") {
|
|||||||
return fallback;
|
return fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isThreadPinned(thread: AgentThread): boolean {
|
||||||
|
return (thread.metadata as Record<string, unknown> | null)?.is_pinned === true;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isThreadFavorite(thread: AgentThread): boolean {
|
||||||
|
return (thread.metadata as Record<string, unknown> | null)?.is_favorite === true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stable sort that lifts pinned (置顶) threads to the top while preserving the
|
||||||
|
* incoming order (typically `updated_at` desc) within both the pinned and the
|
||||||
|
* unpinned group.
|
||||||
|
*/
|
||||||
|
export function sortThreadsPinnedFirst(threads: AgentThread[]): AgentThread[] {
|
||||||
|
const pinned: AgentThread[] = [];
|
||||||
|
const rest: AgentThread[] = [];
|
||||||
|
for (const thread of threads) {
|
||||||
|
(isThreadPinned(thread) ? pinned : rest).push(thread);
|
||||||
|
}
|
||||||
|
return [...pinned, ...rest];
|
||||||
|
}
|
||||||
|
|
||||||
export function sanitizeThreadTitleForDisplay(title: string | null | undefined) {
|
export function sanitizeThreadTitleForDisplay(title: string | null | undefined) {
|
||||||
if (!title) return "Untitled";
|
if (!title) return "Untitled";
|
||||||
|
|
||||||
|
|||||||
@@ -1,95 +1,255 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { DownloadIcon } from "lucide-react";
|
import {
|
||||||
import Link from "next/link";
|
ChevronLeft,
|
||||||
import { useEffect, useMemo, useState } from "react";
|
ChevronRight,
|
||||||
|
DownloadIcon,
|
||||||
import { Button } from "@/components/ui/button";
|
Pin,
|
||||||
import { Input } from "@/components/ui/input";
|
PinOff,
|
||||||
import { ScrollArea } from "@/components/ui/scroll-area";
|
Star,
|
||||||
import { ImportConversationsDialog } from "@/components/workspace/thread-share-dialogs";
|
} from "lucide-react";
|
||||||
import {
|
import Link from "next/link";
|
||||||
WorkspaceBody,
|
import { useEffect, useMemo, useState } from "react";
|
||||||
WorkspaceContainer,
|
|
||||||
WorkspaceHeader,
|
import { Button } from "@/components/ui/button";
|
||||||
} from "@/components/workspace/workspace-container";
|
import { Input } from "@/components/ui/input";
|
||||||
import { useI18n } from "@/core/i18n/hooks";
|
import { ScrollArea } from "@/components/ui/scroll-area";
|
||||||
import { useThreads } from "@/core/threads/hooks";
|
import { ImportConversationsDialog } from "@/components/workspace/thread-share-dialogs";
|
||||||
import { usePathOfThread, titleOfThread } from "@/core/threads/utils";
|
import {
|
||||||
import { formatTimeAgo } from "@/core/utils/datetime";
|
WorkspaceBody,
|
||||||
import { desensitize } from "@/lib/desensitize";
|
WorkspaceContainer,
|
||||||
|
WorkspaceHeader,
|
||||||
export default function ChatsPage() {
|
} from "@/components/workspace/workspace-container";
|
||||||
const pathOfThread = usePathOfThread();
|
import { useI18n } from "@/core/i18n/hooks";
|
||||||
const { t } = useI18n();
|
import {
|
||||||
const { data: threads } = useThreads();
|
useThreads,
|
||||||
const [search, setSearch] = useState("");
|
useToggleThreadFavorite,
|
||||||
const [importOpen, setImportOpen] = useState(false);
|
useToggleThreadPin,
|
||||||
|
} from "@/core/threads/hooks";
|
||||||
useEffect(() => {
|
import type { AgentThread } from "@/core/threads/types";
|
||||||
document.title = `${t.pages.chats} - ${t.pages.appName}`;
|
import {
|
||||||
}, [t.pages.chats, t.pages.appName]);
|
isThreadFavorite,
|
||||||
|
isThreadPinned,
|
||||||
const filteredThreads = useMemo(() => {
|
usePathOfThread,
|
||||||
return threads?.filter((thread) => {
|
titleOfThread,
|
||||||
return (
|
} from "@/core/threads/utils";
|
||||||
thread.metadata?.thread_type !== "scheduler" &&
|
import { formatTimeAgo } from "@/core/utils/datetime";
|
||||||
thread.metadata?.thread_type !== "roundtable" &&
|
import { desensitize } from "@/lib/desensitize";
|
||||||
titleOfThread(thread).toLowerCase().includes(search.toLowerCase())
|
import { cn } from "@/lib/utils";
|
||||||
);
|
|
||||||
});
|
const PAGE_SIZE = 20;
|
||||||
}, [threads, search]);
|
|
||||||
return (
|
export default function ChatsPage() {
|
||||||
<WorkspaceContainer>
|
const pathOfThread = usePathOfThread();
|
||||||
<WorkspaceHeader></WorkspaceHeader>
|
const { t } = useI18n();
|
||||||
<WorkspaceBody>
|
const { data: threads } = useThreads();
|
||||||
<div className="flex size-full flex-col">
|
const { toggle: togglePin } = useToggleThreadPin();
|
||||||
<header className="flex shrink-0 flex-col items-center gap-3 pt-8">
|
const { toggle: toggleFavorite } = useToggleThreadFavorite();
|
||||||
<div className="flex w-full max-w-(--container-width-md) items-center justify-end">
|
const [search, setSearch] = useState("");
|
||||||
<Button
|
const [onlyFavorites, setOnlyFavorites] = useState(false);
|
||||||
variant="outline"
|
const [page, setPage] = useState(1);
|
||||||
size="sm"
|
const [importOpen, setImportOpen] = useState(false);
|
||||||
onClick={() => setImportOpen(true)}
|
|
||||||
>
|
useEffect(() => {
|
||||||
<DownloadIcon className="size-4" />
|
document.title = `${t.pages.chats} - ${t.pages.appName}`;
|
||||||
{t.threadShare.importChats}
|
}, [t.pages.chats, t.pages.appName]);
|
||||||
</Button>
|
|
||||||
</div>
|
// Reset to the first page whenever the filtered result set changes.
|
||||||
<Input
|
useEffect(() => {
|
||||||
type="search"
|
setPage(1);
|
||||||
className="h-12 w-full max-w-(--container-width-md) text-xl"
|
}, [search, onlyFavorites]);
|
||||||
placeholder={t.chats.searchChats}
|
|
||||||
autoFocus
|
const filteredThreads = useMemo(() => {
|
||||||
value={search}
|
return (threads ?? []).filter((thread) => {
|
||||||
onChange={(e) => setSearch(e.target.value)}
|
if (
|
||||||
/>
|
thread.metadata?.thread_type === "scheduler" ||
|
||||||
</header>
|
thread.metadata?.thread_type === "roundtable"
|
||||||
<main className="min-h-0 flex-1">
|
) {
|
||||||
<ScrollArea className="size-full py-4">
|
return false;
|
||||||
<div className="mx-auto flex size-full max-w-(--container-width-md) flex-col">
|
}
|
||||||
{filteredThreads?.map((thread) => (
|
if (onlyFavorites && !isThreadFavorite(thread)) {
|
||||||
<Link key={thread.thread_id} href={pathOfThread(thread)}>
|
return false;
|
||||||
<div className="flex flex-col gap-2 border-b p-4">
|
}
|
||||||
<div>
|
return titleOfThread(thread)
|
||||||
<div>{desensitize(titleOfThread(thread, t.pages.newChat))}</div>
|
.toLowerCase()
|
||||||
</div>
|
.includes(search.toLowerCase());
|
||||||
{thread.updated_at && (
|
});
|
||||||
<div className="text-muted-foreground text-sm">
|
}, [threads, search, onlyFavorites]);
|
||||||
{formatTimeAgo(thread.updated_at)}
|
|
||||||
</div>
|
// Pinned conversations are surfaced in their own section and excluded from
|
||||||
)}
|
// the paginated list so they stay visible regardless of the current page.
|
||||||
</div>
|
const pinnedThreads = useMemo(
|
||||||
</Link>
|
() => filteredThreads.filter(isThreadPinned),
|
||||||
))}
|
[filteredThreads],
|
||||||
</div>
|
);
|
||||||
</ScrollArea>
|
const restThreads = useMemo(
|
||||||
</main>
|
() => filteredThreads.filter((t) => !isThreadPinned(t)),
|
||||||
</div>
|
[filteredThreads],
|
||||||
</WorkspaceBody>
|
);
|
||||||
<ImportConversationsDialog
|
|
||||||
open={importOpen}
|
const totalPages = Math.max(1, Math.ceil(restThreads.length / PAGE_SIZE));
|
||||||
onOpenChange={setImportOpen}
|
const currentPage = Math.min(page, totalPages);
|
||||||
/>
|
const pagedThreads = restThreads.slice(
|
||||||
</WorkspaceContainer>
|
(currentPage - 1) * PAGE_SIZE,
|
||||||
);
|
currentPage * PAGE_SIZE,
|
||||||
}
|
);
|
||||||
|
|
||||||
|
const renderThread = (thread: AgentThread) => {
|
||||||
|
const pinned = isThreadPinned(thread);
|
||||||
|
const favorited = isThreadFavorite(thread);
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={thread.thread_id}
|
||||||
|
className="group/chat-row relative flex flex-col gap-2 border-b"
|
||||||
|
>
|
||||||
|
<Link href={pathOfThread(thread)} className="block p-4 pr-24">
|
||||||
|
<div className="flex items-center gap-1.5">
|
||||||
|
{pinned && (
|
||||||
|
<Pin className="size-3.5 shrink-0 text-muted-foreground/70" />
|
||||||
|
)}
|
||||||
|
<span className="truncate">
|
||||||
|
{desensitize(titleOfThread(thread, t.pages.newChat))}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{thread.updated_at && (
|
||||||
|
<div className="text-muted-foreground mt-2 text-sm">
|
||||||
|
{formatTimeAgo(thread.updated_at)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Link>
|
||||||
|
{/* Row actions — kept out of the Link so clicks don't navigate. */}
|
||||||
|
<div className="absolute right-3 top-3 flex items-center gap-1 opacity-0 transition-opacity group-hover/chat-row:opacity-100 focus-within:opacity-100">
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="size-8"
|
||||||
|
title={favorited ? t.common.unfavorite : t.common.favorite}
|
||||||
|
onClick={() => toggleFavorite(thread.thread_id, !favorited)}
|
||||||
|
>
|
||||||
|
<Star
|
||||||
|
className={cn(
|
||||||
|
"size-4",
|
||||||
|
favorited
|
||||||
|
? "fill-amber-400 text-amber-400"
|
||||||
|
: "text-muted-foreground",
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="size-8"
|
||||||
|
title={pinned ? t.common.unpin : t.common.pin}
|
||||||
|
onClick={() => togglePin(thread.thread_id, !pinned)}
|
||||||
|
>
|
||||||
|
{pinned ? (
|
||||||
|
<PinOff className="size-4 text-muted-foreground" />
|
||||||
|
) : (
|
||||||
|
<Pin className="size-4 text-muted-foreground" />
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const isEmpty = filteredThreads.length === 0;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<WorkspaceContainer>
|
||||||
|
<WorkspaceHeader></WorkspaceHeader>
|
||||||
|
<WorkspaceBody>
|
||||||
|
<div className="flex size-full flex-col">
|
||||||
|
<header className="flex shrink-0 flex-col items-center gap-3 pt-8">
|
||||||
|
<div className="flex w-full max-w-(--container-width-md) items-center justify-between gap-2">
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<Button
|
||||||
|
variant={onlyFavorites ? "outline" : "secondary"}
|
||||||
|
size="sm"
|
||||||
|
onClick={() => setOnlyFavorites(false)}
|
||||||
|
>
|
||||||
|
{t.chats.allChats}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant={onlyFavorites ? "secondary" : "outline"}
|
||||||
|
size="sm"
|
||||||
|
onClick={() => setOnlyFavorites(true)}
|
||||||
|
>
|
||||||
|
<Star className="size-4" />
|
||||||
|
{t.chats.favorites}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => setImportOpen(true)}
|
||||||
|
>
|
||||||
|
<DownloadIcon className="size-4" />
|
||||||
|
{t.threadShare.importChats}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<Input
|
||||||
|
type="search"
|
||||||
|
className="h-12 w-full max-w-(--container-width-md) text-xl"
|
||||||
|
placeholder={t.chats.searchChats}
|
||||||
|
autoFocus
|
||||||
|
value={search}
|
||||||
|
onChange={(e) => setSearch(e.target.value)}
|
||||||
|
/>
|
||||||
|
</header>
|
||||||
|
<main className="min-h-0 flex-1">
|
||||||
|
<ScrollArea className="size-full py-4">
|
||||||
|
<div className="mx-auto flex size-full max-w-(--container-width-md) flex-col">
|
||||||
|
{pinnedThreads.length > 0 && (
|
||||||
|
<>
|
||||||
|
<div className="text-muted-foreground/70 px-4 pb-1 pt-2 text-xs font-semibold tracking-wider uppercase">
|
||||||
|
{t.chats.pinnedSection}
|
||||||
|
</div>
|
||||||
|
{pinnedThreads.map(renderThread)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{pagedThreads.map(renderThread)}
|
||||||
|
{isEmpty && (
|
||||||
|
<div className="text-muted-foreground py-16 text-center text-sm">
|
||||||
|
{onlyFavorites ? t.chats.noFavorites : t.chats.noChats}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{totalPages > 1 && (
|
||||||
|
<div className="flex items-center justify-center gap-3 py-6">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
disabled={currentPage <= 1}
|
||||||
|
onClick={() => setPage((p) => Math.max(1, p - 1))}
|
||||||
|
>
|
||||||
|
<ChevronLeft className="size-4" />
|
||||||
|
{t.chats.prevPage}
|
||||||
|
</Button>
|
||||||
|
<span className="text-muted-foreground text-sm tabular-nums">
|
||||||
|
{currentPage} / {totalPages}
|
||||||
|
</span>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
disabled={currentPage >= totalPages}
|
||||||
|
onClick={() =>
|
||||||
|
setPage((p) => Math.min(totalPages, p + 1))
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{t.chats.nextPage}
|
||||||
|
<ChevronRight className="size-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</ScrollArea>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
</WorkspaceBody>
|
||||||
|
<ImportConversationsDialog
|
||||||
|
open={importOpen}
|
||||||
|
onOpenChange={setImportOpen}
|
||||||
|
/>
|
||||||
|
</WorkspaceContainer>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user