Add comments on Vuex store file
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
export default function({ store, redirect, route }) {
|
export default function({ store, redirect }) {
|
||||||
if (store.state.search == "") return redirect("/");
|
if (store.state.search == "") return redirect("/");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ export const mutations = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const actions = {
|
export const actions = {
|
||||||
|
//
|
||||||
|
// Fetching movies on OMDb API
|
||||||
|
//
|
||||||
async getMovies({ commit, state }) {
|
async getMovies({ commit, state }) {
|
||||||
commit("setLoading", true);
|
commit("setLoading", true);
|
||||||
|
|
||||||
@@ -32,11 +35,13 @@ export const actions = {
|
|||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.Response === "False") throw new Error(response.Error);
|
if (response.Response === "False") throw new Error(response.Error);
|
||||||
|
|
||||||
|
// Populate Vuex store with response data
|
||||||
commit("setNbResults", response.totalResults);
|
commit("setNbResults", response.totalResults);
|
||||||
commit("setMovies", response.Search);
|
commit("setMovies", response.Search);
|
||||||
commit("setError", null);
|
commit("setError", null);
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
|
// Populate Vuex store with response error
|
||||||
commit("setMovies", []);
|
commit("setMovies", []);
|
||||||
commit("setNbResults", 0);
|
commit("setNbResults", 0);
|
||||||
commit("setError", e.message);
|
commit("setError", e.message);
|
||||||
@@ -45,6 +50,10 @@ export const actions = {
|
|||||||
commit("setLoading", false);
|
commit("setLoading", false);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
//
|
||||||
|
// Fetching movie by ID on OMDb API
|
||||||
|
//
|
||||||
async getDirector({}, id) {
|
async getDirector({}, id) {
|
||||||
return await this.$axios
|
return await this.$axios
|
||||||
.$get("", {
|
.$get("", {
|
||||||
@@ -61,6 +70,7 @@ export const actions = {
|
|||||||
})
|
})
|
||||||
.catch(e => commit("setError", e.message));
|
.catch(e => commit("setError", e.message));
|
||||||
},
|
},
|
||||||
|
// Add Director's field for movies into the Vuex store
|
||||||
setDirectors({ state, dispatch, commit }) {
|
setDirectors({ state, dispatch, commit }) {
|
||||||
commit("setLoading", true);
|
commit("setLoading", true);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user