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,
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: {

View File

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

View File

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