refactor(ui): trivial code cleanup
[e-mobility-charging-stations-simulator.git] / ui / web / src / views / ChargingStationsView.vue
1 <template>
2 <Container id="charging-stations">
3 <Button id="simulator-button" @click="startSimulator()">Start Simulator</Button>
4 <Button id="simulator-button" @click="stopSimulator()">Stop Simulator</Button>
5 <Container id="inputs-container">
6 <input
7 id="idtag-field"
8 v-model="state.idTag"
9 type="text"
10 name="idtag-field"
11 placeholder="RFID tag"
12 />
13 <ReloadButton id="reload-button" :loading="state.isLoading" @click="load()" />
14 </Container>
15 <CSTable :charging-stations="state.chargingStations" :id-tag="state.idTag" />
16 </Container>
17 </template>
18
19 <script setup lang="ts">
20 import { getCurrentInstance, onMounted, reactive } from 'vue'
21 import CSTable from '@/components/charging-stations/CSTable.vue'
22 import type { ChargingStationData } from '@/types'
23 import Container from '@/components/Container.vue'
24 import ReloadButton from '@/components/buttons/ReloadButton.vue'
25
26 const UIClient = getCurrentInstance()?.appContext.config.globalProperties.$UIClient
27
28 onMounted(() => {
29 UIClient.registerWSonOpenListener(load)
30 })
31
32 type State = {
33 isLoading: boolean
34 chargingStations: ChargingStationData[]
35 idTag: string
36 }
37
38 const state: State = reactive({
39 isLoading: false,
40 chargingStations: [],
41 idTag: ''
42 })
43
44 async function load(): Promise<void> {
45 if (state.isLoading === false) {
46 state.isLoading = true
47 state.chargingStations = (await UIClient.listChargingStations())
48 .chargingStations as ChargingStationData[]
49 state.isLoading = false
50 }
51 }
52
53 function startSimulator(): void {
54 UIClient.startSimulator()
55 }
56 function stopSimulator(): void {
57 UIClient.stopSimulator()
58 }
59 </script>
60
61 <style>
62 #charging-stations {
63 height: fit-content;
64 width: 100%;
65 background-color: rgb(233, 227, 227);
66 display: flex;
67 flex-direction: column;
68 }
69
70 #inputs-container {
71 display: flex;
72 justify-content: space-between;
73 }
74
75 #reload-button {
76 flex: auto;
77 background-color: rgb(25, 118, 210);
78 color: white;
79 font-size: 35px;
80 font-weight: bold;
81 }
82
83 #reload-button:hover {
84 background-color: rgb(10, 113, 195);
85 }
86
87 #reload-button:active {
88 background-color: rgb(255, 113, 195);
89 }
90
91 #simulator-button {
92 flex: auto;
93 }
94
95 #idtag-field {
96 flex: auto;
97 text-align: center;
98 }
99 </style>