Challenge modal optimization - remove unnecessary API call - partial fix for #9371 (#9546)

* Attempt to use party data from the store rather than always fetching it from the API

* Move init code to shown() to prevent unnecessary network requests

* Use store party data in getGroup action if possible to save an API call

* Use store data rather than API call for party in challengeModal; remove unnecessary code in guilds:getGroup action

* Create party:getParty action and employ it in Group and ChallengeModal

* Use store instead of action return for party data

* Change how party data is stored
This commit is contained in:
Grayson Gilmore
2018-01-12 14:18:56 -08:00
committed by Sabe Jones
parent 183c90ac3a
commit ce14a9dadb
10 changed files with 46 additions and 37 deletions

View File

@@ -1,5 +1,5 @@
<template lang="pug">
b-modal#challenge-modal(:title="title", size='lg')
b-modal#challenge-modal(:title="title", size='lg', @shown="shown")
.form
.form-group
label
@@ -232,24 +232,7 @@ export default {
groups: [],
};
},
async mounted () {
this.groups = await this.$store.dispatch('guilds:getMyGuilds');
if (this.user.party._id) {
let party = await this.$store.dispatch('guilds:getGroup', {groupId: 'party'});
this.groups.push({
name: party.name,
_id: party._id,
privacy: 'private',
});
}
this.groups.push({
name: this.$t('publicChallengesTitle'),
_id: TAVERN_ID,
});
this.setUpWorkingChallenge();
},
async mounted () {},
watch: {
user () {
if (!this.challenge) this.workingChallenge.leader = this.user._id;
@@ -315,6 +298,25 @@ export default {
},
},
methods: {
async shown () {
this.groups = await this.$store.dispatch('guilds:getMyGuilds');
await this.$store.dispatch('party:getParty');
const party = this.$store.state.party.data;
if (party._id) {
this.groups.push({
name: party.name,
_id: party._id,
privacy: 'private',
});
}
this.groups.push({
name: this.$t('publicChallengesTitle'),
_id: TAVERN_ID,
});
this.setUpWorkingChallenge();
},
setUpWorkingChallenge () {
this.resetWorkingChallenge();