-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add copy feature to assistant chat message (#611)
* add copy feature to assistant chat message * fix tooltip not hiding on mobile * fix: add tooltips chore: breakout actions to extendable component + memoize add CopyText to hook we can reuse fix: Copy on code snippets broken, moved to event listener fix: highlightjs patch for new API support feat: add copy response support --------- Co-authored-by: timothycarambat <[email protected]>
- Loading branch information
1 parent
c2c8fe9
commit 56dc499
Showing
9 changed files
with
169 additions
and
31 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
43 changes: 43 additions & 0 deletions
43
...rc/components/WorkspaceChat/ChatContainer/ChatHistory/HistoricalMessage/Actions/index.jsx
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import useCopyText from "@/hooks/useCopyText"; | ||
import { Check, ClipboardText } from "@phosphor-icons/react"; | ||
import { memo } from "react"; | ||
import { Tooltip } from "react-tooltip"; | ||
|
||
const Actions = ({ message }) => { | ||
return ( | ||
<div className="flex justify-start items-center gap-x-4"> | ||
<CopyMessage message={message} /> | ||
{/* Other actions to go here later. */} | ||
</div> | ||
); | ||
}; | ||
|
||
function CopyMessage({ message }) { | ||
const { copied, copyText } = useCopyText(); | ||
return ( | ||
<> | ||
<div className="mt-3 relative"> | ||
<button | ||
data-tooltip-id="copy-assistant-text" | ||
data-tooltip-content="Copy" | ||
className="text-zinc-300" | ||
onClick={() => copyText(message)} | ||
> | ||
{copied ? ( | ||
<Check size={18} className="mb-1" /> | ||
) : ( | ||
<ClipboardText size={18} className="mb-1" /> | ||
)} | ||
</button> | ||
</div> | ||
<Tooltip | ||
id="copy-assistant-text" | ||
place="bottom" | ||
delayShow={300} | ||
className="tooltip !text-xs" | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
export default memo(Actions); |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { useState } from "react"; | ||
|
||
export default function useCopyText(delay = 2500) { | ||
const [copied, setCopied] = useState(false); | ||
const copyText = async (content) => { | ||
if (!content) return; | ||
navigator?.clipboard?.writeText(content); | ||
setCopied(content); | ||
setTimeout(() => { | ||
setCopied(false); | ||
}, delay); | ||
}; | ||
|
||
return { copyText, copied }; | ||
} |
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