From 5bedc8f88296ea372072b4467ade4d37e03b2d50 Mon Sep 17 00:00:00 2001 From: Prince Baghel Date: Sat, 21 Sep 2024 16:57:15 +0530 Subject: [PATCH] patch-clipboard --- src/app/dashboard/page.tsx | 4 ---- src/app/page.tsx | 15 ++++++++++--- src/components/chat.tsx | 34 ++++++++++++------------------ src/components/chatcardwrapper.tsx | 18 +++++++++++++--- 4 files changed, 41 insertions(+), 30 deletions(-) diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx index f54c970..0ea46d3 100644 --- a/src/app/dashboard/page.tsx +++ b/src/app/dashboard/page.tsx @@ -20,10 +20,6 @@ export default async function Page() { .run(); const chatId = data.toJSON().lastInsertRowid; - console.log("org_slug", org_slug); - console.log("org_id", org_id); - console.log("userId", userId); - console.log("\n\n\n\n\n\n"); redirect(`/dashboard/chat/${Number(chatId)}`); // redirect(`/dashboard/user`); } diff --git a/src/app/page.tsx b/src/app/page.tsx index ddc53e9..fd700e8 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -14,6 +14,7 @@ import { useRouter } from "next/navigation"; import InputBar from "@/components/inputBar2"; import { ChatType } from "@/lib/types"; import { parseAsString, useQueryState } from "next-usequerystate"; +import ChatCardWrapper from "@/components/chatcardwrapper"; const handleSmoothScroll = (): void => { if (typeof window !== "undefined") { @@ -69,7 +70,6 @@ export default function Home() { }; const handleSubmit = async () => { - console.log("handleSubmit"); if (input.trim() === "") return; try { @@ -80,7 +80,7 @@ export default function Home() { const data = await res.json(); router.push( - `/dashboard/chat/${data.newChatId}?new=true&clipboard=true&model=${chatType}`, + `/dashboard/chat/${data.newChatId}?new=true&clipboard=true&model=${chatType}&input=${input}`, ); } catch (error) { console.error("Error creating new chat:", error); @@ -116,7 +116,7 @@ export default function Home() { Let's hyper-accelerate your research.
- {isSignedIn ? ( + {isSignedIn && orgId ? (
> } /> +
+ +
) : ( ( props?.type || incomingModel || "chat", ); @@ -166,27 +167,20 @@ export default function Chat(props: ChatProps) { console.log("messages", messages); useEffect(() => { - if (isFromClipboard === "true" && isNewChat === "true") { + if (isNewChat === "true" && incomingInput) { //TODO: use types for useQueryState - navigator.clipboard - .readText() - .then((text) => { - if (text && chattype !== "tldraw") { - const newMessage = { - id: nanoid(), - role: "user", - content: text, - name: `${props.username},${props.uid}`, - audio: "", - } as Message; - append(newMessage); - } - setIsFromClipboard("false"); - setIsNewChat("false"); - }) - .catch((err) => { - console.error("Failed to read clipboard contents: ", err); - }); + if (incomingInput && chattype !== "tldraw") { + const newMessage = { + id: nanoid(), + role: "user", + content: incomingInput, + name: `${props.username},${props.uid}`, + audio: "", + } as Message; + append(newMessage); + } + setIsFromClipboard("false"); + setIsNewChat("false"); } }, [isFromClipboard, isNewChat]); diff --git a/src/components/chatcardwrapper.tsx b/src/components/chatcardwrapper.tsx index 962b30e..ded347a 100644 --- a/src/components/chatcardwrapper.tsx +++ b/src/components/chatcardwrapper.tsx @@ -9,6 +9,7 @@ import { Button, buttonVariants } from "@/components/button"; import { useIntersection } from "@mantine/hooks"; import { CircleNotch } from "@phosphor-icons/react"; import { useQueryState } from "next-usequerystate"; +import { cn } from "@/lib/utils"; interface Props { org_id: string | undefined; @@ -16,15 +17,21 @@ interface Props { uid: string; // initial conversation data initialData: ChatSchema[]; + isHome?: boolean; } // here will get all the conversation, will make them paginated and generate card for them -const ChatCardWrapper = ({ org_id, org_slug, uid, initialData }: Props) => { +const ChatCardWrapper = ({ + org_id, + org_slug, + uid, + initialData, + isHome = false, +}: Props) => { if (org_id === undefined) { redirect(`${uid}`); } const [chatsQuery] = useQueryState("chats"); - console.log("chatsQuery from chatcardwrapper", chatsQuery); const fetchChats = async ({ pageParam = 0 }) => { const response = await fetch( @@ -68,7 +75,12 @@ const ChatCardWrapper = ({ org_id, org_slug, uid, initialData }: Props) => { return (
-
+
{allCards?.map((chat, i) => { return (