mobilizon/js/src/plugins/notifier.ts
Thomas Citharel 4144e9ffd0
Introduce group basic federation, event new page and notifications
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2020-06-03 16:01:26 +02:00

66 lines
1.4 KiB
TypeScript

import Vue from "vue";
import { ColorModifiers } from "buefy/types/helpers.d";
import { Route, RawLocation } from "vue-router";
declare module "vue/types/vue" {
interface Vue {
$notifier: {
success: (message: string) => void;
error: (message: string) => void;
info: (message: string) => void;
};
beforeRouteEnter?(
to: Route,
from: Route,
next: (to?: RawLocation | false | ((vm: Vue) => void)) => void
): void;
beforeRouteLeave?(
to: Route,
from: Route,
next: (to?: RawLocation | false | ((vm: Vue) => void)) => void
): void;
beforeRouteUpdate?(
to: Route,
from: Route,
next: (to?: RawLocation | false | ((vm: Vue) => void)) => void
): void;
}
}
export class Notifier {
private readonly vue: typeof Vue;
constructor(vue: typeof Vue) {
this.vue = vue;
}
success(message: string) {
this.notification(message, "is-success");
}
error(message: string) {
this.notification(message, "is-danger");
}
info(message: string) {
this.notification(message, "is-info");
}
private notification(message: string, type: ColorModifiers) {
this.vue.prototype.$buefy.notification.open({
message,
duration: 5000,
position: "is-bottom-right",
type,
hasIcon: true,
});
}
}
/* eslint-disable */
export function NotifierPlugin(vue: typeof Vue): void {
vue.prototype.$notifier = new Notifier(vue);
}