Skip to content

Commit c634e1c

Browse files
committed
renderer: Add event listener to show/hide DND duration dropdown.
Implements click and mouseleave behavior for the DND button and duration dropdown, allowing the user to select a duration visually. We also remove the dnd-util.js import, since we no longer handle the DNDtoggle() here and instead we send the toggle request to the ipcMain.
1 parent 9b6b47a commit c634e1c

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

app/renderer/js/main.ts

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import * as Sentry from "@sentry/electron/renderer";
99

1010
import type {Config} from "../../common/config-util.js";
1111
import * as ConfigUtil from "../../common/config-util.js";
12-
import * as DNDUtil from "../../common/dnd-util.js";
1312
import type {DndSettings} from "../../common/dnd-util.js";
1413
import * as EnterpriseUtil from "../../common/enterprise-util.js";
1514
import {html} from "../../common/html.js";
@@ -444,14 +443,34 @@ export class ServerManagerView {
444443

445444
initLeftSidebarEvents(): void {
446445
this.$dndButton.addEventListener("click", () => {
447-
const dndUtil = DNDUtil.toggle();
448-
ipcRenderer.send(
449-
"forward-message",
450-
"toggle-dnd",
451-
dndUtil.dnd,
452-
dndUtil.newSettings,
453-
);
446+
const isDndOn = ConfigUtil.getConfigItem("dnd", false);
447+
if (isDndOn) {
448+
ipcRenderer.send("forward-message", "toggle-dnd-request", undefined);
449+
return;
450+
}
451+
452+
const dropdown = document.querySelector("#dnd-dropdown");
453+
dropdown?.classList.toggle("hidden");
454+
this.$dndTooltip.classList.add("hidden");
455+
dropdown?.addEventListener("mouseleave", () => {
456+
dropdown.classList.add("hidden");
457+
this.$dndTooltip.classList.remove("hidden");
458+
});
454459
});
460+
const dropdownItems = document.querySelectorAll("#dnd-dropdown div");
461+
for (const item of dropdownItems) {
462+
item.addEventListener("click", (event) => {
463+
const target = event.target as HTMLElement;
464+
const value = target.dataset.minutes;
465+
const duration = value === "forever" ? undefined : Number(value);
466+
467+
ipcRenderer.send("forward-message", "toggle-dnd-request", duration);
468+
469+
document.querySelector("#dnd-dropdown")?.classList.add("hidden");
470+
this.$dndTooltip.classList.remove("hidden");
471+
});
472+
}
473+
455474
this.$reloadButton.addEventListener("click", async () => {
456475
const tab = this.tabs[this.activeTabIndex];
457476
if (tab instanceof ServerTab) (await tab.webview).reload();

0 commit comments

Comments
 (0)