refactor(ui): refine action bar style
[e-mobility-charging-stations-simulator.git] / ui / web / src / main.ts
index bb42f57690273dd5c88115fd1f6228520f549725..25f92db011de67480df34a95dc48c33dec318b94 100644 (file)
@@ -1,10 +1,10 @@
 import { createApp } from 'vue'
 import ToastPlugin from 'vue-toast-notification'
-import type { ConfigurationData, ResponsePayload } from './types'
+import type { ConfigurationData, ResponsePayload } from '@/types'
 import { router } from '@/router'
 import { UIClient } from '@/composables'
 import App from '@/App.vue'
-import 'vue-toast-notification/dist/theme-default.css'
+import 'vue-toast-notification/dist/theme-bootstrap.css'
 
 const initializeApp = (config: ConfigurationData) => {
   const app = createApp(App)
@@ -14,7 +14,11 @@ const initializeApp = (config: ConfigurationData) => {
     console.info('Error info:', info)
     // TODO: add code for UI notifications or other error handling logic
   }
-  app.config.globalProperties.$uiClient = UIClient.getInstance(config)
+  app.config.globalProperties.$configuration = config
+  app.config.globalProperties.$chargingStations = []
+  app.config.globalProperties.$uiClient = UIClient.getInstance(
+    app.config.globalProperties.$configuration.uiServer
+  )
   app.config.globalProperties.$uiClient.registerWSEventListener('open', () => {
     app.config.globalProperties.$uiClient
       .listChargingStations()
@@ -24,7 +28,6 @@ const initializeApp = (config: ConfigurationData) => {
       .catch((error: Error) => {
         // TODO: add code for UI notifications or other error handling logic
         console.error('Error at fetching charging stations:', error)
-        throw error
       })
       .finally(() => {
         app.use(router).use(ToastPlugin).mount('#app')
@@ -33,15 +36,23 @@ const initializeApp = (config: ConfigurationData) => {
 }
 
 fetch('/config.json')
-  .then(response => response.json())
-  .catch(error => {
-    console.error('Error at fetching app configuration:', error)
-    throw error
-  })
-  .then(config => {
-    initializeApp(config)
+  .then(response => {
+    if (!response.ok) {
+      // TODO: add code for UI notifications or other error handling logic
+      console.error('Failed to fetch app configuration')
+      return
+    }
+    response
+      .json()
+      .then(config => {
+        initializeApp(config)
+      })
+      .catch(error => {
+        // TODO: add code for UI notifications or other error handling logic
+        console.error('Error at app configuration JSON deserialization:', error)
+      })
   })
   .catch(error => {
-    console.error('Error at initializing app:', error)
-    throw error
+    // TODO: add code for UI notifications or other error handling logic
+    console.error('Error at fetching app configuration:', error)
   })