Skip to content

Commit

Permalink
Merge pull request #99 from error505/feature/token_count_copy_button
Browse files Browse the repository at this point in the history
Adding copy button and token count
  • Loading branch information
thivy authored Aug 13, 2023
2 parents 9def0d6 + eba79dc commit 7ea0738
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/components/chat/chat-row.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
import { ChatRole } from "@/features/chat/chat-services/models";
import { cn } from "@/lib/utils";
import { FC } from "react";
import { FC, useState } from "react";
import remarkGfm from "remark-gfm";
import remarkMath from "remark-math";
import Typography from "../typography";
import { Avatar, AvatarImage } from "../ui/avatar";
import { CodeBlock } from "./code-block";
import { MemoizedReactMarkdown } from "./memoized-react-markdown";
import { CheckIcon, ClipboardIcon, ClipboardTypeIcon } from "lucide-react";
import { Button } from "../ui/button";

interface ChatRowProps {
name: string;
profilePicture: string;
message: string;
type: ChatRole;
}


const ChatRow: FC<ChatRowProps> = (props) => {
const [isIconChecked, setIsIconChecked] = useState(false);
const toggleIcon = () => {
setIsIconChecked(prevState => !prevState);
};

const handleButtonClick = () => {
toggleIcon();
navigator.clipboard.writeText(props.message);
};
return (

<div
className={cn(
"border-b ",
Expand All @@ -30,7 +44,16 @@ const ChatRow: FC<ChatRowProps> = (props) => {
</Avatar>
<Typography variant="h5" className="capitalize text-primary">
{props.name}
</Typography>
</Typography>
<Button
variant={"ghost"}
size={"sm"}
title="Copy text"
className="justify-right flex"
onClick={handleButtonClick}
>
{isIconChecked ? <CheckIcon size={16}/> : <ClipboardIcon size={16}/>}
</Button>
</div>
</div>
<div className="py-6">
Expand Down Expand Up @@ -76,8 +99,8 @@ const ChatRow: FC<ChatRowProps> = (props) => {
}}
>
{props.message}
</MemoizedReactMarkdown>
</div>
</MemoizedReactMarkdown>
</div>
</div>
</div>
);
Expand Down

0 comments on commit 7ea0738

Please sign in to comment.