Enhance OverviewView component: Added daemonSocket handling for WebSocket events, improved event processing, and removed deprecated production_ready event handling. This update ensures better responsiveness to socket messages and maintains data integrity in the UI.

This commit is contained in:
Torsten Schulz (local)
2026-02-05 23:37:17 +01:00
parent 2958d38c63
commit 6a6cd7b910

View File

@@ -191,7 +191,7 @@ export default {
}; };
}, },
computed: { computed: {
...mapState(['socket']), ...mapState(['socket', 'daemonSocket']),
getAvatarStyle() { getAvatarStyle() {
if (!this.falukantUser || !this.falukantUser.character) return {}; if (!this.falukantUser || !this.falukantUser.character) return {};
const { gender, age } = this.falukantUser.character; const { gender, age } = this.falukantUser.character;
@@ -242,7 +242,15 @@ export default {
if (newSocket) { if (newSocket) {
this.setupSocketEvents(); this.setupSocketEvents();
} }
},
daemonSocket(newSocket, oldSocket) {
if (oldSocket) {
oldSocket.removeEventListener('message', this.handleDaemonMessage);
} }
if (newSocket) {
newSocket.addEventListener('message', this.handleDaemonMessage);
}
},
}, },
async mounted() { async mounted() {
await this.fetchFalukantUser(); await this.fetchFalukantUser();
@@ -252,27 +260,35 @@ export default {
await this.fetchAllStock(); await this.fetchAllStock();
await this.fetchProductions(); await this.fetchProductions();
} }
// Daemon WebSocket deaktiviert - verwende Socket.io für alle Events
this.setupSocketEvents(); this.setupSocketEvents();
if (this.daemonSocket) {
this.daemonSocket.addEventListener('message', this.handleDaemonMessage);
}
}, },
beforeUnmount() { beforeUnmount() {
if (this.daemonSocket) {
this.daemonSocket.removeEventListener('message', this.handleDaemonMessage);
}
if (this.socket) { if (this.socket) {
this.socket.off("falukantUserUpdated", this.fetchFalukantUser); this.socket.off("falukantUserUpdated", this.fetchFalukantUser);
this.socket.off("production_ready", this.handleProductionReadyEvent); this.socket.off("falukantUpdateStatus");
this.socket.off("falukantBranchUpdate");
this.socket.off("stock_change");
} }
// Daemon WebSocket deaktiviert - keine Cleanup nötig
}, },
methods: { methods: {
setupSocketEvents() { setupSocketEvents() {
if (this.socket) { if (this.socket) {
this.socket.on("falukantUserUpdated", this.fetchFalukantUser); this.socket.on("falukantUserUpdated", this.fetchFalukantUser);
this.socket.on("production_ready", this.handleProductionReadyEvent);
this.socket.on("falukantUpdateStatus", (data) => { this.socket.on("falukantUpdateStatus", (data) => {
this.handleEvent({ event: 'falukantUpdateStatus', ...data }); this.handleEvent({ event: 'falukantUpdateStatus', ...data });
}); });
this.socket.on("falukantBranchUpdate", (data) => { this.socket.on("falukantBranchUpdate", (data) => {
this.handleEvent({ event: 'falukantBranchUpdate', ...data }); this.handleEvent({ event: 'falukantBranchUpdate', ...data });
}); });
this.socket.on("stock_change", (data) => {
this.handleEvent({ event: 'stock_change', ...data });
});
} else { } else {
// Versuche es nach kurzer Verzögerung erneut // Versuche es nach kurzer Verzögerung erneut
setTimeout(() => { setTimeout(() => {
@@ -293,11 +309,35 @@ export default {
if (age <= 55) return '45-55'; if (age <= 55) return '45-55';
return '55+'; return '55+';
}, },
handleEvent(eventData) { handleDaemonMessage(event) {
if (event.data === 'ping') return;
try {
const message = JSON.parse(event.data);
this.handleEvent(message);
} catch (err) {
console.error('Overview: Error processing daemon message:', err);
}
},
async handleEvent(eventData) {
if (!this.falukantUser?.character) return;
switch (eventData.event) { switch (eventData.event) {
case 'falukantUpdateStatus': case 'falukantUpdateStatus':
case 'falukantBranchUpdate': case 'falukantBranchUpdate':
this.fetchFalukantUser(); await this.fetchFalukantUser();
if (this.falukantUser?.character) {
await this.fetchProductions();
await this.fetchAllStock();
}
break;
case 'production_ready':
case 'production_started':
await this.fetchProductions();
await this.fetchAllStock();
break;
case 'stock_change':
case 'selled_items':
await this.fetchProductions();
await this.fetchAllStock();
break; break;
} }
}, },
@@ -326,10 +366,6 @@ export default {
} }
this.allStock = Object.values(aggregated); this.allStock = Object.values(aggregated);
}, },
handleProductionReadyEvent() {
this.fetchAllStock();
this.fetchProductions();
},
openBranch(branchId) { openBranch(branchId) {
this.$router.push({ name: 'BranchView', params: { branchId } }); this.$router.push({ name: 'BranchView', params: { branchId } });
}, },