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