Improve reaadability of notifications.notify

This commit is contained in:
Johannes Loher 2021-02-10 19:05:20 +01:00
parent 033b11fff9
commit 7cc1c37bc3
2 changed files with 1643 additions and 1388 deletions

2994
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,37 @@
const notifications = {
info: (message: string, { permanent = false }: { permanent?: boolean } = {}): void => {
if (ui.notifications) {
ui.notifications.info(message, { permanent });
} else {
console.info(message);
}
},
warn: (message: string, { permanent = false }: { permanent?: boolean } = {}): void => {
if (ui.notifications) {
ui.notifications.warn(message, { permanent });
} else {
console.log(message);
}
},
error: (message: string, { permanent = false }: { permanent?: boolean } = {}): void => {
if (ui.notifications) {
ui.notifications.error(message, { permanent });
} else {
console.warn(message);
}
},
notify: (
message: string,
type: "info" | "warning" | "error" = "info",
{ permanent = false }: { permanent?: boolean } = {},
): void => {
if (ui.notifications) {
ui.notifications.notify(message, type, { permanent });
} else {
const log = { info: console.info, warning: console.warn, error: console.error }[type];
log(message);
}
},
};
export default notifications;