fix: ensure local storage is cleaned at CS deletion
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 22 Nov 2024 15:40:25 +0000 (16:40 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 22 Nov 2024 15:40:25 +0000 (16:40 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
ui/web/src/components/charging-stations/CSData.vue
ui/web/src/views/ChargingStationsView.vue

index c01302b9e102ab7809776b266bd1b8c8219a1ea8..d735ca32dfeac3a7b7f54d027d6fea6e1d26e7b0 100644 (file)
@@ -131,7 +131,7 @@ import type { ChargingStationData, ConnectorStatus, Status } from '@/types'
 import Button from '@/components/buttons/Button.vue'
 import ToggleButton from '@/components/buttons/ToggleButton.vue'
 import CSConnector from '@/components/charging-stations/CSConnector.vue'
-import { useUIClient } from '@/composables'
+import { deleteFromLocalStorage, getLocalStorage, useUIClient } from '@/composables'
 import { useToast } from 'vue-toast-notification'
 
 const props = defineProps<{
@@ -229,6 +229,11 @@ const deleteChargingStation = (): void => {
   uiClient
     .deleteChargingStation(props.chargingStation.stationInfo.hashId)
     .then(() => {
+      for (const key in getLocalStorage()) {
+        if (key.includes(props.chargingStation.stationInfo.hashId)) {
+          deleteFromLocalStorage(key)
+        }
+      }
       return $toast.success('Charging station successfully deleted')
     })
     .catch((error: Error) => {
index b532ba254397275ea40f90b0a29521ad9a0d9d54..603cfdac04deb647121baa65936e410d22585801 100644 (file)
@@ -24,6 +24,7 @@
                   () => {
                     setToLocalStorage<number>('uiServerConfigurationIndex', state.uiServerIndex)
                     clearToggleButtons()
+                    refresh()
                     $route.name !== 'charging-stations' &&
                       $router.push({ name: 'charging-stations' })
                   },
@@ -165,14 +166,17 @@ const state = ref<{
   uiServerIndex: getFromLocalStorage<number>('uiServerConfigurationIndex', 0),
 })
 
+const refresh = (): void => {
+  state.value.renderChargingStations = randomUUID()
+  state.value.renderAddChargingStations = randomUUID()
+}
+
 const clearToggleButtons = (): void => {
   for (const key in getLocalStorage()) {
     if (key.includes('toggle-button')) {
       deleteFromLocalStorage(key)
     }
   }
-  state.value.renderChargingStations = randomUUID()
-  state.value.renderAddChargingStations = randomUUID()
 }
 
 const app = getCurrentInstance()