From ff2d24274c9c359e2b7ebaefafbf7a45d092c36b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 21 Jul 2023 17:02:48 +0200 Subject: [PATCH] Webapp: delay useNotifs() call in socket-status.js Instead of calling `useNotifs()` from the main body of `socket-status.js`, defer that call until the notifications are actually used. This decouples the two Pina stores at startup, making it possible to load `socket-status.js` from `App.vue` without conflicts. --- web/app/src/stores/socket-status.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/web/app/src/stores/socket-status.js b/web/app/src/stores/socket-status.js index fdc6fbf2..e9764280 100644 --- a/web/app/src/stores/socket-status.js +++ b/web/app/src/stores/socket-status.js @@ -1,13 +1,6 @@ import { defineStore } from 'pinia' import { useNotifs } from '@/stores/notifications' -// Not sure if this is the best way to deal with those notifications. It feels a -// bit spaghetto to have one Pinia store influence another. Maybe move this to -// the app level once the Workers and Settings views are fleshed out. Maybe -// that'll cause the Notifications popover to be handled at the app-global -// level, instead of per view, creating a better place to put this logic. -const notifs = useNotifs(); - /** * Status of the SocketIO/Websocket connection to Flamenco Manager. */ @@ -30,7 +23,7 @@ export const useSocketStatus = defineStore('socket-status', { // Only patch the state if it actually will change. if (!this.isConnected) return; - notifs.add(`Connection to Flamenco Manager lost`); + this._get_notifs().add(`Connection to Flamenco Manager lost`); this.$patch({ isConnected: false, wasEverDisconnected: true, @@ -46,11 +39,20 @@ export const useSocketStatus = defineStore('socket-status', { return; if (this.wasEverDisconnected) - notifs.add("Connection to Flamenco Manager established"); + this._get_notifs().add("Connection to Flamenco Manager established"); this.$patch({ isConnected: true, message: "", }); }, + + _get_notifs() { + // Not sure if this is the best way to deal with those notifications. It feels a + // bit spaghetto to have one Pinia store influence another. Maybe move this to + // the app level once the Workers and Settings views are fleshed out. Maybe + // that'll cause the Notifications popover to be handled at the app-global + // level, instead of per view, creating a better place to put this logic. + return useNotifs(); + } } })