96 lines
3.5 KiB
TypeScript
96 lines
3.5 KiB
TypeScript
"use client";
|
|
|
|
import { DownloadIcon } from "lucide-react";
|
|
import Link from "next/link";
|
|
import { useEffect, useMemo, useState } from "react";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
import { Input } from "@/components/ui/input";
|
|
import { ScrollArea } from "@/components/ui/scroll-area";
|
|
import { ImportConversationsDialog } from "@/components/workspace/thread-share-dialogs";
|
|
import {
|
|
WorkspaceBody,
|
|
WorkspaceContainer,
|
|
WorkspaceHeader,
|
|
} from "@/components/workspace/workspace-container";
|
|
import { useI18n } from "@/core/i18n/hooks";
|
|
import { useThreads } from "@/core/threads/hooks";
|
|
import { usePathOfThread, titleOfThread } from "@/core/threads/utils";
|
|
import { formatTimeAgo } from "@/core/utils/datetime";
|
|
import { desensitize } from "@/lib/desensitize";
|
|
|
|
export default function ChatsPage() {
|
|
const pathOfThread = usePathOfThread();
|
|
const { t } = useI18n();
|
|
const { data: threads } = useThreads();
|
|
const [search, setSearch] = useState("");
|
|
const [importOpen, setImportOpen] = useState(false);
|
|
|
|
useEffect(() => {
|
|
document.title = `${t.pages.chats} - ${t.pages.appName}`;
|
|
}, [t.pages.chats, t.pages.appName]);
|
|
|
|
const filteredThreads = useMemo(() => {
|
|
return threads?.filter((thread) => {
|
|
return (
|
|
thread.metadata?.thread_type !== "scheduler" &&
|
|
thread.metadata?.thread_type !== "roundtable" &&
|
|
titleOfThread(thread).toLowerCase().includes(search.toLowerCase())
|
|
);
|
|
});
|
|
}, [threads, search]);
|
|
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-end">
|
|
<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">
|
|
{filteredThreads?.map((thread) => (
|
|
<Link key={thread.thread_id} href={pathOfThread(thread)}>
|
|
<div className="flex flex-col gap-2 border-b p-4">
|
|
<div>
|
|
<div>{desensitize(titleOfThread(thread))}</div>
|
|
</div>
|
|
{thread.updated_at && (
|
|
<div className="text-muted-foreground text-sm">
|
|
{formatTimeAgo(thread.updated_at)}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</Link>
|
|
))}
|
|
</div>
|
|
</ScrollArea>
|
|
</main>
|
|
</div>
|
|
</WorkspaceBody>
|
|
<ImportConversationsDialog
|
|
open={importOpen}
|
|
onOpenChange={setImportOpen}
|
|
/>
|
|
</WorkspaceContainer>
|
|
);
|
|
}
|