Add Skeleton for GridItem and Image + Refactor components architecture with more modularity + Delete Fruit feature

This commit is contained in:
2020-12-07 12:48:06 +01:00
parent 5d34725344
commit 5ef8c424fd
19 changed files with 435 additions and 249 deletions

View File

@@ -9,25 +9,31 @@ export default {
})
.catch(err => {
if (err.message === "Network Error") throw "Check API connectivity ...";
});
})
.finally(() => commit("setLoading", false));
},
getFruit: async ({ commit }, id) => {
const response = await axios.get(`http://localhost:3000/fruit/${id}`);
commit("setFruit", response.data);
await axios.get(`http://localhost:3000/fruit/${id}`).then(res => commit("setFruit", res.data));
},
getImageFromUnsplash: async (_, keyword) => {
const response = await axios.get(
`https://api.unsplash.com/search/photos?query=${keyword}&w=800&h=400`,
{
removeFruit: async ({ commit }, id) => {
await axios
.delete(`http://localhost:3000/fruit/${id}`)
.then(() => commit("removeFruit", id))
.catch(err => console.log(err));
},
getImageFromUnsplash: async ({ commit }, keyword) => {
commit("setLoading", true);
return await axios
.get(`https://api.unsplash.com/search/photos?query=${keyword}&w=800&h=400`, {
headers: {
Authorization: "Client-ID NjFwGYsnksnzH2uh12W55aobUpTe0h06oSVACd5cWt0",
"X-Total": 1
}
}
);
if (response.data.total === 0) throw new Error("0 found.");
return response.data.results[0];
})
.then(res => {
if (res.data.total === 0) throw new Error("0 found.");
return res.data.results[0];
})
.finally(() => commit("setLoading", false));
}
};

View File

@@ -1,5 +1 @@
export default {
parsedFruits: () => {
return [{ id: 1 }];
}
};
export default {};

View File

@@ -7,7 +7,8 @@ import getters from "./getters";
export const state = {
fruits: [],
fruit: {},
modalIsOpen: false
modalIsOpen: false,
loading: true
};
Vue.use(Vuex);

View File

@@ -15,5 +15,8 @@ export default {
},
toggleModal: state => {
state.modalIsOpen = !state.modalIsOpen;
},
setLoading: (state, loading) => {
state.loading = loading;
}
};