Create basic Person component + collect data by getter

This commit is contained in:
2020-12-21 22:05:53 +01:00
parent a9771243a1
commit 188625a413
4 changed files with 80 additions and 96 deletions

View File

@@ -9,22 +9,15 @@ export const mutations = {
},
setFilm: (state, film) => {
state.film = film;
},
setPeople: (state, people) => {
state.film.people = people;
},
setVehicles: (state, vehicles) => {
state.film.vehicles = vehicles;
},
setLocations: (state, locations) => {
state.film.locations = locations;
}
};
export const actions = {
async getList({ commit }) {
try {
const films = await this.$axios.$get("/api/films");
const films = await this.$axios.$get(
"/api/films?fields=id,title,release_date,director,description,rt_score"
);
commit("setList", films);
} catch (e) {
throw Error(`API Error occurred: ${e.message}`);
@@ -32,77 +25,13 @@ export const actions = {
},
async getFilm({ commit }, id) {
try {
const film = await this.$axios.$get(`/api/films/${id}`);
const film = await this.$axios.$get(
`/api/films/${id}?fields=id,title,release_date,director,description,rt_score`
);
commit("setFilm", film);
} catch (e) {
throw Error(`API Error occurred: ${e.message}`);
}
},
async getPeople({ commit, dispatch, state }) {
let people = {};
try {
if (state.film.people[0].split("/")[4] !== "") {
const promises = state.film.people.map(async person => {
const id = person.split("/")[4];
return await dispatch(
"people/getPerson",
{
id: id,
callback: true
},
{ root: true }
);
});
people = await Promise.all(promises);
}
commit("setPeople", people);
} catch (e) {
throw Error(`API Error occurred: ${e.message}`);
}
},
async getVehicles({ commit, dispatch, state }) {
let vehicles = {};
try {
if (state.film.vehicles[0].split("/")[4] !== "") {
const promises = state.film.vehicles.map(async vehicle => {
const id = vehicle.split("/")[4];
return await dispatch(
"vehicles/getVehicle",
{
id: id,
callback: true
},
{ root: true }
);
});
vehicles = await Promise.all(promises);
}
commit("setVehicles", vehicles);
} catch (e) {
throw Error(`API Error occurred: ${e.message}`);
}
},
async getLocations({ commit, dispatch, state }) {
let locations = {};
try {
if (state.film.locations[0].split("/")[4] !== "") {
const promises = state.film.locations.map(async location => {
const id = location.split("/")[4];
return await dispatch(
"locations/getLocation",
{
id: id,
callback: true
},
{ root: true }
);
});
locations = await Promise.all(promises);
}
commit("setLocations", locations);
} catch (e) {
throw Error(`API Error occurred: ${e.message}`);
}
}
};