Skip to content

Commit cd333bf

Browse files
committed
feat: add confirmation dialog before closing host lobby modal
Show a confirm prompt when the user tries to close the host lobby via click-outside or Escape key, preventing accidental lobby exits. - Add confirmBeforeClose() guard to BaseModal (Escape key) - Check confirmBeforeClose() in Navigation.ts (click-outside) - Override in HostLobbyModal with translated confirmation message - Add leave_confirmation translation key
1 parent 47ef5a0 commit cd333bf

4 files changed

Lines changed: 25 additions & 1 deletion

File tree

resources/lang/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,8 @@
433433
"teams_Humans Vs Nations": "Humans vs Nations",
434434
"starting_gold": "Starting gold",
435435
"crowded": "Crowded modifier",
436-
"hard_nations": "Hard Nations"
436+
"hard_nations": "Hard Nations",
437+
"leave_confirmation": "Are you sure you want to leave the lobby?"
437438
},
438439
"team_colors": {
439440
"red": "Red",

src/client/HostLobbyModal.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,10 @@ export class HostLobbyModal extends BaseModal {
406406
);
407407
}
408408

409+
public confirmBeforeClose(): boolean {
410+
return confirm(translateText("host_modal.leave_confirmation"));
411+
}
412+
409413
protected onClose(): void {
410414
console.log("Closing host lobby modal");
411415
this.stopLobbyUpdates();

src/client/Navigation.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ export function initNavigation() {
106106
) as any;
107107

108108
if (openModal && typeof openModal.close === "function") {
109+
// Check confirmation guard before closing
110+
if (
111+
typeof openModal.confirmBeforeClose === "function" &&
112+
!openModal.confirmBeforeClose()
113+
) {
114+
return;
115+
}
109116
// Call leaveLobby or closeAndLeave first if it exists (for lobby modals)
110117
if (typeof openModal.leaveLobby === "function") {
111118
openModal.leaveLobby();

src/client/components/BaseModal.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ export abstract class BaseModal extends LitElement {
5757
private handleKeyDown = (e: KeyboardEvent) => {
5858
if (e.key === "Escape" && this.isModalOpen) {
5959
e.preventDefault();
60+
if (!this.confirmBeforeClose()) {
61+
return;
62+
}
6063
this.close();
6164
}
6265
};
@@ -93,6 +96,15 @@ export abstract class BaseModal extends LitElement {
9396
// Default implementation does nothing
9497
}
9598

99+
/**
100+
* Guard called before closing via Escape key or click-outside.
101+
* Override in subclasses to show a confirmation dialog.
102+
* Return false to prevent the modal from closing.
103+
*/
104+
public confirmBeforeClose(): boolean {
105+
return true;
106+
}
107+
96108
/**
97109
* Open the modal. Handles both inline and modal element modes.
98110
* Subclasses can override onOpen() for custom behavior.

0 commit comments

Comments
 (0)