Added "type" argument to flashNotification (to distinguish between error and info)
parent
d57a9e79de
commit
a8274d225c
|
@ -41,8 +41,11 @@ export function openUrl(url: string): Promise<void> {
|
||||||
return syscall("editor.openUrl", url);
|
return syscall("editor.openUrl", url);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function flashNotification(message: string): Promise<void> {
|
export function flashNotification(
|
||||||
return syscall("editor.flashNotification", message);
|
message: string,
|
||||||
|
type: "info" | "error" = "info"
|
||||||
|
): Promise<void> {
|
||||||
|
return syscall("editor.flashNotification", message, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function filterBox(
|
export function filterBox(
|
||||||
|
|
|
@ -39,9 +39,14 @@ export function TopBar({
|
||||||
{prettyName(pageName)}
|
{prettyName(pageName)}
|
||||||
</span>
|
</span>
|
||||||
{notifications.length > 0 && (
|
{notifications.length > 0 && (
|
||||||
<div className="status">
|
<div className="notifications">
|
||||||
{notifications.map((notification) => (
|
{notifications.map((notification) => (
|
||||||
<div key={notification.id}>{notification.message}</div>
|
<div
|
||||||
|
key={notification.id}
|
||||||
|
className={`notification-${notification.type}`}
|
||||||
|
>
|
||||||
|
{notification.message}
|
||||||
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -272,22 +272,26 @@ export class Editor {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
flashNotification(message: string) {
|
flashNotification(message: string, type: "info" | "error" = "info") {
|
||||||
let id = Math.floor(Math.random() * 1000000);
|
let id = Math.floor(Math.random() * 1000000);
|
||||||
this.viewDispatch({
|
this.viewDispatch({
|
||||||
type: "show-notification",
|
type: "show-notification",
|
||||||
notification: {
|
notification: {
|
||||||
id: id,
|
id,
|
||||||
message: message,
|
type,
|
||||||
|
message,
|
||||||
date: new Date(),
|
date: new Date(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
setTimeout(() => {
|
setTimeout(
|
||||||
this.viewDispatch({
|
() => {
|
||||||
type: "dismiss-notification",
|
this.viewDispatch({
|
||||||
id: id,
|
type: "dismiss-notification",
|
||||||
});
|
id: id,
|
||||||
}, 2000);
|
});
|
||||||
|
},
|
||||||
|
type === "info" ? 2000 : 5000
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
filterBox(
|
filterBox(
|
||||||
|
@ -334,7 +338,10 @@ export class Editor {
|
||||||
.then(def.run)
|
.then(def.run)
|
||||||
.catch((e: any) => {
|
.catch((e: any) => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
this.flashNotification(`Error running command: ${e.message}`);
|
this.flashNotification(
|
||||||
|
`Error running command: ${e.message}`,
|
||||||
|
"error"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
|
@ -76,18 +76,28 @@ body {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
|
|
||||||
.status {
|
.notifications {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
font-family: "iA-Mono";
|
font-family: "iA-Mono";
|
||||||
bottom: 45px;
|
bottom: 45px;
|
||||||
left: 5px;
|
left: 5px;
|
||||||
right: 5px;
|
right: 5px;
|
||||||
background-color: rgb(187, 221, 247);
|
|
||||||
border: rgb(41, 41, 41) 1px solid;
|
|
||||||
border-radius: 5px;
|
|
||||||
padding: 3px;
|
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
z-index: 100;
|
z-index: 100;
|
||||||
|
|
||||||
|
> div {
|
||||||
|
padding: 3px;
|
||||||
|
margin-bottom: 3px;
|
||||||
|
border-radius: 5px;
|
||||||
|
border: rgb(41, 41, 41) 1px solid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.notification-info {
|
||||||
|
background-color: rgb(187, 221, 247);
|
||||||
|
}
|
||||||
|
.notification-error {
|
||||||
|
background-color: rgb(255, 84, 84);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.current-page {
|
.current-page {
|
||||||
|
|
|
@ -55,8 +55,12 @@ export function editorSyscalls(editor: Editor): SysCallMapping {
|
||||||
win.focus();
|
win.focus();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"editor.flashNotification": (ctx, message: string) => {
|
"editor.flashNotification": (
|
||||||
editor.flashNotification(message);
|
ctx,
|
||||||
|
message: string,
|
||||||
|
type: "error" | "info" = "info"
|
||||||
|
) => {
|
||||||
|
editor.flashNotification(message, type);
|
||||||
},
|
},
|
||||||
"editor.filterBox": (
|
"editor.filterBox": (
|
||||||
ctx,
|
ctx,
|
||||||
|
|
|
@ -6,6 +6,7 @@ export const slashCommandRegexp = /\/[\w\-]*/;
|
||||||
export type Notification = {
|
export type Notification = {
|
||||||
id: number;
|
id: number;
|
||||||
message: string;
|
message: string;
|
||||||
|
type: "info" | "error";
|
||||||
date: Date;
|
date: Date;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue