Skip to content

Commit

Permalink
Merge pull request #3444 from nextcloud/fix/add-visual-feedback-loadi…
Browse files Browse the repository at this point in the history
…ng-master

fix: Add visual loading feedback for polls list
  • Loading branch information
artonge authored Apr 24, 2024
2 parents 8d5201c + 96aae76 commit 8102a56
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
8 changes: 8 additions & 0 deletions src/js/store/modules/polls.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const state = {
isPollCreationAllowed: false,
isComboAllowed: false,
currentCategoryId: 'all',
pollsLoading: false,
sort: {
by: 'created',
reverse: true,
Expand Down Expand Up @@ -141,6 +142,10 @@ const mutations = {
Object.assign(state, payload)
},

setLoading(state, loading) {
state.pollsLoading = loading ?? true
},

setFilter(state, payload) {
state.currentCategoryId = payload.currentCategoryId
},
Expand Down Expand Up @@ -195,6 +200,7 @@ const actions = {
async list(context) {

try {
context.commit('setLoading')
const response = await PollsAPI.getPolls()
context.commit('set', { list: response.data.list })
context.commit('setPollCreationAllowed', { pollCreationAllowed: response.data.pollCreationAllowed })
Expand All @@ -203,6 +209,8 @@ const actions = {
if (e?.code === 'ERR_CANCELED') return
console.error('Error loading polls', { error: e.response })
throw e
} finally {
context.commit('setLoading', false)
}
},
}
Expand Down
22 changes: 10 additions & 12 deletions src/js/views/PollList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@
</HeaderBar>

<div class="area__main">
<NcEmptyContent v-if="noPolls"
<NcEmptyContent v-if="noPolls && isLoading"
:name="t('polls', 'Loading polls…')">
<NcLoadingIcon slot="icon" :size="64" />
</NcEmptyContent>
<NcEmptyContent v-else-if="noPolls"
:name="t('polls', 'No polls found for this category')"
:description="t('polls', 'Add one or change category!')">
<template #icon>
<PollsAppIcon />
</template>
</NcEmptyContent>

<TransitionGroup is="div"
v-else
<TransitionGroup v-else
tag="div"
name="list"
class="poll-list__list">
<PollItem key="0"
Expand Down Expand Up @@ -94,14 +98,13 @@
</PollItem>
</TransitionGroup>
</div>
<LoadingOverlay v-if="isLoading" />
</NcAppContent>
</template>

<script>
import { mapGetters, mapState, mapActions } from 'vuex'
import { showError } from '@nextcloud/dialogs'
import { NcActions, NcActionButton, NcAppContent, NcEmptyContent } from '@nextcloud/vue'
import { NcActions, NcActionButton, NcAppContent, NcEmptyContent, NcLoadingIcon } from '@nextcloud/vue'
import { HeaderBar } from '../components/Base/index.js'
import DeletePollIcon from 'vue-material-design-icons/Delete.vue'
import ClonePollIcon from 'vue-material-design-icons/ContentCopy.vue'
Expand All @@ -117,26 +120,21 @@ export default {
NcActions,
NcActionButton,
NcEmptyContent,
NcLoadingIcon,
HeaderBar,
DeletePollIcon,
ClonePollIcon,
ArchivePollIcon,
RestorePollIcon,
PollsAppIcon,
LoadingOverlay: () => import('../components/Base/modules/LoadingOverlay.vue'),
PollItem: () => import('../components/PollList/PollItem.vue'),
},

data() {
return {
isLoading: false,
}
},

computed: {
...mapState({
pollCategories: (state) => state.polls.categories,
isPollCreationAllowed: (state) => state.polls.isPollCreationAllowed,
isLoading: (state) => state.polls.pollsLoading,
}),

...mapGetters({
Expand Down

0 comments on commit 8102a56

Please sign in to comment.