From 9d2d74ad3a9b34cbb7a3004cd55bf009b176e6b2 Mon Sep 17 00:00:00 2001 From: PerikiyoXD Date: Wed, 9 Oct 2024 01:11:20 +0200 Subject: [PATCH] Lazy loaded and refactored CopyButton component logic --- frontend/src/components/Diff/Diff.tsx | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/frontend/src/components/Diff/Diff.tsx b/frontend/src/components/Diff/Diff.tsx index b6f21cd5e..928d39aff 100644 --- a/frontend/src/components/Diff/Diff.tsx +++ b/frontend/src/components/Diff/Diff.tsx @@ -20,12 +20,7 @@ import * as Objdiff from "./DiffRowObjdiff" import DragBar from "./DragBar" import { useHighlighers } from "./Highlighter" -// Utility function to copy content to clipboard -const copyToClipboard = (text: string) => { - navigator.clipboard.writeText(text) -} - -const getContentsFromDiffOutput = (diff: api.DiffOutput, kind: string): string => { +const copyDiffContentsToClipboard = (diff: api.DiffOutput, kind: string) => { // kind is either "base", "current", or "previous" const contents = diff.rows.map(row => { let text = "" @@ -39,15 +34,15 @@ const getContentsFromDiffOutput = (diff: api.DiffOutput, kind: string): string = return text }) - return contents.join("\n") + navigator.clipboard.writeText(contents.join("\n")) } // Small component for the copy button -function CopyButton({ content }: { content: string }) { +function CopyButton({ diff, kind }: { diff: api.DiffOutput, kind: string }) { return (