mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-09 07:09:36 +08:00
modal result notifications
This commit is contained in:
parent
ec33078234
commit
02435a76d2
2 changed files with 22 additions and 7 deletions
|
@ -92,14 +92,28 @@ const addFriendModal = new SimpleModal({
|
|||
execFn: async (_thisPopup, receiverName) => {
|
||||
const result = await addFriend(receiverName);
|
||||
|
||||
if (result !== true) {
|
||||
return {
|
||||
status: -1,
|
||||
message: result,
|
||||
};
|
||||
} else {
|
||||
if (result === true) {
|
||||
return { status: 1, message: `Request send to ${receiverName}` };
|
||||
}
|
||||
|
||||
let status: -1 | 0 | 1 = -1;
|
||||
let message: string = "Unknown error";
|
||||
|
||||
if (result.includes("already exists")) {
|
||||
status = 0;
|
||||
message = `You are already friends with ${receiverName}`;
|
||||
} else if (result.includes("request already sent")) {
|
||||
status = 0;
|
||||
message = `You have already sent a friend request to ${receiverName}`;
|
||||
} else if (result.includes("blocked by initiator")) {
|
||||
status = 0;
|
||||
message = `You have blocked ${receiverName}`;
|
||||
} else if (result.includes("blocked by receiver")) {
|
||||
status = 0;
|
||||
message = `${receiverName} has blocked you`;
|
||||
}
|
||||
|
||||
return { status, message, alwaysHide: true };
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -86,6 +86,7 @@ export type ExecReturn = {
|
|||
notificationOptions?: Notifications.AddNotificationOptions;
|
||||
hideOptions?: HideOptions;
|
||||
afterHide?: () => void;
|
||||
alwaysHide?: boolean;
|
||||
};
|
||||
|
||||
type FormInput = CommonInputType & {
|
||||
|
@ -373,7 +374,7 @@ export class SimpleModal {
|
|||
if (res.showNotification ?? true) {
|
||||
Notifications.add(res.message, res.status, res.notificationOptions);
|
||||
}
|
||||
if (res.status === 1) {
|
||||
if (res.status === 1 || res.alwaysHide) {
|
||||
void this.hide(true, res.hideOptions).then(() => {
|
||||
if (res.afterHide) {
|
||||
res.afterHide();
|
||||
|
|
Loading…
Add table
Reference in a new issue