From c1a492cb7f11abe6223fd4f9e01d04f55790540e Mon Sep 17 00:00:00 2001 From: bracesproul Date: Tue, 4 Mar 2025 11:01:19 -0800 Subject: [PATCH] mobile support --- src/components/thread/history/index.tsx | 102 ++++++++++++++++-------- src/components/thread/index.tsx | 40 +++++++--- 2 files changed, 98 insertions(+), 44 deletions(-) diff --git a/src/components/thread/history/index.tsx b/src/components/thread/history/index.tsx index 1e73293..af545fb 100644 --- a/src/components/thread/history/index.tsx +++ b/src/components/thread/history/index.tsx @@ -3,11 +3,65 @@ import { useThreads } from "@/hooks/useThreads"; import { Thread } from "@langchain/langgraph-sdk"; import { useEffect, useState } from "react"; import { getContentString } from "../utils"; -import { useQueryParam, StringParam } from "use-query-params"; +import { useQueryParam, StringParam, BooleanParam } from "use-query-params"; +import { + Sheet, + SheetContent, + SheetHeader, + SheetTitle, +} from "@/components/ui/sheet"; + +function ThreadList({ + threads, + onThreadClick, +}: { + threads: Thread[]; + onThreadClick?: (threadId: string) => void; +}) { + const [threadId, setThreadId] = useQueryParam("threadId", StringParam); + + return ( +
+ {threads.map((t) => { + let itemText = t.thread_id; + if ( + typeof t.values === "object" && + t.values && + "messages" in t.values && + Array.isArray(t.values.messages) && + t.values.messages?.length > 0 + ) { + const firstMessage = t.values.messages[0]; + itemText = getContentString(firstMessage.content); + } + return ( +
+ +
+ ); + })} +
+ ); +} export default function ThreadHistory() { const [threads, setThreads] = useState([]); - const [threadId, setThreadId] = useQueryParam("threadId", StringParam); + const [chatHistoryOpen, setChatHistoryOpen] = useQueryParam( + "chatHistoryOpen", + BooleanParam, + ); + const { getThreads } = useThreads(); useEffect(() => { @@ -16,39 +70,21 @@ export default function ThreadHistory() { return ( <> -
+

Thread History

-
- {threads.map((t) => { - let itemText = t.thread_id; - if ( - typeof t.values === "object" && - t.values && - "messages" in t.values && - Array.isArray(t.values.messages) && - t.values.messages?.length > 0 - ) { - const firstMessage = t.values.messages[0]; - itemText = getContentString(firstMessage.content); - } - return ( -
- -
- ); - })} -
+
+ + + + Thread History + + setChatHistoryOpen((o) => !o)} + /> + + ); } diff --git a/src/components/thread/index.tsx b/src/components/thread/index.tsx index a6c49c1..2855368 100644 --- a/src/components/thread/index.tsx +++ b/src/components/thread/index.tsx @@ -14,8 +14,13 @@ import { } from "@/lib/ensure-tool-responses"; import { LangGraphLogoSVG } from "../icons/langgraph"; import { TooltipIconButton } from "./tooltip-icon-button"; -import { ArrowDown, LoaderCircle, SquarePen } from "lucide-react"; -import { StringParam, useQueryParam } from "use-query-params"; +import { + ArrowDown, + LoaderCircle, + PanelRightOpen, + SquarePen, +} from "lucide-react"; +import { BooleanParam, StringParam, useQueryParam } from "use-query-params"; import { StickToBottom, useStickToBottomContext } from "use-stick-to-bottom"; import ThreadHistory from "./history"; @@ -59,6 +64,10 @@ function ScrollToBottom(props: { className?: string }) { export function Thread() { const [threadId, setThreadId] = useQueryParam("threadId", StringParam); + const [_, setChatHistoryOpen] = useQueryParam( + "chatHistoryOpen", + BooleanParam, + ); const [input, setInput] = useState(""); const [firstTokenReceived, setFirstTokenReceived] = useState(false); @@ -133,15 +142,24 @@ export function Thread() { > {threadId && (
- +
+ + +