mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-22 15:29:27 +02:00
Stupid promises everyone hates them and they deserver to die
This commit is contained in:
parent
a477880ea1
commit
74264e063a
@ -100,7 +100,7 @@ export default class AdminUiHandler extends FormModalUiHandler {
|
|||||||
this.scene.ui.setMode(Mode.ADMIN, Object.assign(config, { errorMessage: message?.trim() }), this.adminMode, adminResult, isError);
|
this.scene.ui.setMode(Mode.ADMIN, Object.assign(config, { errorMessage: message?.trim() }), this.adminMode, adminResult, isError);
|
||||||
this.scene.ui.playError();
|
this.scene.ui.playError();
|
||||||
};
|
};
|
||||||
let adminSearchResult: AdminSearchInfo = this.convertInputsToAdmin(); // this converts the input texts into a single object for use later
|
const adminSearchResult: AdminSearchInfo = this.convertInputsToAdmin(); // this converts the input texts into a single object for use later
|
||||||
const validFields = this.areFieldsValid(this.adminMode);
|
const validFields = this.areFieldsValid(this.adminMode);
|
||||||
if (validFields.error) {
|
if (validFields.error) {
|
||||||
this.scene.ui.setMode(Mode.LOADING, { buttonActions: [] }); // this is here to force a loading screen to allow the admin tool to reopen again if there's an error
|
this.scene.ui.setMode(Mode.LOADING, { buttonActions: [] }); // this is here to force a loading screen to allow the admin tool to reopen again if there's an error
|
||||||
@ -112,27 +112,49 @@ export default class AdminUiHandler extends FormModalUiHandler {
|
|||||||
/*this.updateAdminPanelInfo(adminSearchResult, AdminMode.LINK);*/
|
/*this.updateAdminPanelInfo(adminSearchResult, AdminMode.LINK);*/
|
||||||
return showMessage("Username and discord successfully linked", adminSearchResult, false);
|
return showMessage("Username and discord successfully linked", adminSearchResult, false);
|
||||||
} else if (this.adminMode === AdminMode.SEARCH) {
|
} else if (this.adminMode === AdminMode.SEARCH) {
|
||||||
Utils.apiFetch(`admin/account/admin-search?username=${encodeURIComponent(adminSearchResult.username)}`, true)
|
const results = this.adminSearch(adminSearchResult)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (!response.ok) { // error
|
console.log("RESONSE: " + response);
|
||||||
console.error(response);
|
response?.adminSearchResult;
|
||||||
} else if (response.status === this.httpUserNotFoundErrorCode) { // username doesn't exist
|
console.log("RESONSE.adminSearchResult: " + response?.adminSearchResult);
|
||||||
return showMessage("Username not found in the database", adminSearchResult, true);
|
this.updateAdminPanelInfo(adminSearchResult);
|
||||||
} else { // success
|
|
||||||
response.json().then(jsonResponse => {
|
|
||||||
adminSearchResult = jsonResponse;
|
|
||||||
// we double revert here and below to go back 2 layers of menus
|
|
||||||
//this.scene.ui.revertMode();
|
|
||||||
//this.scene.ui.revertMode();
|
|
||||||
this.updateAdminPanelInfo(adminSearchResult);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.error(err);
|
|
||||||
this.scene.ui.revertMode();
|
|
||||||
this.scene.ui.revertMode();
|
|
||||||
});
|
});
|
||||||
|
console.log(results);
|
||||||
|
//this.updateAdminPanelInfo(adminSearchResult);
|
||||||
|
//});
|
||||||
|
//response.then(value => {
|
||||||
|
// adminResult = value;
|
||||||
|
// console.log(adminResult);
|
||||||
|
// this.updateAdminPanelInfo(adminResult);
|
||||||
|
//});
|
||||||
|
|
||||||
|
//.then(value => {
|
||||||
|
// adminResult = value;
|
||||||
|
// this.updateAdminPanelInfo(adminResult);
|
||||||
|
//});
|
||||||
|
|
||||||
|
|
||||||
|
//Utils.apiFetch(`admin/account/admin-search?username=${encodeURIComponent(adminSearchResult.username)}`, true)
|
||||||
|
// .then(response => {
|
||||||
|
// if (!response.ok) { // error
|
||||||
|
// console.error(response);
|
||||||
|
// } else if (response.status === this.httpUserNotFoundErrorCode) { // username doesn't exist
|
||||||
|
// return showMessage("Username not found in the database", adminSearchResult, true);
|
||||||
|
// } else { // success
|
||||||
|
// response.json().then(jsonResponse => {
|
||||||
|
// adminSearchResult = jsonResponse;
|
||||||
|
// // we double revert here and below to go back 2 layers of menus
|
||||||
|
// //this.scene.ui.revertMode();
|
||||||
|
// //this.scene.ui.revertMode();
|
||||||
|
// this.updateAdminPanelInfo(adminSearchResult);
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// .catch((err) => {
|
||||||
|
// console.error(err);
|
||||||
|
// this.scene.ui.revertMode();
|
||||||
|
// this.scene.ui.revertMode();
|
||||||
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -218,6 +240,52 @@ export default class AdminUiHandler extends FormModalUiHandler {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async adminSearch(adminSearchResult: AdminSearchInfo): Promise<{ adminSearchResult?: AdminSearchInfo, error: boolean, errorType?: string }> {
|
||||||
|
try {
|
||||||
|
const response = await Utils.apiFetch(`admin/account/admin-search?username=${encodeURIComponent(adminSearchResult.username)}`, true);
|
||||||
|
if (!response.ok) { // error
|
||||||
|
console.error(response);
|
||||||
|
console.log(adminSearchResult);
|
||||||
|
return { adminSearchResult: adminSearchResult, error: true, errorType: "Error" };
|
||||||
|
} else if (response.status === this.httpUserNotFoundErrorCode) { // username doesn't exist
|
||||||
|
console.log(adminSearchResult);
|
||||||
|
return { adminSearchResult: adminSearchResult, error: true, errorType: "UsernameNotFound" };
|
||||||
|
}
|
||||||
|
response.json().then(jsonResponse => {
|
||||||
|
console.log(jsonResponse);
|
||||||
|
return { adminSearchResult: jsonResponse, error: false };
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
return { error: true, errorType: err };
|
||||||
|
}
|
||||||
|
//Utils.apiFetch(`admin/account/admin-search?username=${encodeURIComponent(adminSearchResult.username)}`, true)
|
||||||
|
// .then(response => {
|
||||||
|
// if (!response.ok) { // error
|
||||||
|
// console.error(response);
|
||||||
|
// return { adminSearchResult: adminSearchResult, error: true, errorType: "Error" };
|
||||||
|
// } else if (response.status === this.httpUserNotFoundErrorCode) { // username doesn't exist
|
||||||
|
// //return showMessage("Username not found in the database", adminSearchResult, true);
|
||||||
|
// return { adminSearchResult: adminSearchResult, error: true, errorType: "UsernameNotFound" };
|
||||||
|
// } else { // success
|
||||||
|
// response.json().then(jsonResponse => {
|
||||||
|
// adminSearchResult = jsonResponse;
|
||||||
|
// //this.updateAdminPanelInfo(adminSearchResult);
|
||||||
|
// return { adminSearchResult: adminSearchResult, error: false };
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// //.then(adminSearchResult => {
|
||||||
|
// // return { adminSearchResult: adminSearchResult, error: true, errorType: "Weird spot" };
|
||||||
|
// //})
|
||||||
|
// .catch((err) => {
|
||||||
|
// console.error(err);
|
||||||
|
// this.scene.ui.revertMode();
|
||||||
|
// this.scene.ui.revertMode();
|
||||||
|
// return { adminSearchResult: adminSearchResult, error: true, errorType: err };
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
|
||||||
adminLinkUnlink(adminSearchResult: AdminSearchInfo, service: string, mode: string) {
|
adminLinkUnlink(adminSearchResult: AdminSearchInfo, service: string, mode: string) {
|
||||||
Utils.apiPost(`admin/account/${service}-${mode}`, `username=${encodeURIComponent(adminSearchResult.username)}&discordId=${encodeURIComponent(adminSearchResult.discordId)}`, "application/x-www-form-urlencoded", true)
|
Utils.apiPost(`admin/account/${service}-${mode}`, `username=${encodeURIComponent(adminSearchResult.username)}&discordId=${encodeURIComponent(adminSearchResult.discordId)}`, "application/x-www-form-urlencoded", true)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
Loading…
Reference in New Issue
Block a user