Most of submit code is OK now, just not yet pushing through API

This commit is contained in:
Lucas Verney 2017-11-17 19:07:02 +01:00
parent b600d97e44
commit a5ed530081
7 changed files with 53 additions and 7 deletions

View File

@ -59,8 +59,14 @@ function missingCategories() {
}
function updateCategories(productId, categories) {
// TODO
console.log(productId, categories);
}
function missingBrands() {
return fetch(`${BASEURL}state/brands-to-be-completed.json`)
return _fetchFromOFFApi(['state/brands-to-be-completed'])
.then(response => response.json())
.then(response => response.products.map(product => ({
id: product.id,
@ -72,7 +78,7 @@ function missingBrands() {
function missingProductName() {
return fetch(`${BASEURL}state/product-name-to-be-completed.json`)
return _fetchFromOFFApi(['state/product-name-to-be-completed'])
.then(response => response.json())
.then(response => response.products.map(product => ({
id: product.id,
@ -83,4 +89,4 @@ function missingProductName() {
}
export { missingBrands, missingCategories, missingProductName };
export { missingBrands, missingCategories, updateCategories, missingProductName };

View File

@ -43,7 +43,7 @@
</v-layout>
<v-layout row>
<v-flex xs12>
<v-btn>submit</v-btn>
<v-btn @click="handleSubmit()">Submit</v-btn>
</v-flex>
</v-layout>
</v-container>
@ -53,12 +53,24 @@
export default {
props: {
data: Object,
onSubmit: Function,
},
data() {
return {
dialog: false,
};
},
methods: {
handleSubmit() {
const okCategories = [];
Object.keys(this.data.predictedCategories).forEach((key) => {
if (this.data.predictedCategories[key].isOk) {
okCategories.push(key);
}
});
this.onSubmit(okCategories);
},
},
};
</script>

View File

@ -1,3 +1,4 @@
import { updateCategories } from '../api';
import * as types from './mutations-types';
import quests from './quests';
@ -17,4 +18,16 @@ export default {
);
});
},
validateQuest({ commit }, { type, id, solution }) {
if (type === 'missingCategories') {
updateCategories(id, solution).then(() => commit(
types.VALIDATE_QUEST,
{
type,
id,
},
));
}
},
};

View File

@ -11,8 +11,10 @@ function popQuest(state) {
if (availableQuests.length === 0) {
return null;
}
const randomQuestsList = pickRandomFromArray(availableQuests);
return pickRandomFromArray(state.questsItems[randomQuestsList]);
const randomQuestsType = pickRandomFromArray(availableQuests);
const randomQuest = pickRandomFromArray(state.questsItems[randomQuestsType]);
randomQuest.type = randomQuestsType;
return randomQuest;
}
export default { popQuest };

View File

@ -1,2 +1,3 @@
export const IS_LOADING_QUESTS = 'IS_LOADING_QUESTS';
export const STORE_QUESTS_ITEMS = 'STORE_QUESTS_ITEMS';
export const VALIDATE_QUEST = 'VALIDATE_QUEST';

View File

@ -14,4 +14,9 @@ export const mutations = {
[types.STORE_QUESTS_ITEMS](state, { type, items }) {
Vue.set(state.questsItems, type, items);
},
[types.VALIDATE_QUEST](state, { id, type }) {
const items = state.questsItems[type];
delete items[id];
Vue.set(state.questsItems, type, items);
},
};

View File

@ -1,5 +1,5 @@
<template>
<QuestMissingCategories v-if="questData" :data="questData" />
<QuestMissingCategories v-if="questData" :data="questData" :onSubmit="validateQuest" />
</template>
<script>
@ -18,6 +18,13 @@ export default {
fetchData() {
this.$store.dispatch('preloadQuests');
},
validateQuest(solution) {
this.$store.dispatch('validateQuest', {
type: this.questData.type,
id: this.questData.id,
solution,
});
},
},
computed: {
questData() {