From 674801c8b2ab2c5fefd786b4223064228d01aab5 Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Sun, 22 Mar 2026 07:57:55 +0000 Subject: [PATCH] Fix subscription in the store We are back to having instant data --- ts/{sse-manager.ts => SSEManager.ts} | 0 ts/main.ts | 8 ++++++-- ts/store/communication.ts | 9 ++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) rename ts/{sse-manager.ts => SSEManager.ts} (100%) diff --git a/ts/sse-manager.ts b/ts/SSEManager.ts similarity index 100% rename from ts/sse-manager.ts rename to ts/SSEManager.ts diff --git a/ts/main.ts b/ts/main.ts index 8532c68d..000afa9e 100644 --- a/ts/main.ts +++ b/ts/main.ts @@ -2,7 +2,7 @@ import { createApp } from "vue"; import { createPinia } from "pinia"; import App from "./App.vue"; import router from "./router"; -import { SSEManager } from "./sse-manager"; +import { SSEManager } from "./SSEManager"; //import { SetupSidebar } from "./sidebar"; import "maplibre-gl/dist/maplibre-gl.css"; @@ -22,7 +22,11 @@ window.SSEManager = SSEManager; document.addEventListener("DOMContentLoaded", () => { SSEManager.connect("/api/events"); - //SetupSidebar(); + SSEManager.subscribe("*", (e) => { + if (e.type != "heartbeat") { + console.log("SSE", e); + } + }); }); document.addEventListener("init", () => { const user = { diff --git a/ts/store/communication.ts b/ts/store/communication.ts index 3371c403..89317141 100644 --- a/ts/store/communication.ts +++ b/ts/store/communication.ts @@ -1,7 +1,8 @@ import { defineStore } from "pinia"; import { ref, computed } from "vue"; -import { useUserStore } from "./user"; import { Communication } from "../types"; +import { SSEManager } from "../SSEManager"; +import { useUserStore } from "./user"; export const useCommunicationStore = defineStore("communication", () => { // State @@ -9,6 +10,12 @@ export const useCommunicationStore = defineStore("communication", () => { const loading = ref(false); const error = ref(null); + // Subscription + SSEManager.subscribe("*", (e) => { + if (e.resource.startsWith("rmo")) { + fetchAll(); + } + }); // Actions async function fetchAll() { const userStore = useUserStore();