feat: defer everything until the api config is loaded #926
|
@ -94,7 +94,7 @@ export default {
|
|||
}
|
||||
|
||||
try {
|
||||
const url = await checkAndSetApiUrl(this.apiUrl, () => this.$store.dispatch('config/update'))
|
||||
const url = await checkAndSetApiUrl(this.apiUrl)
|
||||
|
||||
konrad marked this conversation as resolved
|
||||
if (url === '') {
|
||||
// If the config setter function could not figure out a url
|
||||
konrad marked this conversation as resolved
Outdated
dpschen
commented
That seems like it should throw an error? (2) That seems like it should throw an error? (2)
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
import {store} from '@/store'
|
||||
|
||||
const API_DEFAULT_PORT = '3456'
|
||||
|
||||
export const ERROR_NO_API_URL = 'noApiUrlProvided'
|
||||
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.
|
||||
|
||||
export const checkAndSetApiUrl = (url: string, updateConfig: () => Promise<void>): Promise<string> => {
|
||||
const updateConfig = () => store.dispatch('config/update')
|
||||
|
||||
export const checkAndSetApiUrl = (url: string): Promise<string> => {
|
||||
// Check if the url has an http prefix
|
||||
if (
|
||||
!url.startsWith('http://') &&
|
||||
|
|
|
@ -144,7 +144,7 @@ export const store = createStore({
|
|||
commit(CURRENT_LIST, currentList)
|
||||
},
|
||||
async loadApp({commit, dispatch}) {
|
||||
await checkAndSetApiUrl(window.API_URL, () => dispatch('config/update'))
|
||||
await checkAndSetApiUrl(window.API_URL)
|
||||
await dispatch('auth/checkAuth')
|
||||
commit('vikunjaReady', true)
|
||||
},
|
||||
|
|
Reference in New Issue
Explain why we return here