From 431b3f527deb318b723e3d2a41f560b970697dff Mon Sep 17 00:00:00 2001 From: lain Date: Tue, 7 Jul 2020 14:39:43 +0200 Subject: [PATCH 1/2] StaffPanel: Move staff loading to panel creation. --- src/boot/after_store.js | 1 - src/components/staff_panel/staff_panel.js | 4 ++++ src/modules/users.js | 5 +++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/boot/after_store.js b/src/boot/after_store.js index 47524112..302b278c 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -215,7 +215,6 @@ const getAppSecret = async ({ store }) => { const resolveStaffAccounts = ({ store, accounts }) => { const nicknames = accounts.map(uri => uri.split('/').pop()) - nicknames.map(nickname => store.dispatch('fetchUser', nickname)) store.dispatch('setInstanceOption', { name: 'staffAccounts', value: nicknames }) } diff --git a/src/components/staff_panel/staff_panel.js b/src/components/staff_panel/staff_panel.js index 4f98fff6..8c2abcd8 100644 --- a/src/components/staff_panel/staff_panel.js +++ b/src/components/staff_panel/staff_panel.js @@ -2,6 +2,10 @@ import map from 'lodash/map' import BasicUserCard from '../basic_user_card/basic_user_card.vue' const StaffPanel = { + created() { + const nicknames = this.$store.state.instance.staffAccounts + nicknames.forEach(nickname => this.$store.dispatch('fetchUserIfMissing', nickname)) + }, components: { BasicUserCard }, diff --git a/src/modules/users.js b/src/modules/users.js index 68d02931..7e136c61 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -266,6 +266,11 @@ const users = { mutations, getters, actions: { + fetchUserIfMissing (store, id) { + if (!store.getters.findUser(id)) { + store.dispatch('fetchUser', id) + } + }, fetchUser (store, id) { return store.rootState.api.backendInteractor.fetchUser({ id }) .then((user) => { From 7d881d97fe7ac96ecfa58b18a87b5d9379858b4c Mon Sep 17 00:00:00 2001 From: Shpuld Shpludson Date: Tue, 7 Jul 2020 12:44:29 +0000 Subject: [PATCH 2/2] Apply suggestion to src/components/staff_panel/staff_panel.js --- src/components/staff_panel/staff_panel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/staff_panel/staff_panel.js b/src/components/staff_panel/staff_panel.js index 8c2abcd8..8665648a 100644 --- a/src/components/staff_panel/staff_panel.js +++ b/src/components/staff_panel/staff_panel.js @@ -2,7 +2,7 @@ import map from 'lodash/map' import BasicUserCard from '../basic_user_card/basic_user_card.vue' const StaffPanel = { - created() { + created () { const nicknames = this.$store.state.instance.staffAccounts nicknames.forEach(nickname => this.$store.dispatch('fetchUserIfMissing', nickname)) },