Skip to content
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

Add "Copy SGF" Button to Game Dock #2695

Closed
wants to merge 1 commit into from
Closed
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
43 changes: 43 additions & 0 deletions src/views/Game/GameDock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<div>{_("SGF content copied to clipboard!")}</div>, 2000);
})
.catch((err) => {
console.error("Failed to copy text to clipboard", err);
});
})
.catch((error) => {
console.error("Fetch error:", error);
toast(<div>{_("Failed to fetch SGF data.")}</div>, 2000);
});
};

const openACL = () => {
if (game_id) {
openACLModal({ game_id: game_id });
Expand Down Expand Up @@ -496,6 +521,24 @@ export function GameDock({
<i className="fa fa-download"></i> {_("Download SGF")}
</a>
)}
{sgf_download_enabled ? (
<Tooltip tooltipRequired={tooltipRequired} title={_("Copy SGF")}>
<a onClick={copySGFToClipboard}>
<i className="fa fa-clipboard"></i> {_("Copy SGF")}
</a>
</Tooltip>
) : (
<a
className="disabled"
onClick={() =>
void alert.fire(
_("SGF copying for this game is disabled until the game is complete."),
)
}
>
<i className="fa fa-clipboard"></i> {_("Copy SGF")}
</a>
)}
{sgf_download_enabled && sgf_with_ai_review_url && (
<Tooltip tooltipRequired={tooltipRequired} title={_("SGF with AI Review")}>
<a href={sgf_with_ai_review_url} target="_blank">
Expand Down
Loading