diff --git a/src/api/index.js b/src/api/index.js index 6fa0235..66b1a94 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -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 }; diff --git a/src/components/QuestMissingCategories/index.vue b/src/components/QuestMissingCategories/index.vue index 65f43ff..32c450e 100644 --- a/src/components/QuestMissingCategories/index.vue +++ b/src/components/QuestMissingCategories/index.vue @@ -43,7 +43,7 @@ - submit + Submit @@ -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); + }, + }, }; diff --git a/src/store/actions.js b/src/store/actions.js index e63df32..6e872d7 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -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, + }, + )); + } + }, }; diff --git a/src/store/getters.js b/src/store/getters.js index 14864af..fa870a8 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -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 }; diff --git a/src/store/mutations-types.js b/src/store/mutations-types.js index 890e9a3..d65eb6e 100644 --- a/src/store/mutations-types.js +++ b/src/store/mutations-types.js @@ -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'; diff --git a/src/store/mutations.js b/src/store/mutations.js index 1214e47..923fe90 100644 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -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); + }, }; diff --git a/src/views/Quest.vue b/src/views/Quest.vue index 91a9889..481dd90 100644 --- a/src/views/Quest.vue +++ b/src/views/Quest.vue @@ -1,5 +1,5 @@