Skip to content

Msg Clipboard to checkmark (optimistic UX) #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions client/src/components/Messages/HoverButtons.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import Clipboard from '../svg/Clipboard';
import CheckMark from '../svg/CheckMark';
import EditIcon from '../svg/EditIcon';
import RegenerateIcon from '../svg/RegenerateIcon';

Expand All @@ -13,6 +14,7 @@ export default function HoverButtons({
regenerate
}) {
const { endpoint, jailbreak = false } = conversation;
const [isCopied, setIsCopied] = React.useState(false);

const branchingSupported =
// azureOpenAI, openAI, chatGPTBrowser support branching, so edit enabled
Expand Down Expand Up @@ -59,11 +61,11 @@ export default function HoverButtons({

<button
className="hover-button rounded-md p-1 hover:bg-gray-100 hover:text-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-gray-200 disabled:dark:hover:text-gray-400 md:invisible md:group-hover:visible"
onClick={copyToClipboard}
onClick={() => copyToClipboard(setIsCopied)}
type="button"
title="copy to clipboard"
title={isCopied ? 'Copied to clipboard' : 'Copy to clipboard'}
>
<Clipboard />
{isCopied ? <CheckMark /> : <Clipboard />}
</button>
</div>
);
Expand Down
9 changes: 7 additions & 2 deletions client/src/components/Messages/Message.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,13 @@ export default function Message({
if (!isSubmitting && !message?.isCreatedByUser) regenerate(message);
};

const copyToClipboard = () => {
const copyToClipboard = (setIsCopied) => {
setIsCopied(true);
copy(message?.text);

setTimeout(() => {
setIsCopied(false);
}, 3000);
};

const clickSearchResult = async () => {
Expand Down Expand Up @@ -217,7 +222,7 @@ export default function Message({
conversation={conversation}
enterEdit={() => enterEdit()}
regenerate={() => regenerateMessage()}
copyToClipboard={() => copyToClipboard()}
copyToClipboard={copyToClipboard}
/>
<SubRow subclasses="switch-container">
<SiblingSwitch
Expand Down