UI: Streamline initial load

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
This commit is contained in:
Marcel Klehr 2023-08-17 14:13:29 +02:00
parent 205ed69552
commit 81366e8ae1
3 changed files with 20 additions and 17 deletions

View File

@ -66,6 +66,7 @@ export default {
showDetails: false, showDetails: false,
smallScreen: false, smallScreen: false,
showWhatsnew: false, showWhatsnew: false,
initialLoad: false,
} }
}, },
computed: { computed: {
@ -85,18 +86,14 @@ export default {
watch: { watch: {
$route: 'onRoute', $route: 'onRoute',
async showFolderOverview(value) { async showFolderOverview(value) {
// hack to make bookmarkslist rerender if (!this.initialLoad) {
await this.$store.dispatch(actions.SET_SETTING, { // hack to make bookmarkslist rerender
key: 'viewMode', await this.$store.dispatch(actions.RELOAD_VIEW)
value: this.$store.state.viewMode === 'grid' ? 'list' : 'grid', }
})
await this.$store.dispatch(actions.SET_SETTING, {
key: 'viewMode',
value: this.$store.state.viewMode === 'grid' ? 'list' : 'grid',
})
}, },
}, },
async created() { async created() {
this.initialLoad = true
const mediaQuery = window.matchMedia('(max-width: 1024px)') const mediaQuery = window.matchMedia('(max-width: 1024px)')
this.smallScreen = mediaQuery.matches this.smallScreen = mediaQuery.matches
mediaQuery.addEventListener('change', this.onWindowFormatChange) mediaQuery.addEventListener('change', this.onWindowFormatChange)
@ -105,10 +102,12 @@ export default {
// legacy search pre nc v20 // legacy search pre nc v20
this.search = new window.OCA.Search(this.onSearch, this.onResetSearch) this.search = new window.OCA.Search(this.onSearch, this.onResetSearch)
} }
// set loading indicator // set loading indicator
this.$store.commit(mutations.FETCH_START, { type: 'bookmarks' }) this.$store.commit(mutations.FETCH_START, { type: 'bookmarks' })
await this.reloadSettings() await this.reloadSettings()
this.onRoute() this.onRoute()
this.reloadFolders() this.reloadFolders()
this.reloadSharedFolders() this.reloadSharedFolders()
@ -124,6 +123,7 @@ export default {
this.$store.commit(mutations.SET_NOTIFICATION, t('bookmarks', 'Network access is disabled by default. Go to administrator settings for the bookmarks app to allow fetching previews and favicons.')) this.$store.commit(mutations.SET_NOTIFICATION, t('bookmarks', 'Network access is disabled by default. Go to administrator settings for the bookmarks app to allow fetching previews and favicons.'))
} }
} }
this.initialLoad = false
}, },
methods: { methods: {

View File

@ -994,18 +994,18 @@ export default {
return dispatch(actions.FETCH_PAGE) return dispatch(actions.FETCH_PAGE)
}, },
[actions.FETCH_PAGE]({ dispatch, commit, state }) { async [actions.FETCH_PAGE]({ dispatch, commit, state }) {
if (state.fetchState.reachedEnd) return if (state.fetchState.reachedEnd) return
if (state.loading.bookmarks) return if (state.loading.bookmarks) return
let canceled = false let canceled = false
const fetchedPage = state.fetchState.page const fetchedPage = state.fetchState.page
commit(mutations.FETCH_START, { await commit(mutations.FETCH_START, {
type: 'bookmarks', type: 'bookmarks',
cancel() { cancel() {
canceled = true canceled = true
}, },
}) })
axios return axios
.get(url(state, '/bookmark'), { .get(url(state, '/bookmark'), {
params: { params: {
limit: BATCH_SIZE, limit: BATCH_SIZE,
@ -1133,7 +1133,7 @@ export default {
throw err throw err
}) })
}, },
[actions.LOAD_SETTINGS]({ commit, dispatch, state }) { async [actions.LOAD_SETTINGS]({ commit, dispatch, state }) {
const settings = loadState('bookmarks', 'settings') const settings = loadState('bookmarks', 'settings')
for (const setting in settings) { for (const setting in settings) {
const key = setting const key = setting
@ -1141,14 +1141,14 @@ export default {
switch (key) { switch (key) {
case 'viewMode': case 'viewMode':
value = value || state.settings.viewMode value = value || state.settings.viewMode
commit(mutations.SET_VIEW_MODE, value) await commit(mutations.SET_VIEW_MODE, value)
break break
case 'sorting': case 'sorting':
value = value || state.settings.sorting value = value || state.settings.sorting
commit(mutations.RESET_PAGE) await commit(mutations.RESET_PAGE)
break break
} }
commit(mutations.SET_SETTING, { key, value }) await commit(mutations.SET_SETTING, { key, value })
} }
['archivePath', 'backupPath', 'backupEnabled', 'limit'].forEach(key => ['archivePath', 'backupPath', 'backupEnabled', 'limit'].forEach(key =>
dispatch(actions.LOAD_SETTING, key) dispatch(actions.LOAD_SETTING, key)

View File

@ -27,7 +27,10 @@ export default {
authToken: null, authToken: null,
fetchState: { fetchState: {
page: 0, page: 0,
query: {}, query: {
// Set home filter to avoid trying to load *all* bookmark initially until onRoute is called
folder: -1,
},
reachedEnd: false, reachedEnd: false,
}, },
loading: { loading: {