diff --git a/frontend/src/ts/states/notifications.ts b/frontend/src/ts/states/notifications.ts index d003750fb3d8..3108c1594d1d 100644 --- a/frontend/src/ts/states/notifications.ts +++ b/frontend/src/ts/states/notifications.ts @@ -115,7 +115,7 @@ export function addNotificationWithLevel( message: string, level: NotificationLevel, options: AddNotificationOptions = {}, -): void { +): number { let details = options.details; if (options.response !== undefined) { @@ -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); } diff --git a/frontend/src/ts/test/test-timer.ts b/frontend/src/ts/test/test-timer.ts index 26cf66b694e3..cff4ac39940d 100644 --- a/frontend/src/ts/test/test-timer.ts +++ b/frontend/src/ts/test/test-timer.ts @@ -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"; @@ -52,6 +53,7 @@ type TimerStats = { }; let slowTimerCount = 0; +let slowTimerNotifIds: number[] = []; let timer: NodeJS.Timeout | null = null; const interval = 1000; let expected = 0; @@ -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" }); @@ -294,6 +298,10 @@ function checkIfTimerIsSlow(drift: number): void { export async function start(): Promise { SlowTimer.clear(); slowTimerCount = 0; + for (const id of slowTimerNotifIds) { + removeNotification(id, "clear"); + } + slowTimerNotifIds = []; void _startNew(); // void _startOld(); }