hungergames/src/store/actions.js

47 lines
1.1 KiB
JavaScript
Raw Normal View History

import { updateCategories } from '../api';
2017-09-29 18:12:00 +02:00
import * as types from './mutations-types';
import quests from './quests';
export default {
preloadQuests({ commit }) {
2017-11-21 22:11:58 +01:00
const apiRequests = [];
2017-09-29 18:12:00 +02:00
Object.keys(quests).forEach((quest) => {
2017-11-21 22:11:58 +01:00
apiRequests.push(
quests[quest]().then(
items => commit(
types.STORE_QUESTS_ITEMS,
{
type: 'missingCategories',
items,
},
),
2017-09-29 18:12:00 +02:00
),
);
});
2017-11-21 22:11:58 +01:00
return Promise.all(apiRequests);
2017-09-29 18:12:00 +02:00
},
validateQuest({ commit }, { type, id, solution }) {
if (type === 'missingCategories') {
updateCategories(id, solution).then(() => commit(
2017-11-21 22:11:58 +01:00
types.REMOVE_QUEST_ITEM,
{
type,
id,
},
));
}
},
2017-11-21 22:11:58 +01:00
skipQuest({ commit }, { type, id }) {
commit(
types.REMOVE_QUEST_ITEM,
{
type,
id,
},
);
},
2017-09-29 18:12:00 +02:00
};