From 7d9994ab5fba561a2cdb2275b4458db3dc2354d0 Mon Sep 17 00:00:00 2001 From: Pavel Watson Date: Mon, 27 May 2024 19:34:09 +0300 Subject: [PATCH] Add Copy SGF button to Game Dock --- src/views/Game/GameDock.tsx | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/views/Game/GameDock.tsx b/src/views/Game/GameDock.tsx index 832580d444..299728ebaa 100644 --- a/src/views/Game/GameDock.tsx +++ b/src/views/Game/GameDock.tsx @@ -129,6 +129,31 @@ export function GameDock({ ? api1(`reviews/${review_id}/sgf`) : null; + // Function to copy SGF content to clipboard + const copySGFToClipboard = () => { + fetch(sgf_url) + .then((response) => { + if (!response.ok) { + throw new Error("Network response was not ok"); + } + return response.text(); + }) + .then((sgfData) => { + navigator.clipboard + .writeText(sgfData) + .then(() => { + toast(
{_("SGF content copied to clipboard!")}
, 2000); + }) + .catch((err) => { + console.error("Failed to copy text to clipboard", err); + }); + }) + .catch((error) => { + console.error("Fetch error:", error); + toast(
{_("Failed to fetch SGF data.")}
, 2000); + }); + }; + const openACL = () => { if (game_id) { openACLModal({ game_id: game_id }); @@ -496,6 +521,24 @@ export function GameDock({ {_("Download SGF")} )} + {sgf_download_enabled ? ( + + + {_("Copy SGF")} + + + ) : ( + + void alert.fire( + _("SGF copying for this game is disabled until the game is complete."), + ) + } + > + {_("Copy SGF")} + + )} {sgf_download_enabled && sgf_with_ai_review_url && (