Improve reaadability of notifications.notify
This commit is contained in:
parent
033b11fff9
commit
7cc1c37bc3
2 changed files with 1643 additions and 1388 deletions
2954
package-lock.json
generated
2954
package-lock.json
generated
File diff suppressed because it is too large
Load diff
37
src/module/ui/notifications.ts
Normal file
37
src/module/ui/notifications.ts
Normal 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;
|
Loading…
Reference in a new issue