Commit | Line | Data |
---|---|---|
66a7748d | 1 | import { createApp } from 'vue' |
57c0ba05 | 2 | import type { ConfigurationData, ResponsePayload } from './types' |
13c19b7b | 3 | import { router } from '@/router' |
9d76f5ec JB |
4 | import { UIClient } from '@/composables' |
5 | import App from '@/App.vue' | |
32de5a57 | 6 | |
57c0ba05 | 7 | const 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 JB |
15 | app.config.globalProperties.$uiClient = UIClient.getInstance(config) |
16 | app.config.globalProperties.$uiClient.registerWSonOpenListener(async () => { | |
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 | |
32 | fetch('/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 | }) |