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:
@@ -191,7 +191,7 @@ export default {
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
...mapState(['socket']),
|
||||
...mapState(['socket', 'daemonSocket']),
|
||||
getAvatarStyle() {
|
||||
if (!this.falukantUser || !this.falukantUser.character) return {};
|
||||
const { gender, age } = this.falukantUser.character;
|
||||
@@ -242,7 +242,15 @@ export default {
|
||||
if (newSocket) {
|
||||
this.setupSocketEvents();
|
||||
}
|
||||
},
|
||||
daemonSocket(newSocket, oldSocket) {
|
||||
if (oldSocket) {
|
||||
oldSocket.removeEventListener('message', this.handleDaemonMessage);
|
||||
}
|
||||
if (newSocket) {
|
||||
newSocket.addEventListener('message', this.handleDaemonMessage);
|
||||
}
|
||||
},
|
||||
},
|
||||
async mounted() {
|
||||
await this.fetchFalukantUser();
|
||||
@@ -252,27 +260,35 @@ export default {
|
||||
await this.fetchAllStock();
|
||||
await this.fetchProductions();
|
||||
}
|
||||
// Daemon WebSocket deaktiviert - verwende Socket.io für alle Events
|
||||
this.setupSocketEvents();
|
||||
if (this.daemonSocket) {
|
||||
this.daemonSocket.addEventListener('message', this.handleDaemonMessage);
|
||||
}
|
||||
},
|
||||
beforeUnmount() {
|
||||
if (this.daemonSocket) {
|
||||
this.daemonSocket.removeEventListener('message', this.handleDaemonMessage);
|
||||
}
|
||||
if (this.socket) {
|
||||
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: {
|
||||
setupSocketEvents() {
|
||||
if (this.socket) {
|
||||
this.socket.on("falukantUserUpdated", this.fetchFalukantUser);
|
||||
this.socket.on("production_ready", this.handleProductionReadyEvent);
|
||||
this.socket.on("falukantUpdateStatus", (data) => {
|
||||
this.handleEvent({ event: 'falukantUpdateStatus', ...data });
|
||||
});
|
||||
this.socket.on("falukantBranchUpdate", (data) => {
|
||||
this.handleEvent({ event: 'falukantBranchUpdate', ...data });
|
||||
});
|
||||
this.socket.on("stock_change", (data) => {
|
||||
this.handleEvent({ event: 'stock_change', ...data });
|
||||
});
|
||||
} else {
|
||||
// Versuche es nach kurzer Verzögerung erneut
|
||||
setTimeout(() => {
|
||||
@@ -293,11 +309,35 @@ export default {
|
||||
if (age <= 55) return '45-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) {
|
||||
case 'falukantUpdateStatus':
|
||||
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;
|
||||
}
|
||||
},
|
||||
@@ -326,10 +366,6 @@ export default {
|
||||
}
|
||||
this.allStock = Object.values(aggregated);
|
||||
},
|
||||
handleProductionReadyEvent() {
|
||||
this.fetchAllStock();
|
||||
this.fetchProductions();
|
||||
},
|
||||
openBranch(branchId) {
|
||||
this.$router.push({ name: 'BranchView', params: { branchId } });
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user