feat(ui): enhance charging stations list structure
[e-mobility-charging-stations-simulator.git] / ui / web / src / views / ChargingStationsView.vue
index 25ea51d9bc02549c1526725e9f5e92b9fde96e5e..15564785ee2238b555d0f7bac41c1268661abb20 100644 (file)
@@ -5,70 +5,65 @@
     <Container id="inputs-container">
       <input
         id="idtag-field"
+        v-model="state.idTag"
         type="text"
         name="idtag-field"
         placeholder="RFID tag"
-        v-model="state.idTag"
       />
       <ReloadButton id="reload-button" :loading="state.isLoading" @click="load()" />
     </Container>
-    <CSTable :chargingStations="state.chargingStations" :idTag="state.idTag" />
+    <CSTable :charging-stations="state.chargingStations" :id-tag="state.idTag" />
   </Container>
 </template>
 
 <script setup lang="ts">
-import Container from '@/components/Container.vue';
-import ReloadButton from '@/components/buttons/ReloadButton.vue';
-import CSTable from '@/components/charging-stations/CSTable.vue';
+import { getCurrentInstance, onMounted, reactive } from 'vue'
+import CSTable from '@/components/charging-stations/CSTable.vue'
+import type { ChargingStationData } from '@/types'
+import Container from '@/components/Container.vue'
+import ReloadButton from '@/components/buttons/ReloadButton.vue'
 
-import { onMounted, reactive } from 'vue';
-import UIClient from '@/composables/UIClient';
-import type { ChargingStationData } from '@/types/ChargingStationType';
-
-const UIClientInstance = UIClient.getInstance();
+const UIClient = getCurrentInstance()?.appContext.config.globalProperties.$UIClient
 
 onMounted(() => {
-  UIClientInstance.registerWSonOpenListener(load);
-});
+  UIClient.registerWSonOpenListener(load)
+})
 
 type State = {
-  isLoading: boolean;
-  chargingStations: ChargingStationData[];
-  idTag: string;
-};
+  isLoading: boolean
+  chargingStations: ChargingStationData[]
+  idTag: string
+}
 
 const state: State = reactive({
   isLoading: false,
   chargingStations: [],
-  idTag: '',
-});
+  idTag: ''
+})
 
 async function load(): Promise<void> {
-  if (state.isLoading === true) return;
-  state.isLoading = true;
-  const listChargingStationsPayload = await UIClientInstance.listChargingStations();
-  state.chargingStations =
-    listChargingStationsPayload.chargingStations as unknown as ChargingStationData[];
-  state.isLoading = false;
+  if (state.isLoading === false) {
+    state.isLoading = true
+    state.chargingStations = (await UIClient.listChargingStations())
+      .chargingStations as ChargingStationData[]
+    state.isLoading = false
+  }
 }
 
 function startSimulator(): void {
-  UIClientInstance.startSimulator();
+  UIClient.startSimulator()
 }
 function stopSimulator(): void {
-  UIClientInstance.stopSimulator();
+  UIClient.stopSimulator()
 }
 </script>
 
 <style>
 #charging-stations {
-  height: 100%;
+  height: fit-content;
   width: 100%;
-  padding: 30px;
-  background-color: rgb(233, 227, 227);
   display: flex;
   flex-direction: column;
-  gap: 0.5%;
 }
 
 #inputs-container {
@@ -78,20 +73,18 @@ function stopSimulator(): void {
 
 #reload-button {
   flex: auto;
-  padding: 5px 15px;
-  background-color: rgb(25, 118, 210);
-  border-radius: 5px;
   color: white;
+  background-color: blue;
   font-size: 35px;
   font-weight: bold;
 }
 
 #reload-button:hover {
-  background-color: rgb(10, 113, 195);
+  background-color: rgb(0, 0, 225);
 }
 
 #reload-button:active {
-  background-color: rgb(255, 113, 195);
+  background-color: red;
 }
 
 #simulator-button {
@@ -100,5 +93,6 @@ function stopSimulator(): void {
 
 #idtag-field {
   flex: auto;
+  text-align: center;
 }
 </style>