Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
fix: use async / await
Browse files Browse the repository at this point in the history
  • Loading branch information
reneaaron committed Jun 13, 2024
1 parent fc70bd5 commit 8c34fe2
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions frontend/src/lib/clipboard.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { toast } from "src/components/ui/use-toast";

export function copyToClipboard(content: string) {
export async function copyToClipboard(content: string) {
const copyPromise = new Promise((resolve, reject) => {
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(content).then(resolve).catch(reject);
Expand All @@ -21,16 +21,15 @@ export function copyToClipboard(content: string) {
}
});

copyPromise
.then(() => {
toast({ title: "Copied to clipboard." });
})
.catch(() => {
toast({
title: "Failed to copy",
variant: "destructive",
});
try {
await copyPromise;
toast({ title: "Copied to clipboard." });
} catch (e) {
toast({
title: "Failed to copy to clipboard.",
variant: "destructive",
});
}
}

function selectElement(element: Element) {
Expand Down

0 comments on commit 8c34fe2

Please sign in to comment.