mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-28 06:22:45 -08:00
refactor: extract overlay modal restore-state helpers
This commit is contained in:
30
src/core/services/overlay-modal-restore-service.test.ts
Normal file
30
src/core/services/overlay-modal-restore-service.test.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import {
|
||||
addOverlayModalRestoreFlagService,
|
||||
handleOverlayModalClosedService,
|
||||
} from "./overlay-modal-restore-service";
|
||||
|
||||
test("overlay modal restore service adds modal restore flag", () => {
|
||||
const restore = new Set<"runtime-options" | "subsync">();
|
||||
addOverlayModalRestoreFlagService(restore, "runtime-options");
|
||||
assert.equal(restore.has("runtime-options"), true);
|
||||
});
|
||||
|
||||
test("overlay modal restore service hides overlay only when last modal closes", () => {
|
||||
const restore = new Set<"runtime-options" | "subsync">();
|
||||
const visibility: boolean[] = [];
|
||||
|
||||
addOverlayModalRestoreFlagService(restore, "runtime-options");
|
||||
addOverlayModalRestoreFlagService(restore, "subsync");
|
||||
|
||||
handleOverlayModalClosedService(restore, "runtime-options", (visible) => {
|
||||
visibility.push(visible);
|
||||
});
|
||||
assert.equal(visibility.length, 0);
|
||||
|
||||
handleOverlayModalClosedService(restore, "subsync", (visible) => {
|
||||
visibility.push(visible);
|
||||
});
|
||||
assert.deepEqual(visibility, [false]);
|
||||
});
|
||||
18
src/core/services/overlay-modal-restore-service.ts
Normal file
18
src/core/services/overlay-modal-restore-service.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export function addOverlayModalRestoreFlagService<T extends string>(
|
||||
restoreSet: Set<T>,
|
||||
modal: T,
|
||||
): void {
|
||||
restoreSet.add(modal);
|
||||
}
|
||||
|
||||
export function handleOverlayModalClosedService<T extends string>(
|
||||
restoreSet: Set<T>,
|
||||
modal: T,
|
||||
setVisibleOverlayVisible: (visible: boolean) => void,
|
||||
): void {
|
||||
if (!restoreSet.has(modal)) return;
|
||||
restoreSet.delete(modal);
|
||||
if (restoreSet.size === 0) {
|
||||
setVisibleOverlayVisible(false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user