From a443f9431eba89fbff54557d16b6c4298082d7c2 Mon Sep 17 00:00:00 2001 From: Eliot Berriot Date: Thu, 21 Jun 2018 23:26:17 +0200 Subject: [PATCH] See #190: now store sidebar notifications in vuex store --- front/src/components/Sidebar.vue | 48 +++++++------------------------- front/src/store/ui.js | 28 ++++++++++++++++++- 2 files changed, 37 insertions(+), 39 deletions(-) diff --git a/front/src/components/Sidebar.vue b/front/src/components/Sidebar.vue index 87c374a33..065a0a03a 100644 --- a/front/src/components/Sidebar.vue +++ b/front/src/components/Sidebar.vue @@ -58,21 +58,16 @@
{{ $t('Administration') }}
import {mapState, mapActions} from 'vuex' -import axios from 'axios' import Player from '@/components/audio/Player' import Logo from '@/components/Logo' @@ -183,11 +177,7 @@ export default { selectedTab: 'library', backend: backend, isCollapsed: true, - fetchInterval: null, - notifications: { - federation: 0, - importRequests: 0 - } + fetchInterval: null } }, mounted () { @@ -224,26 +214,8 @@ export default { cleanTrack: 'queue/cleanTrack' }), fetchNotificationsCount () { - this.fetchFederationNotificationsCount() - this.fetchFederationImportRequestsCount() - }, - fetchFederationNotificationsCount () { - if (!this.$store.state.auth.availablePermissions['federation']) { - return - } - let self = this - axios.get('federation/libraries/followers/', {params: {pending: true}}).then(response => { - self.notifications.federation = response.data.count - }) - }, - fetchFederationImportRequestsCount () { - if (!this.$store.state.auth.availablePermissions['library']) { - return - } - let self = this - axios.get('requests/import-requests/', {params: {status: 'pending'}}).then(response => { - self.notifications.importRequests = response.data.count - }) + this.$store.dispatch('ui/fetchFederationNotificationsCount') + this.$store.dispatch('ui/fetchImportRequestsCount') }, reorder: function (event) { this.$store.commit('queue/reorder', { diff --git a/front/src/store/ui.js b/front/src/store/ui.js index be744afe5..c33680347 100644 --- a/front/src/store/ui.js +++ b/front/src/store/ui.js @@ -1,3 +1,4 @@ +import axios from 'axios' export default { namespaced: true, @@ -5,7 +6,11 @@ export default { lastDate: new Date(), maxMessages: 100, messageDisplayDuration: 10000, - messages: [] + messages: [], + notifications: { + federation: 0, + importRequests: 0 + } }, mutations: { computeLastDate: (state) => { @@ -16,6 +21,27 @@ export default { if (state.messages.length > state.maxMessages) { state.messages.shift() } + }, + notifications (state, {type, count}) { + state.notifications[type] = count + } + }, + actions: { + fetchFederationNotificationsCount ({rootState, commit}) { + if (!rootState.auth.availablePermissions['federation']) { + return + } + axios.get('federation/libraries/followers/', {params: {pending: true}}).then(response => { + commit('notifications', {type: 'federation', count: response.data.count}) + }) + }, + fetchImportRequestsCount ({rootState, commit}) { + if (!rootState.auth.availablePermissions['library']) { + return + } + axios.get('requests/import-requests/', {params: {status: 'pending'}}).then(response => { + commit('notifications', {type: 'importRequests', count: response.data.count}) + }) } } }