Skip to content

Commit

Permalink
refactor(vuex): refactor loading states for collective and pagelist
Browse files Browse the repository at this point in the history
Aim to only show loading indicators when content is loaded for the
first time, to be less disruptive.

Signed-off-by: Jonas <[email protected]>
  • Loading branch information
mejo- committed Jul 17, 2023
1 parent 340383b commit ecb5648
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 22 deletions.
10 changes: 5 additions & 5 deletions src/components/Collective.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<NcAppContentDetails>
<Version v-if="currentPage && version" />
<Page v-else-if="currentPage && !loading('collective')" />
<SkeletonLoading v-else-if="loading('collective') || loading('page')" :count="1" type="page-heading" />
<SkeletonLoading v-if="loading('collective') || loading('currentPage')" :count="1" type="page-heading" />
<Version v-else-if="currentPage && version" />
<Page v-else-if="currentPage" />
<PageNotFound v-else />
</NcAppContentDetails>
</template>
Expand Down Expand Up @@ -57,7 +57,7 @@ export default {
]),
notFound() {
return !this.loading('collective') && !this.loading('pagelist') && !this.currentPage
return !this.loading('collective') && !this.currentPage
},
},
Expand Down Expand Up @@ -125,7 +125,7 @@ export default {
},
handleNetworkOnline() {
this.getPages()
this.getPagesBackground()
console.debug('Network is online.')
this._setPollingInterval(this.pollIntervalBase)
},
Expand Down
5 changes: 3 additions & 2 deletions src/components/Page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ import TextEditor from './Page/TextEditor.vue'
import { mapActions, mapGetters, mapMutations } from 'vuex'
import pageMixin from '../mixins/pageMixin.js'
import { showError } from '@nextcloud/dialogs'
import { RENAME_PAGE } from '../store/actions.js'
import { GET_PAGES, RENAME_PAGE } from '../store/actions.js'
export default {
name: 'Page',
Expand Down Expand Up @@ -243,6 +243,7 @@ export default {
]),
...mapActions({
dispatchGetPages: GET_PAGES,
dispatchRenamePage: RENAME_PAGE,
}),
Expand Down Expand Up @@ -286,7 +287,7 @@ export default {
await this.dispatchRenamePage(this.newTitle)
// The resulting title may be different due to sanitizing
this.newTitle = this.currentPage.title
this.dispatchGetPages()
this.dispatchGetPages(false)
} catch (e) {
console.error(e)
showError(t('collectives', 'Could not rename the page'))
Expand Down
2 changes: 0 additions & 2 deletions src/components/Page/TextEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import Editor from './Editor.vue'
import RichText from './RichText.vue'
import { mapActions, mapGetters, mapMutations } from 'vuex'
import {
GET_PAGES,
GET_VERSIONS,
TOUCH_PAGE,
} from '../../store/actions.js'
Expand Down Expand Up @@ -126,7 +125,6 @@ export default {
...mapActions({
dispatchTouchPage: TOUCH_PAGE,
dispatchGetPages: GET_PAGES,
dispatchGetVersions: GET_VERSIONS,
}),
Expand Down
4 changes: 2 additions & 2 deletions src/components/PageList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
</NcActionButton>
</NcActions>
</div>
<div v-if="loading('collective') || loading('pagelist')" class="page-list">
<div v-if="!currentCollective || !collectivePage || loading('collective')" class="page-list">
<SkeletonLoading type="items" :count="3" />
</div>
<div v-if="!loading('collective') && currentCollective && collectivePage" class="page-list">
<div v-else class="page-list">
<Item key="Readme"
:to="currentCollectivePath"
:page-id="collectivePage.id"
Expand Down
8 changes: 4 additions & 4 deletions src/mixins/pageMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default {
}

// Parents location changes when the first subpage is created.
this.dispatchGetPages()
this.dispatchGetPages(false)
} catch (e) {
console.error(e)
showError(t('collectives', 'Could not create the page'))
Expand All @@ -97,7 +97,7 @@ export default {
this.$nextTick(() => scrollToPage(this.newPageId))

// Parents location changes when the first subpage is created.
this.dispatchGetPages()
this.dispatchGetPages(false)
} catch (e) {
console.error(e)
showError(t('collectives', 'Could not create the page'))
Expand Down Expand Up @@ -139,14 +139,14 @@ export default {

// Move subpage to new parent
try {
this.load('page')
this.load('currentPage')
await this.dispatchMovePage({ newParentId, pageId, index: newIndex })
} catch (e) {
console.error(e)
showError(t('collectives', 'Could not move page'))
return
} finally {
this.done('page')
this.done('currentPage')
}

// Redirect to new page path if currentPage got moved
Expand Down
2 changes: 1 addition & 1 deletion src/store/circles.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default {

if (collective.id === getters.currentCollective?.id) {
// Update page list, properties like `collectivePath` might have changed
await dispatch(GET_PAGES)
await dispatch(GET_PAGES, false)
await dispatch(GET_TRASH_PAGES)
}
commit(PATCH_COLLECTIVE_WITH_CIRCLE, response.data.ocs.data)
Expand Down
6 changes: 0 additions & 6 deletions src/store/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,8 @@ export default {
* @param {number} pageId Page ID
*/
async [GET_PAGE]({ commit, getters, state }, { parentId, pageId }) {
commit('load', 'page')
const response = await axios.get(getters.pageUrl(parentId, pageId))
commit(UPDATE_PAGE, response.data.data)
commit('done', 'page')
},

/**
Expand Down Expand Up @@ -572,12 +570,10 @@ export default {
* @param {string} newTitle new title for the page
*/
async [RENAME_PAGE]({ commit, getters }, newTitle) {
commit('load', 'page')
const page = getters.currentPage
const url = getters.pageUrl(page.parentId, page.id)
const response = await axios.put(url, { title: newTitle })
await commit(UPDATE_PAGE, response.data.data)
commit('done', 'page')
},

/**
Expand Down Expand Up @@ -693,10 +689,8 @@ export default {
* @param {number} page.pageId ID of the page
*/
async [TRASH_PAGE]({ commit, getters }, { parentId, pageId }) {
commit('load', 'page')
const response = await axios.delete(getters.pageUrl(parentId, pageId))
commit(MOVE_PAGE_INTO_TRASH, response.data.data)
commit('done', 'page')
},

/**
Expand Down

0 comments on commit ecb5648

Please sign in to comment.