-const initializeWSEventListeners = () => {
- app?.appContext.config.globalProperties.$uiClient.registerWSEventListener('open', () => {
- getSimulatorState()
- if (state.value.gettingTemplates === false) {
- state.value.gettingTemplates = true
- uiClient
- .listTemplates()
- .then((response: ResponsePayload) => {
- if (app != null) {
- app.appContext.config.globalProperties.$templates = response.templates
- }
- })
- .catch((error: Error) => {
- if (app != null) {
- app.appContext.config.globalProperties.$templates = []
- }
- $toast.error('Error at fetching charging station templates')
- console.error('Error at fetching charging station templates:', error)
- })
- .finally(() => {
- state.value.gettingTemplates = false
- })
- }
- getChargingStations()
- })
- app?.appContext.config.globalProperties.$uiClient.registerWSEventListener(
- 'error',
- clearChargingStations
- )
- app?.appContext.config.globalProperties.$uiClient.registerWSEventListener(
- 'close',
- clearChargingStations
- )
+const getTemplates = (): void => {
+ if (state.value.gettingTemplates === false) {
+ state.value.gettingTemplates = true
+ uiClient
+ .listTemplates()
+ .then((response: ResponsePayload) => {
+ if (app != null) {
+ app.appContext.config.globalProperties.$templates = response.templates
+ }
+ })
+ .catch((error: Error) => {
+ if (app != null) {
+ app.appContext.config.globalProperties.$templates = []
+ }
+ $toast.error('Error at fetching charging station templates')
+ console.error('Error at fetching charging station templates:', error)
+ })
+ .finally(() => {
+ state.value.gettingTemplates = false
+ })
+ }