feat: defer everything until the api config is loaded #926
|
@ -44,8 +44,7 @@ import ApiConfig from '@/components/misc/api-config'
|
|||
import NoAuthWrapper from '@/components/misc/no-auth-wrapper'
|
||||
import {mapState} from 'vuex'
|
||||
import {ONLINE} from '@/store/mutation-types'
|
||||
|
||||
const ERROR_NO_API_URL = 'noApiUrlProvided'
|
||||
import {ERROR_NO_API_URL} from '@/helpers/checkAndSetApiUrl'
|
||||
|
||||
export default {
|
||||
name: 'ready',
|
||||
|
@ -76,11 +75,6 @@ export default {
|
|||
},
|
||||
konrad marked this conversation as resolved
Outdated
|
||||
methods: {
|
||||
load() {
|
||||
if (window.API_URL === '') {
|
||||
this.error = ERROR_NO_API_URL
|
||||
return
|
||||
}
|
||||
|
||||
this.$store.dispatch('loadApp')
|
||||
.catch(e => {
|
||||
this.error = e
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
const API_DEFAULT_PORT = '3456'
|
||||
|
||||
export const ERROR_NO_API_URL = 'noApiUrlProvided'
|
||||
|
||||
export const checkAndSetApiUrl = (url: string, updateConfig: () => Promise<void>): Promise<string> => {
|
||||
konrad marked this conversation as resolved
Outdated
dpschen
commented
Since Since `updateConfig` is always `() => dispatch('config/update')`:
Shouldn't we just import he store in this file and call `dispatch('config/update')` directly?
konrad
commented
Will that work outside of a vue component? Will that work outside of a vue component?
dpschen
commented
If you import the store with:
Because it's JS ™️ (trying to steal reacts claim here) If you import the store with:
```
import {store} from '@/store'
// then you can
store.dispatch('config/update')
```
Because it's JS ™️ (trying to steal reacts claim here)
konrad
commented
That seems like a nice way to solve it. Done. That seems like a nice way to solve it. Done.
|
||||
// Check if the url has an http prefix
|
||||
if (
|
||||
|
@ -106,6 +108,7 @@ export const checkAndSetApiUrl = (url: string, updateConfig: () => Promise<void>
|
|||
localStorage.setItem('API_URL', window.API_URL)
|
||||
return window.API_URL
|
||||
}
|
||||
return ''
|
||||
|
||||
throw new Error(ERROR_NO_API_URL)
|
||||
})
|
||||
}
|
||||
|
|
Reference in New Issue
ONLINE
is no mutation type. It's a state.Right, fixed.