generated from pinecone-io/pinecone-vercel-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
trying to get initial input. but need to figure out async data fetchi…
…ng in component rendering.
- Loading branch information
Showing
7 changed files
with
154 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,61 @@ | ||
import React from "react"; | ||
import { Message } from "ai"; | ||
import { useState } from "react"; | ||
import ContentCopyIcon from "@mui/icons-material/ContentCopy"; | ||
import DoneIcon from "@mui/icons-material/Done"; | ||
|
||
interface ChatMessagesProps { | ||
searchResultId: string; | ||
} | ||
export default function Messages({ messages }: { messages: Message[] }) { | ||
const [copiedIndices, setCopiedIndices] = useState<{ | ||
[key: number]: boolean; | ||
}>({}); | ||
|
||
const ChatMessages: React.FC<ChatMessagesProps> = ({ searchResultId }) => { | ||
return <div>ChatMessages</div>; | ||
}; | ||
const handleIconClick = async (content: string, index: number) => { | ||
try { | ||
await navigator.clipboard.writeText(content); | ||
setCopiedIndices((prev) => ({ ...prev, [index]: true })); | ||
setTimeout(() => { | ||
setCopiedIndices((prev) => ({ ...prev, [index]: false })); | ||
}, 1000); | ||
} catch (err) { | ||
console.error("Failed to copy: ", err); | ||
} | ||
}; | ||
|
||
export default ChatMessages; | ||
return ( | ||
<div className="flex flex-col bg-gray-700 leading-7"> | ||
{messages.map((msg, index) => ( | ||
<div | ||
key={index} | ||
className={`group ${ | ||
msg.role === "assistant" ? "bg-[#18181A]" : "bg-[#18181A]" | ||
} px-3 py-3 shadow-md hover:shadow-lg transition-shadow duration-200 flex slide-in-bottom border-b message-glow`} | ||
> | ||
<div | ||
className={`pr-3 border-r border-gray-500 flex items-center ${ | ||
msg.role === "assistant" ? "bg-[#18181A]" : "bg-[#18181A]" | ||
}`} | ||
> | ||
{msg.role === "assistant" ? "🤖" : "🧑💻"} | ||
</div> | ||
<div className="ml-4 flex flex-col items-center text-gray-200 pr-7"> | ||
{msg.content.split("\n").map((line, i) => ( | ||
<span key={i}> | ||
{line} | ||
<br></br> | ||
</span> | ||
))} | ||
</div> | ||
<div | ||
onClick={() => handleIconClick(msg.content, index)} | ||
className="cursor-pointer" | ||
> | ||
{copiedIndices[index] ? ( | ||
<DoneIcon className="text-white text-lg" /> | ||
) : ( | ||
<ContentCopyIcon className="text-white text-lg" /> | ||
)} | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters