mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 11:42:07 +00:00
Copy FEN to clipboard from the endgame view (#33)
* display fen string under engame data and add hook to copy to clipboard * split seed data across files
This commit is contained in:
@@ -25,10 +25,12 @@ import { LiveSocket } from "phoenix_live_view";
|
||||
import { hooks as colocatedHooks } from "phoenix-colocated/chesstrainer";
|
||||
import topbar from "../vendor/topbar";
|
||||
import { ChessBoard } from "./hooks/chessBoard";
|
||||
import { CopyFen } from "./hooks/copyFen"
|
||||
|
||||
let Hooks = {
|
||||
...colocatedHooks,
|
||||
ChessBoard,
|
||||
CopyFen
|
||||
};
|
||||
|
||||
const csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content");
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
export const CopyFen = {
|
||||
mounted() {
|
||||
this.el.addEventListener("click", e => {
|
||||
e.preventDefault()
|
||||
const fen = this.el.dataset.fen
|
||||
|
||||
navigator.clipboard.writeText(fen).then(() => {
|
||||
const originalHTML = this.el.innerHTML
|
||||
this.el.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4 text-emerald-600 inline" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" /></svg> Copied!`
|
||||
|
||||
setTimeout(() => {
|
||||
this.el.innerHTML = originalHTML
|
||||
}, 2000)
|
||||
}).catch(err => {
|
||||
console.log('Failed to copy FEN: ', err)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user