Skip to content

Commit 0dc520b

Browse files
authored
Add confirmation dialog before closing host lobby modal 🔧 (#3364)
## Description: Show a confirm prompt when the user tries to close the host lobby via click-outside or Escape key, preventing accidental lobby exits. Happened to many people and also DougDoug... Does not show the prompt when the user clicks the arrow button because it's probably intentional. ## Please complete the following: - [X] I have added screenshots for all UI updates - [X] I process any text displayed to the user through translateText() and I've added it to the en.json file - [X] I have added relevant tests to the test directory - [X] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: FloPinguin
1 parent 6154b77 commit 0dc520b

4 files changed

Lines changed: 30 additions & 1 deletion

File tree

‎resources/lang/en.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,8 @@
430430
"teams_Humans Vs Nations": "Humans vs Nations",
431431
"starting_gold": "Starting gold",
432432
"crowded": "Crowded modifier",
433-
"hard_nations": "Hard Nations"
433+
"hard_nations": "Hard Nations",
434+
"leave_confirmation": "Are you sure you want to leave the lobby?"
434435
},
435436
"team_colors": {
436437
"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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ export abstract class BaseModal extends LitElement {
3939
if (this.modalEl) {
4040
this.modalEl.onClose = () => {
4141
if (this.isModalOpen) {
42+
if (!this.confirmBeforeClose()) {
43+
// Re-open the underlying o-modal since it already closed itself
44+
this.modalEl?.open();
45+
return;
46+
}
4247
this.close();
4348
}
4449
};
@@ -57,6 +62,9 @@ export abstract class BaseModal extends LitElement {
5762
private handleKeyDown = (e: KeyboardEvent) => {
5863
if (e.key === "Escape" && this.isModalOpen) {
5964
e.preventDefault();
65+
if (!this.confirmBeforeClose()) {
66+
return;
67+
}
6068
this.close();
6169
}
6270
};
@@ -93,6 +101,15 @@ export abstract class BaseModal extends LitElement {
93101
// Default implementation does nothing
94102
}
95103

104+
/**
105+
* Guard called before closing via Escape key or click-outside.
106+
* Override in subclasses to show a confirmation dialog.
107+
* Return false to prevent the modal from closing.
108+
*/
109+
public confirmBeforeClose(): boolean {
110+
return true;
111+
}
112+
96113
/**
97114
* Open the modal. Handles both inline and modal element modes.
98115
* Subclasses can override onOpen() for custom behavior.

0 commit comments

Comments
 (0)