ui: fix message.FLAG_ALERT display

This commit is contained in:
undefined committed 2022-12-13 21:36:31 +08:00
1 parent 13c9e86bd9
commit 71f5f5d8fb
3 files changed
+24 -8

No files matched your search

@@ -8,7 +8,6 @@ import { i18n, tpl } from 'vj/utils';
const onmessage = (msg) => { const onmessage = (msg) => {
console.log('Received message', msg); console.log('Received message', msg);
if (document.hidden) return false;
if (msg.mdoc.flag & FLAG_ALERT) { if (msg.mdoc.flag & FLAG_ALERT) {
// Is alert // Is alert
new InfoDialog({ new InfoDialog({
@@ -21,6 +20,7 @@ const onmessage = (msg) => {
}).open(); }).open();
return true; return true;
} }
if (document.hidden) return false;
// Is message // Is message
new VjNotification({ new VjNotification({
...(msg.udoc._id === 1 && msg.mdoc.flag & 4) ...(msg.udoc._id === 1 && msg.mdoc.flag & 4)
@@ -12,12 +12,28 @@ export const AppToaster = Toaster.create({
className: 'recipe-toaster', className: 'recipe-toaster',
position: Position.LEFT_BOTTOM, position: Position.LEFT_BOTTOM,
usePortal: true, usePortal: true,
}, ToasterContainer); } as any, ToasterContainer);
interface NotificationOptions {
avatar?: string;
title?: string;
message: string;
type?: string;
duration?: number;
action?: any;
}
export default class Notification { export default class Notification {
type: string;
action: any;
$dom: JQuery<HTMLElement>;
$n: JQuery<HTMLElement>;
duration: number;
autoHideTimer?: NodeJS.Timeout;
constructor({ constructor({
avatar, title, message, type = '', duration = 3000, action, avatar, title, message, type = '', duration = 3000, action,
}) { }: NotificationOptions) {
this.type = type; this.type = type;
if (avatar) this.type += ' avatar'; if (avatar) this.type += ' avatar';
if (title) this.type += ' title'; if (title) this.type += ' title';
@@ -49,19 +65,19 @@ export default class Notification {
setTimeout(() => this.$n.remove(), 200); setTimeout(() => this.$n.remove(), 200);
} }
static success(message, duration) { static success(message: string, duration?: number) {
return AppToaster.show({ message, timeout: duration, intent: Intent.SUCCESS }); return AppToaster.show({ message, timeout: duration, intent: Intent.SUCCESS });
} }
static info(message, duration) { static info(message: string, duration?: number) {
return AppToaster.show({ message, timeout: duration, intent: Intent.PRIMARY }); return AppToaster.show({ message, timeout: duration, intent: Intent.PRIMARY });
} }
static warn(message, duration) { static warn(message: string, duration?: number) {
return AppToaster.show({ message, timeout: duration, intent: Intent.WARNING }); return AppToaster.show({ message, timeout: duration, intent: Intent.WARNING });
} }
static error(message, duration) { static error(message: string, duration?: number) {
return AppToaster.show({ message, timeout: duration, intent: Intent.DANGER }); return AppToaster.show({ message, timeout: duration, intent: Intent.DANGER });
} }
} }
@@ -7,7 +7,7 @@
{% if UserContext %}{% include "partials/header_mobile.html" %}{% endif %} {% if UserContext %}{% include "partials/header_mobile.html" %}{% endif %}
<div class="main"> <div class="main">
{% for item in ui.getNodes('Notification').concat(notification or []) %}{% if item.checker(handler) %} {% for item in ui.getNodes('Notification').concat(notification or []) %}{% if item.checker(handler) %}
<div class="row"><blockquote class="{{ item.args.type }}">{{ _(item.name).format(item.args.args or []) }}</blockquote></div> <div class="row typo"><blockquote class="{{ item.args.type }}">{{ _(item.name).format(item.args.args or [])|nl2br|safe }}</blockquote></div>
{% endif %}{% endfor %} {% endif %}{% endfor %}
{% block content %}{% endblock %} {% block content %}{% endblock %}
</div> </div>