mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-10-03 02:04:31 +10:00
fix(applications): handle cover letter copy failures (#3394)
* fix(applications): handle cover letter copy failures * style(applications): format clipboard error toast * refactor(applications): memoize copy draft handler
This commit is contained in:
@@ -14,7 +14,7 @@ import {
|
||||
SpinnerGapIcon,
|
||||
} from "@phosphor-icons/react";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useState } from "react";
|
||||
import { useCallback, useState } from "react";
|
||||
import { toast } from "@reactive-resume/ui/components/toast";
|
||||
import { generateFilename } from "@reactive-resume/utils/file";
|
||||
import { cn } from "@reactive-resume/utils/style";
|
||||
@@ -235,6 +235,20 @@ export function ApplicationAiCopilot({ application }: Props) {
|
||||
}
|
||||
};
|
||||
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: keep review-requested callback dependencies explicit.
|
||||
const copyDraft = useCallback(async () => {
|
||||
try {
|
||||
if (!navigator.clipboard?.writeText) throw new Error("Clipboard unavailable");
|
||||
await navigator.clipboard.writeText(draft?.text ?? "");
|
||||
toast.add({ type: "success", description: t`Copied to clipboard.` });
|
||||
} catch {
|
||||
toast.add({
|
||||
type: "error",
|
||||
description: t`Could not copy to clipboard. Please copy the text manually.`,
|
||||
});
|
||||
}
|
||||
}, [draft?.text, toast, t]);
|
||||
|
||||
return (
|
||||
<section className="overflow-hidden rounded-xl border border-primary/15 bg-primary/[0.04]">
|
||||
<header className="flex items-center gap-2 px-3.5 pt-3">
|
||||
@@ -341,10 +355,7 @@ export function ApplicationAiCopilot({ application }: Props) {
|
||||
<button
|
||||
type="button"
|
||||
className="inline-flex items-center gap-1 text-muted-foreground text-xs hover:text-foreground"
|
||||
onClick={() => {
|
||||
void navigator.clipboard.writeText(draft.text);
|
||||
toast.add({ type: "success", description: t`Copied to clipboard.` });
|
||||
}}
|
||||
onClick={() => void copyDraft()}
|
||||
>
|
||||
<CopyIcon className="size-3.5" /> <Trans>Copy</Trans>
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user