fix(ui): remove incorrect async on WS open callback
[e-mobility-charging-stations-simulator.git] / ui / web / src / main.ts
CommitLineData
66a7748d 1import { createApp } from 'vue'
57c0ba05 2import type { ConfigurationData, ResponsePayload } from './types'
13c19b7b 3import { router } from '@/router'
9d76f5ec
JB
4import { UIClient } from '@/composables'
5import App from '@/App.vue'
32de5a57 6
57c0ba05 7const initializeApp = (config: ConfigurationData) => {
a64b9a64
JB
8 const app = createApp(App)
9 app.config.errorHandler = (error, instance, info) => {
10 console.error('Error:', error)
11 console.info('Vue instance:', instance)
12 console.info('Error info:', info)
13 // TODO: Add code for UI notifications or other error handling logic
14 }
57c0ba05 15 app.config.globalProperties.$uiClient = UIClient.getInstance(config)
0e60d4cc 16 app.config.globalProperties.$uiClient.registerWSonOpenListener(() => {
57c0ba05
JB
17 app.config.globalProperties.$uiClient
18 .listChargingStations()
19 .then((response: ResponsePayload) => {
20 app.config.globalProperties.$chargingStations = response.chargingStations
21 })
22 .catch((error: Error) => {
23 console.error('Error at fetching charging stations:', error)
24 throw error
25 })
26 .finally(() => {
27 app.use(router).mount('#app')
28 })
29 })
a64b9a64 30}
9d76f5ec
JB
31
32fetch('/config.json')
33 .then(response => response.json())
a64b9a64
JB
34 .catch(error => {
35 console.error('Error at fetching app configuration:', error)
36 throw error
37 })
9d76f5ec 38 .then(config => {
a64b9a64
JB
39 initializeApp(config)
40 })
41 .catch(error => {
42 console.error('Error at initializing app:', error)
9e1d6e03 43 throw error
9d76f5ec 44 })