Skip to content

Commit

Permalink
patch-clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
PrinceBaghel258025 committed Sep 21, 2024
1 parent c10e779 commit 5bedc8f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 30 deletions.
4 changes: 0 additions & 4 deletions src/app/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
}
15 changes: 12 additions & 3 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -69,7 +70,6 @@ export default function Home() {
};

const handleSubmit = async () => {
console.log("handleSubmit");
if (input.trim() === "") return;

try {
Expand All @@ -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);
Expand Down Expand Up @@ -116,7 +116,7 @@ export default function Home() {
Let's hyper-accelerate your research.
</h1>
<div className="grid md:grid-col-2 gap-4 sm:grid-col-1 p-4">
{isSignedIn ? (
{isSignedIn && orgId ? (
<div className="w-full md:min-w-[400px] lg:min-w-[600px] xl:min-w-[800px] ">
<InputBar
isHome={true}
Expand All @@ -130,6 +130,15 @@ export default function Home() {
setChattype as Dispatch<SetStateAction<ChatType>>
}
/>
<div className="w-full md:w-[400px] lg:w-[600px] xl:w-[800px] h-[500px] overflow-y-scroll scrollbar-hide">
<ChatCardWrapper
isHome={true}
org_id={orgId}
org_slug={orgSlug!}
uid={userId}
initialData={[]}
/>
</div>
</div>
) : (
<Link
Expand Down
34 changes: 14 additions & 20 deletions src/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default function Chat(props: ChatProps) {
const [isNewChat, setIsNewChat] = useQueryState("new");
const [isFromClipboard, setIsFromClipboard] = useQueryState("clipboard");
const [incomingModel] = useQueryState("model");
const [incomingInput] = useQueryState("input");
const [chattype, setChattype] = useState<ChatType>(
props?.type || incomingModel || "chat",
);
Expand Down Expand Up @@ -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]);

Expand Down
18 changes: 15 additions & 3 deletions src/components/chatcardwrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,29 @@ 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;
org_slug: string; // handle case of undefined in future
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(
Expand Down Expand Up @@ -68,7 +75,12 @@ const ChatCardWrapper = ({ org_id, org_slug, uid, initialData }: Props) => {

return (
<div>
<div className="grid sm:grid-cols-1 gap-3">
<div
className={cn(
"grid sm:grid-cols-1 gap-3",
isHome ? "sm:grid-cols-2" : "",
)}
>
{allCards?.map((chat, i) => {
return (
<div
Expand Down

0 comments on commit 5bedc8f

Please sign in to comment.