feat: defer everything until the api config is loaded #926

Merged
konrad merged 27 commits from feature/ready-state into main 2021-11-13 19:49:03 +00:00
3 changed files with 7 additions and 3 deletions
Showing only changes of commit 817372b751 - Show all commits

View File

@ -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
Review

Explain why we return here

Explain why we return here
if (url === '') {
// If the config setter function could not figure out a url
konrad marked this conversation as resolved Outdated

That seems like it should throw an error? (2)

That seems like it should throw an error? (2)

View File

@ -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

Since updateConfig is always () => dispatch('config/update'):
Shouldn't we just import he store in this file and call dispatch('config/update') directly?

Since `updateConfig` is always `() => dispatch('config/update')`: Shouldn't we just import he store in this file and call `dispatch('config/update')` directly?

Will that work outside of a vue component?

Will that work outside of a vue component?

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)

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)

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://') &&

View File

@ -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)
},