fix(ui): ensure the charging stations list re-rendered after UI server
[e-mobility-charging-stations-simulator.git] / ui / web / src / views / ChargingStationsView.vue
index 113137c80a44a5eb302c0d1cead562f5acae90ad..d4848e11e8a631186424aec088f0a72624e9035e 100644 (file)
                 getFromLocalStorage<number>('uiServerConfigurationIndex', 0) !== state.uiServerIndex
               ) {
                 setToLocalStorage<number>('uiServerConfigurationIndex', state.uiServerIndex)
-                app!.appContext.config.globalProperties.$uiClient.setConfiguration(
+                app?.appContext.config.globalProperties.$uiClient.registerWSEventListener(
+                  'close',
+                  () => {
+                    app!.appContext.config.globalProperties.$chargingStations = []
+                  },
+                  { once: true }
+                )
+                app?.appContext.config.globalProperties.$uiClient.setConfiguration(
                   app?.appContext.config.globalProperties.$configuration.uiServer[
                     getFromLocalStorage<number>('uiServerConfigurationIndex', state.uiServerIndex)
                   ]
                 )
+                app?.appContext.config.globalProperties.$uiClient.registerWSEventListener(
+                  'open',
+                  () => {
+                    loadChargingStations(() => (state.renderChargingStationsList = randomUUID()))
+                  },
+                  { once: true }
+                )
               }
             } catch (error) {
               $toast.error('Error at changing UI server configuration')