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"> <template lang="pug">
b-modal#challenge-modal(:title="title", size='lg') b-modal#challenge-modal(:title="title", size='lg', @shown="shown")
.form .form
.form-group .form-group
label label
@@ -232,24 +232,7 @@ export default {
groups: [], groups: [],
}; };
}, },
async mounted () { 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();
},
watch: { watch: {
user () { user () {
if (!this.challenge) this.workingChallenge.leader = this.user._id; if (!this.challenge) this.workingChallenge.leader = this.user._id;
@@ -315,6 +298,25 @@ export default {
}, },
}, },
methods: { 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 () { setUpWorkingChallenge () {
this.resetWorkingChallenge(); this.resetWorkingChallenge();

View File

@@ -538,16 +538,14 @@ export default {
return; return;
} }
let group = await this.$store.dispatch('guilds:getGroup', {groupId: this.searchId});
if (this.isParty) { if (this.isParty) {
this.$store.state.party.data = group; await this.$store.dispatch('party:getParty');
this.group = this.$store.state.party.data; this.group = this.$store.state.party.data;
this.checkForAchievements(); this.checkForAchievements();
return; } else {
} const group = await this.$store.dispatch('guilds:getGroup', {groupId: this.searchId});
this.$set(this, 'group', group); this.$set(this, 'group', group);
}
}, },
deleteAllMessages () { deleteAllMessages () {
if (confirm(this.$t('confirmDeleteAllMessages'))) { if (confirm(this.$t('confirmDeleteAllMessages'))) {

View File

@@ -173,7 +173,7 @@ export default {
computed: { computed: {
...mapState({ ...mapState({
user: 'user.data', user: 'user.data',
partyMembers: 'party.members.data', partyMembers: 'partyMembers.data',
}), }),
questData () { questData () {
return quests.quests[this.group.quest.key]; return quests.quests[this.group.quest.key];

View File

@@ -132,7 +132,7 @@ export default {
computed: { computed: {
...mapGetters({ ...mapGetters({
user: 'user:data', user: 'user:data',
partyMembers: 'party:members', partyMembers: 'partyMembers',
}), }),
showHeader () { showHeader () {

View File

@@ -30,7 +30,7 @@ export default {
return; return;
} }
let party = this.$store.state.party.members; let party = this.$store.state.partyMembers;
party = isArray(party) ? party : []; party = isArray(party) ? party : [];
party = party.concat(this.user); party = party.concat(this.user);
this.castEnd(party, spell.target); this.castEnd(party, spell.target);

View File

@@ -38,12 +38,11 @@ export async function getMyGuilds (store) {
export async function getGroup (store, payload) { export async function getGroup (store, payload) {
let response = await axios.get(`/api/v3/groups/${payload.groupId}`); let response = await axios.get(`/api/v3/groups/${payload.groupId}`);
// @TODO: should we store the active group for modifying? // @TODO: should we store the active group for modifying?
// let guilds = response.data.data; // let guilds = response.data.data;
// store.state.myGuilds = guilds; // store.state.myGuilds = guilds;
// @TODO: Populate wiht members, challenges, and invites // @TODO: Populate with members, challenges, and invites
return response.data.data; return response.data.data;
} }

View File

@@ -3,7 +3,7 @@ import { loadAsyncResource } from 'client/libs/asyncResource';
export function getMembers (store, forceLoad = false) { export function getMembers (store, forceLoad = false) {
return loadAsyncResource({ return loadAsyncResource({
store, store,
path: 'party.members', path: 'partyMembers',
url: '/api/v3/groups/party/members?includeAllPublicFields=true', url: '/api/v3/groups/party/members?includeAllPublicFields=true',
deserialize (response) { deserialize (response) {
return response.data.data; return response.data.data;
@@ -11,3 +11,15 @@ export function getMembers (store, forceLoad = false) {
forceLoad, forceLoad,
}); });
} }
export function getParty (store, forceLoad = false) {
return loadAsyncResource({
store,
path: 'party',
url: '/api/v3/groups/party',
deserialize (response) {
return response.data.data;
},
forceLoad,
});
}

View File

@@ -8,7 +8,7 @@ export async function sendAction (store, payload) {
// @TODO: Maybe move this to server // @TODO: Maybe move this to server
let partyData = { let partyData = {
partyID: store.state.user.data.party._id, partyID: store.state.user.data.party._id,
partySize: store.state.party.members.data.length, partySize: store.state.partyMembers.data.length,
}; };
if (store.state.party && store.state.party.data) { if (store.state.party && store.state.party.data) {

View File

@@ -1,3 +1,3 @@
export function members (store) { export function members (store) {
return store.state.party.members.data; return store.state.partyMembers.data;
} }

View File

@@ -71,10 +71,8 @@ export default function () {
browserTimezoneOffset, browserTimezoneOffset,
tasks: asyncResourceFactory(), // user tasks tasks: asyncResourceFactory(), // user tasks
completedTodosStatus: 'NOT_LOADED', completedTodosStatus: 'NOT_LOADED',
party: { party: asyncResourceFactory(),
quest: {}, partyMembers: asyncResourceFactory(),
members: asyncResourceFactory(),
},
shops: { shops: {
market: asyncResourceFactory(), market: asyncResourceFactory(),
quests: asyncResourceFactory(), quests: asyncResourceFactory(),