Skip to content

Commit

Permalink
feat: add copy missed words to result screen (fehmer) (#5086)
Browse files Browse the repository at this point in the history
* feat: Add copy missed words to result screen

* remove margin

* update icons

---------

Co-authored-by: Miodec <jack@monkeytype.com>
  • Loading branch information
fehmer and Miodec authored Feb 19, 2024
1 parent 67881ca commit a1f883b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
1 change: 0 additions & 1 deletion frontend/src/styles/test.scss
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,6 @@
margin-bottom: 1rem;
.textButton {
padding: 0;
margin-left: 0.5rem;
}
.heatmapLegend {
margin-left: 0.5rem;
Expand Down
34 changes: 24 additions & 10 deletions frontend/src/ts/test/test-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1249,23 +1249,37 @@ $(".pageTest").on("click", "#saveScreenshotButton", () => {
});

$(".pageTest #copyWordsListButton").on("click", async () => {
let words;
if (Config.mode === "zen") {
words = TestInput.input.history.join(" ");
} else {
words = (TestWords.words.get() as string[])
.slice(0, TestInput.input.history.length)
.join(" ");
}
await copyToClipboard(words);
});

$(".pageTest #copyMissedWordsListButton").on("click", async () => {
let words;
if (Config.mode === "zen") {
words = TestInput.input.history.join(" ");
} else {
words = Object.keys(TestInput.missedWords ?? {}).join(" ");
}
await copyToClipboard(words);
});

async function copyToClipboard(content: string): Promise<void> {
try {
let words;
if (Config.mode === "zen") {
words = TestInput.input.history.join(" ");
} else {
words = (TestWords.words.get() as string[])
.slice(0, TestInput.input.history.length)
.join(" ");
}
await navigator.clipboard.writeText(words);
await navigator.clipboard.writeText(content);
Notifications.add("Copied to clipboard", 0, {
duration: 2,
});
} catch (e) {
Notifications.add("Could not copy to clipboard: " + e, -1);
}
});
}

$(".pageTest #toggleBurstHeatmap").on("click", async () => {
UpdateConfig.setBurstHeatmap(!Config.burstHeatmap);
Expand Down
10 changes: 9 additions & 1 deletion frontend/static/html/pages/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,15 @@
data-balloon-pos="up"
style="display: inline-block"
>
<i class="fas fa-fw fa-copy"></i>
<i class="fas fa-fw fa-align-left"></i>
</span>
<span
id="copyMissedWordsListButton"
class="textButton"
aria-label="Copy missed words list"
data-balloon-pos="up"
>
<i class="fas fa-fw fa-times"></i>
</span>
<span
id="toggleBurstHeatmap"
Expand Down

0 comments on commit a1f883b

Please sign in to comment.