Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions frontend/src/html/pages/test-result.html
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@
>
<i class="fas fa-fw fa-times"></i>
</button>
<button
id="copySlowWordsListButton"
class="textButton"
aria-label="Copy slow words list"
data-balloon-pos="up"
tabindex="-1"
>
<i class="fas fa-fw fa-tachometer-alt"></i>
</button>
<button
id="toggleBurstHeatmap"
class="textButton"
Expand Down
74 changes: 72 additions & 2 deletions frontend/src/ts/test/test-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {
showNoticeNotification,
showErrorNotification,
} from "../states/notifications";
import { showSimpleModal } from "../states/simple-modal";
import { z } from "zod";

import { Config } from "../config/store";
import { setConfig } from "../config/setters";
Expand Down Expand Up @@ -1914,10 +1916,78 @@ qs(".pageTest #copyMissedWordsListButton")?.on("click", async () => {
await copyToClipboard(words);
});

async function copyToClipboard(content: string): Promise<void> {
qs(".pageTest #copySlowWordsListButton")?.on("click", () => {
const eventLog = getLastEventLog();
if (eventLog === null) return;

const burstHistory = getWordBurstHistory(eventLog);
const avgWpm =
burstHistory.length > 0
? Math.round(
burstHistory.reduce((a, b) => a + b, 0) / burstHistory.length,
)
: 80;

showSimpleModal({
title: "Copy slow words",
buttonText: "copy",
buttonAlwaysEnabled: true,
schema: z.object({
speedThreshold: z.number().positive(),
}),
Comment thread
vrutant08 marked this conversation as resolved.
inputs: {
speedThreshold: {
type: "number",
label: "WPM threshold:",
placeholder: "80",
initVal: avgWpm,
},
},
execFn: async ({ speedThreshold }) => {
let typedWords: string[];
if (Config.mode === "zen") {
typedWords = getInputHistory(eventLog);
} else {
typedWords = TestWords.words
.get()
.slice(0, getInputHistory(eventLog).length)
.map((w) => w.text);
}

const slowWords: string[] = [];
typedWords.forEach((word, index) => {
const speed = burstHistory[index] ?? Infinity;
if (speed < speedThreshold) {
slowWords.push(word);
}
});

if (slowWords.length === 0) {
return {
status: "notice",
message: `No words typed under ${speedThreshold} WPM`,
};
}

await copyToClipboard(
slowWords.join(" "),
`Copied ${slowWords.length} slow word${slowWords.length > 1 ? "s" : ""} to clipboard`,
);
return {
status: "success",
showNotification: false,
};
},
});
});

async function copyToClipboard(
content: string,
customMessage?: string,
): Promise<void> {
try {
await navigator.clipboard.writeText(content);
showNoticeNotification("Copied to clipboard", {
showNoticeNotification(customMessage ?? "Copied to clipboard", {
durationMs: 2000,
});
} catch (e) {
Expand Down
Loading