From 07ca1acee9a5f4227d18766b49b3fe6c8690e9a1 Mon Sep 17 00:00:00 2001 From: Rémy Raes Date: Mon, 16 Oct 2023 16:17:37 +0200 Subject: feat: Notification menu (#615) Introduces a notification menu, which hosts notifications fired while the app was not focused. Notifications can be closed by the user. --- src-vue/src/plugins/modules/notifications.ts | 31 ++++++++++++++++++++++++++++ src-vue/src/plugins/store.ts | 2 ++ 2 files changed, 33 insertions(+) create mode 100644 src-vue/src/plugins/modules/notifications.ts (limited to 'src-vue/src/plugins') diff --git a/src-vue/src/plugins/modules/notifications.ts b/src-vue/src/plugins/modules/notifications.ts new file mode 100644 index 00000000..ed57f8af --- /dev/null +++ b/src-vue/src/plugins/modules/notifications.ts @@ -0,0 +1,31 @@ +type NotificationType = 'success' | 'warning' | 'info' | 'error'; + +export interface Notification { + title: string; + text: string; + type: NotificationType; +} + +interface NotificationsStoreState { + notifications: Notification[]; +} + + +/** + * This notification module is meant to host the list of notifications that have been fired while the application was + * not focused. + * This list is then used by the [NotificationButton] component to display notifications to user. + **/ +export const notificationsModule = { + state: () => ({ + notifications: [] + }) as NotificationsStoreState, + mutations: { + addNotification(state: NotificationsStoreState, payload: Notification) { + state.notifications.push(payload); + }, + removeNotification(state: NotificationsStoreState, index: number): void { + state.notifications.splice(index, 1); + } + } + } diff --git a/src-vue/src/plugins/store.ts b/src-vue/src/plugins/store.ts index 854cd19e..56bf37e9 100644 --- a/src-vue/src/plugins/store.ts +++ b/src-vue/src/plugins/store.ts @@ -19,6 +19,7 @@ import { searchModule } from './modules/search'; import { i18n } from '../main'; import { pullRequestModule } from './modules/pull_requests'; import { showErrorNotification, showNotification } from '../utils/ui'; +import { notificationsModule } from './modules/notifications'; const persistentStore = new Store('flight-core-settings.json'); @@ -57,6 +58,7 @@ export const store = createStore({ modules: { search: searchModule, pullrequests: pullRequestModule, + notifications: notificationsModule }, state(): FlightCoreStore { return { -- cgit v1.2.3