Skip to content
Open
Show file tree
Hide file tree
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
16 changes: 9 additions & 7 deletions frontend/src/ts/states/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export function addNotificationWithLevel(
message: string,
level: NotificationLevel,
options: AddNotificationOptions = {},
): void {
): number {
let details = options.details;

if (options.response !== undefined) {
Expand Down Expand Up @@ -174,25 +174,27 @@ export function addNotificationWithLevel(
}, durationMs + 250);
autoRemoveTimers.set(notifId, timer);
}

return notifId;
}

export function showNoticeNotification(
message: string,
options?: AddNotificationOptions,
): void {
addNotificationWithLevel(message, "notice", options);
): number {
return addNotificationWithLevel(message, "notice", options);
}

export function showSuccessNotification(
message: string,
options?: AddNotificationOptions,
): void {
addNotificationWithLevel(message, "success", options);
): number {
return addNotificationWithLevel(message, "success", options);
}

export function showErrorNotification(
message: string,
options?: AddNotificationOptions,
): void {
addNotificationWithLevel(message, "error", options);
): number {
return addNotificationWithLevel(message, "error", options);
}
12 changes: 10 additions & 2 deletions frontend/src/ts/test/test-timer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as Numbers from "@monkeytype/util/numbers";
import {
showNoticeNotification,
showErrorNotification,
removeNotification,
} from "../states/notifications";
import * as Caret from "./caret";
import * as SlowTimer from "../legacy-states/slow-timer";
Expand Down Expand Up @@ -52,6 +53,7 @@ type TimerStats = {
};

let slowTimerCount = 0;
let slowTimerNotifIds: number[] = [];
let timer: NodeJS.Timeout | null = null;
const interval = 1000;
let expected = 0;
Expand Down Expand Up @@ -282,8 +284,10 @@ function checkIfTimerIsSlow(drift: number): void {
'This could be caused by "efficiency mode" on Microsoft Edge.',
);

showErrorNotification(
"Stopping the test due to bad performance. This would cause test calculations to be incorrect. If this happens a lot, please report this.",
slowTimerNotifIds.push(
showErrorNotification(
"Stopping the test due to bad performance. This would cause test calculations to be incorrect. If this happens a lot, please report this.",
),
);

timerEvent.dispatch({ key: "fail", value: "slow timer" });
Expand All @@ -294,6 +298,10 @@ function checkIfTimerIsSlow(drift: number): void {
export async function start(): Promise<void> {
SlowTimer.clear();
slowTimerCount = 0;
for (const id of slowTimerNotifIds) {
removeNotification(id, "clear");
}
slowTimerNotifIds = [];
void _startNew();
// void _startOld();
}
Expand Down
Loading