diff --git a/src/api/index.js b/src/api/index.js index 38b5676..4de590a 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -3,11 +3,17 @@ require('isomorphic-fetch'); /** * TODO: Handle country/locale + * TODO: Handle errors */ export default function (EAN) { return fetch( `https://world.openfoodfacts.org/api/v0/product/${EAN}.json`, ) .then(response => response.json()) + .then(response => ({ + // Return a clean object with only interesting fields + icon: response.product.image_thumb_url, + name: response.product.product_name, + })) .catch(exc => console.error(`Unable to fetch product: ${exc}.`)); } diff --git a/src/store/actions.js b/src/store/actions.js index 2bace7d..203fc98 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -5,10 +5,7 @@ export default { getProduct({ commit }, { EAN }) { commit(types.IS_LOADING); getProduct(EAN).then( - (result) => { - const { product } = result; - commit(types.STORE_PRODUCT, { product }); - }, + product => commit(types.STORE_PRODUCT, { product }), ); }, setTitle({ commit }, { title }) { diff --git a/src/store/mutations.js b/src/store/mutations.js index 72f1e79..41c2409 100644 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -14,7 +14,7 @@ export const mutations = { [types.STORE_PRODUCT](state, { product }) { state.product = product; state.isLoading = false; - state.ui.title = product.product_name; // Set UI title + state.ui.title = product.name; // Set UI title }, [types.IS_LOADING](state) { state.isLoading = true; diff --git a/src/views/Product.vue b/src/views/Product.vue index 3bbc4a9..a228c4e 100644 --- a/src/views/Product.vue +++ b/src/views/Product.vue @@ -5,7 +5,7 @@ - +