mirror of
https://github.com/hubHarmony/servii-frontend.git
synced 2024-11-18 05:40:31 +00:00
[+] Added maintenance toast
This commit is contained in:
parent
f52930bce4
commit
7edcbe3653
@ -59,30 +59,8 @@ const nonToastableCalls: string[] = [
|
|||||||
serviiRequest.fetchPlayersStatus,
|
serviiRequest.fetchPlayersStatus,
|
||||||
];
|
];
|
||||||
|
|
||||||
class serviiApi {
|
function toast_status(status: number, message: string) {
|
||||||
constructor() {}
|
let toastType: 'success' | 'error' | 'info' | 'warning';
|
||||||
|
|
||||||
private static async call<T extends BaseRequest>(endpoint: serviiRequest, body: T): Promise<ApiResponse> {
|
|
||||||
const response = await fetch(`${apiUrl}/${endpoint}`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify(body),
|
|
||||||
});
|
|
||||||
const status: number = response.status;
|
|
||||||
const json = await response.json();
|
|
||||||
|
|
||||||
if (json.message === undefined) {
|
|
||||||
if (!(endpoint === serviiRequest.fetchServers)) {
|
|
||||||
return { return_code: status, message: "Couldn't find an available API" };
|
|
||||||
}
|
|
||||||
return { return_code: status, message: json };
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!nonToastableCalls.includes(endpoint)) {
|
|
||||||
|
|
||||||
let toastType: 'success' | 'error' | 'info';
|
|
||||||
|
|
||||||
if (status >= 200 && status < 300) {
|
if (status >= 200 && status < 300) {
|
||||||
toastType = 'success';
|
toastType = 'success';
|
||||||
@ -91,8 +69,11 @@ class serviiApi {
|
|||||||
} else {
|
} else {
|
||||||
toastType = 'info';
|
toastType = 'info';
|
||||||
}
|
}
|
||||||
|
if (status == 666) {
|
||||||
|
toastType = 'warning';
|
||||||
|
}
|
||||||
|
|
||||||
toast[toastType](json.message, {
|
toast[toastType](message, {
|
||||||
position: "top-right",
|
position: "top-right",
|
||||||
autoClose: 3500,
|
autoClose: 3500,
|
||||||
hideProgressBar: false,
|
hideProgressBar: false,
|
||||||
@ -103,11 +84,43 @@ class serviiApi {
|
|||||||
theme: "light",
|
theme: "light",
|
||||||
transition: Bounce,
|
transition: Bounce,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
class serviiApi {
|
||||||
|
private static async call<T extends BaseRequest>(endpoint: serviiRequest, body: T): Promise<ApiResponse> {
|
||||||
|
const unreachable: string = "Couldn't find an available API";
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${apiUrl}/${endpoint}`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
});
|
||||||
|
const status: number = response.status;
|
||||||
|
const json = await response.json();
|
||||||
|
const message = json.message;
|
||||||
|
|
||||||
|
if (message === undefined) {
|
||||||
|
if (!(endpoint === serviiRequest.fetchServers)) {
|
||||||
|
return {return_code: 503, message: "Couldn't find an available API"};
|
||||||
|
}
|
||||||
|
return {return_code: status, message: json};
|
||||||
}
|
}
|
||||||
|
|
||||||
return { return_code: status, message: json.message };
|
if (!nonToastableCalls.includes(endpoint)) {
|
||||||
|
toast_status(status, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {return_code: status, message: json.message};
|
||||||
|
} catch (error) {
|
||||||
|
toast_status(666, unreachable);
|
||||||
|
return {return_code: 503, message: "Couldn't find an available API"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
private static token(): string {
|
private static token(): string {
|
||||||
const currentUser = getAuth().currentUser;
|
const currentUser = getAuth().currentUser;
|
||||||
if (!currentUser) {
|
if (!currentUser) {
|
||||||
|
Loading…
Reference in New Issue
Block a user