fix(ui): fix charging stations refresh
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 17 Feb 2024 22:15:01 +0000 (23:15 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 17 Feb 2024 22:15:01 +0000 (23:15 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
ui/web/src/components/actions/AddChargingStations.vue
ui/web/src/views/ChargingStationsView.vue

index b1409bb714087e40c98900c20f2a415b42dedb0e..94879da1c0d089512b144c57e4b01f1d3f7e49e2 100644 (file)
@@ -9,11 +9,17 @@ const app = getCurrentInstance()
 const uiClient = app?.appContext.config.globalProperties.$uiClient
 
 onMounted(() => {
-  uiClient.listTemplates().then((response: ResponsePayload) => {
-    if (app != null && app.appContext.config.globalProperties.$templates == null) {
-      app.appContext.config.globalProperties.$templates = response.templates
-    }
-  })
+  uiClient
+    .listTemplates()
+    .then((response: ResponsePayload) => {
+      if (app != null && app.appContext.config.globalProperties.$templates == null) {
+        app.appContext.config.globalProperties.$templates = response.templates
+      }
+    })
+    .catch((error: Error) => {
+      // TODO: add code for UI notifications or other error handling logic
+      console.error('Error at fetching charging station templates:', error)
+    })
 })
 </script>
 
index f5757248a07d5afdeb322937b75f909d4db8ab1e..5e0ce534e85691554e9230986d539793df2ba32e 100644 (file)
@@ -3,13 +3,13 @@
     <Container id="buttons-container">
       <Button id="simulator-button" @click="startSimulator()">Start Simulator</Button>
       <Button id="simulator-button" @click="stopSimulator()">Stop Simulator</Button>
-      <ReloadButton id="reload-button" :loading="state.isLoading" @click="loadChargingStations()" />
+      <ReloadButton
+        id="reload-button"
+        :loading="state.isLoading"
+        @click="loadChargingStations(() => $router.go(0))"
+      />
     </Container>
-    <CSTable
-      :charging-stations="
-        getCurrentInstance()?.appContext.config.globalProperties.$chargingStations ?? []
-      "
-    />
+    <CSTable :charging-stations="app?.appContext.config.globalProperties.$chargingStations ?? []" />
   </Container>
 </template>
 
@@ -28,7 +28,7 @@ const state = reactive({
 const app = getCurrentInstance()
 const uiClient = app?.appContext.config.globalProperties.$uiClient
 
-function loadChargingStations(): void {
+function loadChargingStations(reloadCallback?: () => void): void {
   if (state.isLoading === false) {
     state.isLoading = true
     uiClient
@@ -43,6 +43,9 @@ function loadChargingStations(): void {
         console.error('Error at fetching charging stations:', error)
       })
       .finally(() => {
+        if (reloadCallback != null) {
+          reloadCallback()
+        }
         state.isLoading = false
       })
   }