mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-29 10:17:30 +08:00
fix: ape key not shown after generation
Fixed by making the close function async and resolving the promise on animation finish Closes #4657
This commit is contained in:
parent
aee1cc1581
commit
3dd5c880b7
1 changed files with 33 additions and 15 deletions
|
|
@ -51,6 +51,7 @@ interface ExecReturn {
|
|||
message: string;
|
||||
showNotification?: false;
|
||||
notificationOptions?: MonkeyTypes.AddNotificationOptions;
|
||||
afterHide?: () => void;
|
||||
}
|
||||
|
||||
const list: { [key: string]: SimplePopup } = {};
|
||||
|
|
@ -232,7 +233,11 @@ class SimplePopup {
|
|||
Notifications.add(res.message, res.status, res.notificationOptions);
|
||||
}
|
||||
if (res.status === 1) {
|
||||
this.hide();
|
||||
this.hide().then(() => {
|
||||
if (res.afterHide) {
|
||||
res.afterHide();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.enableInputs();
|
||||
$($("#simplePopup").find("input")[0]).trigger("focus");
|
||||
|
|
@ -271,22 +276,33 @@ class SimplePopup {
|
|||
});
|
||||
}
|
||||
|
||||
hide(): void {
|
||||
if (!this.canClose) return;
|
||||
activePopup = null;
|
||||
this.wrapper
|
||||
.stop(true, true)
|
||||
.css("opacity", 1)
|
||||
.removeClass("hidden")
|
||||
.animate({ opacity: 0 }, this.noAnimation ? 0 : 125, () => {
|
||||
this.wrapper.addClass("hidden");
|
||||
Skeleton.remove(wrapperId);
|
||||
});
|
||||
async hide(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!this.canClose) {
|
||||
reject(new Error("Cannot close popup"));
|
||||
return;
|
||||
}
|
||||
|
||||
activePopup = null;
|
||||
|
||||
this.wrapper
|
||||
.stop(true, true)
|
||||
.css("opacity", 1)
|
||||
.removeClass("hidden")
|
||||
.animate({ opacity: 0 }, this.noAnimation ? 0 : 125, () => {
|
||||
this.wrapper.addClass("hidden");
|
||||
Skeleton.remove(wrapperId);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function hide(): void {
|
||||
if (activePopup) return activePopup.hide();
|
||||
if (activePopup) {
|
||||
activePopup.hide();
|
||||
return;
|
||||
}
|
||||
$("#simplePopupWrapper")
|
||||
.stop(true, true)
|
||||
.css("opacity", 1)
|
||||
|
|
@ -1232,11 +1248,13 @@ list["generateApeKey"] = new SimplePopup(
|
|||
}
|
||||
|
||||
const data = response.data;
|
||||
list["viewApeKey"].show([data.apeKey]);
|
||||
|
||||
return {
|
||||
status: 1,
|
||||
message: "Key generated",
|
||||
afterHide: (): void => {
|
||||
list["viewApeKey"].show([data.apeKey]);
|
||||
},
|
||||
};
|
||||
},
|
||||
() => {
|
||||
|
|
@ -1278,7 +1296,7 @@ list["viewApeKey"] = new SimplePopup(
|
|||
setTimeout(() => {
|
||||
_thisPopup.canClose = true;
|
||||
$("#simplePopup .button").removeClass("hidden");
|
||||
}, 3000);
|
||||
}, 5000);
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue