From 81366e8ae11ea109f598fa504644842b42348fa5 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Thu, 17 Aug 2023 14:13:29 +0200 Subject: [PATCH] UI: Streamline initial load Signed-off-by: Marcel Klehr --- src/components/ViewPrivate.vue | 18 +++++++++--------- src/store/actions.js | 14 +++++++------- src/store/index.js | 5 ++++- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/components/ViewPrivate.vue b/src/components/ViewPrivate.vue index e2ab8bbe..b33c1643 100644 --- a/src/components/ViewPrivate.vue +++ b/src/components/ViewPrivate.vue @@ -66,6 +66,7 @@ export default { showDetails: false, smallScreen: false, showWhatsnew: false, + initialLoad: false, } }, computed: { @@ -85,18 +86,14 @@ export default { watch: { $route: 'onRoute', async showFolderOverview(value) { - // hack to make bookmarkslist rerender - await this.$store.dispatch(actions.SET_SETTING, { - key: 'viewMode', - 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', - }) + if (!this.initialLoad) { + // hack to make bookmarkslist rerender + await this.$store.dispatch(actions.RELOAD_VIEW) + } }, }, async created() { + this.initialLoad = true const mediaQuery = window.matchMedia('(max-width: 1024px)') this.smallScreen = mediaQuery.matches mediaQuery.addEventListener('change', this.onWindowFormatChange) @@ -105,10 +102,12 @@ export default { // legacy search pre nc v20 this.search = new window.OCA.Search(this.onSearch, this.onResetSearch) } + // set loading indicator this.$store.commit(mutations.FETCH_START, { type: 'bookmarks' }) await this.reloadSettings() + this.onRoute() this.reloadFolders() 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.initialLoad = false }, methods: { diff --git a/src/store/actions.js b/src/store/actions.js index f9e7a1e9..d63a25e8 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -994,18 +994,18 @@ export default { 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.loading.bookmarks) return let canceled = false const fetchedPage = state.fetchState.page - commit(mutations.FETCH_START, { + await commit(mutations.FETCH_START, { type: 'bookmarks', cancel() { canceled = true }, }) - axios + return axios .get(url(state, '/bookmark'), { params: { limit: BATCH_SIZE, @@ -1133,7 +1133,7 @@ export default { throw err }) }, - [actions.LOAD_SETTINGS]({ commit, dispatch, state }) { + async [actions.LOAD_SETTINGS]({ commit, dispatch, state }) { const settings = loadState('bookmarks', 'settings') for (const setting in settings) { const key = setting @@ -1141,14 +1141,14 @@ export default { switch (key) { case 'viewMode': value = value || state.settings.viewMode - commit(mutations.SET_VIEW_MODE, value) + await commit(mutations.SET_VIEW_MODE, value) break case 'sorting': value = value || state.settings.sorting - commit(mutations.RESET_PAGE) + await commit(mutations.RESET_PAGE) break } - commit(mutations.SET_SETTING, { key, value }) + await commit(mutations.SET_SETTING, { key, value }) } ['archivePath', 'backupPath', 'backupEnabled', 'limit'].forEach(key => dispatch(actions.LOAD_SETTING, key) diff --git a/src/store/index.js b/src/store/index.js index 5c530859..8ff93a7c 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -27,7 +27,10 @@ export default { authToken: null, fetchState: { page: 0, - query: {}, + query: { + // Set home filter to avoid trying to load *all* bookmark initially until onRoute is called + folder: -1, + }, reachedEnd: false, }, loading: {