Homepage, lepsi POI
This commit is contained in:
@@ -2,6 +2,7 @@ import {defineStore} from 'pinia'
|
||||
import {apolloWrapper} from "src/graphql/apollo";
|
||||
import {AIRCRAFT_DETAIL, AIRCRAFTS_LIST} from "src/graphql/queries/aircrafts";
|
||||
import {CREATE_AIRCRAFT, DELETE_AIRCRAFT, EDIT_AIRCRAFT} from "src/graphql/mutations/aircrafts";
|
||||
import {deleteFromItems, updateInItems} from "stores/helpers";
|
||||
|
||||
export const useAircraftsStore = defineStore('Aircrafts', {
|
||||
state: () => ({
|
||||
@@ -29,17 +30,16 @@ export const useAircraftsStore = defineStore('Aircrafts', {
|
||||
},
|
||||
delete(id) {
|
||||
return apolloWrapper.mutate(DELETE_AIRCRAFT, {id}).then(({data}) => {
|
||||
const idx = this.items.findIndex(a => a.id === id);
|
||||
console.log(idx);
|
||||
this.items.splice(idx, 1);
|
||||
deleteFromItems(this.items, 'id', id);
|
||||
|
||||
return data;
|
||||
});
|
||||
},
|
||||
update(id, formData) {
|
||||
return apolloWrapper.mutate(EDIT_AIRCRAFT, {id: id, input: formData}).then(({data}) => {
|
||||
console.log("Pridat update ve storu")
|
||||
return data.editAircraft;
|
||||
const aircraft = data.editAircraft;
|
||||
updateInItems(this.items, 'id', aircraft);
|
||||
return aircraft;
|
||||
});
|
||||
},
|
||||
fetch() {
|
||||
@@ -47,7 +47,7 @@ export const useAircraftsStore = defineStore('Aircrafts', {
|
||||
.query(AIRCRAFTS_LIST)
|
||||
.then((result) => {
|
||||
this.items = result.data.aircrafts;
|
||||
return result.data.aircrafts;
|
||||
return this.items;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import {defineStore} from 'pinia'
|
||||
import {apolloWrapper} from "src/graphql/apollo";
|
||||
import {COPILOT_DETAIL, COPILOTS_LIST} from "src/graphql/queries/copilots";
|
||||
import {CREATE_COPILOT, EDIT_COPILOT} from "src/graphql/mutations/copilot";
|
||||
import {updateInItems} from "stores/helpers";
|
||||
|
||||
export const useCopilotsStore = defineStore('SecondPilots', {
|
||||
state: () => ({
|
||||
@@ -28,7 +29,10 @@ export const useCopilotsStore = defineStore('SecondPilots', {
|
||||
},
|
||||
update(id, formData) {
|
||||
return apolloWrapper.mutate(EDIT_COPILOT, {id: id, input: formData}).then(({data}) => {
|
||||
return data.editCopilot;
|
||||
const copilot = data.editCopilot;
|
||||
|
||||
updateInItems(this.items, "id", copilot);
|
||||
return copilot;
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import {defineStore} from 'pinia'
|
||||
import {apolloWrapper} from "src/graphql/apollo"
|
||||
import {FLIGHT_DETAIL, FLIGHTS_LIST} from "src/graphql/queries/flights";
|
||||
import {EDIT_FLIGHT, CREATE_FLIGHT, DELETE_FLIGHT} from "src/graphql/mutations/flight";
|
||||
import {updateInItems} from "stores/helpers";
|
||||
|
||||
export const useFlightsStore = defineStore('Flights', {
|
||||
state: () => ({
|
||||
@@ -26,12 +27,7 @@ export const useFlightsStore = defineStore('Flights', {
|
||||
update(id, formData) {
|
||||
return apolloWrapper.mutate(EDIT_FLIGHT, {id: id, input: formData}).then(({data}) => {
|
||||
const flight = data.editFlight;
|
||||
const idx = this.items.findIndex(item => item.id === id);
|
||||
if (idx < 0) {
|
||||
this.items.push(flight)
|
||||
} else {
|
||||
this.items[idx] = flight;
|
||||
}
|
||||
updateInItems(this.items, "id", flight);
|
||||
|
||||
return flight;
|
||||
});
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import {defineStore} from 'pinia'
|
||||
import {apolloWrapper} from "src/graphql/apollo";
|
||||
import {POI_TYPE_DETAIL, POI_TYPE_LIST} from "src/graphql/queries/poi_type";
|
||||
|
||||
export const usePointsOfInterestTypeStore = defineStore('PointsOfInterestType', {
|
||||
state: () => ({
|
||||
items: []
|
||||
}),
|
||||
|
||||
|
||||
actions: {
|
||||
// create(input) {
|
||||
// return apolloWrapper.mutate(CREATE_POI, {input}).then((data) => {
|
||||
// const poi = data.data.createPointOfInterest;
|
||||
// this.items.push(poi);
|
||||
// return poi;
|
||||
// })
|
||||
// },
|
||||
// update(id, input) {
|
||||
// return apolloWrapper.mutate(EDIT_POI, {id, input}).then((data) => {
|
||||
// console.log("Pridat update POI ve store");
|
||||
// return data.data.editPointOfInterest;
|
||||
// })
|
||||
// },
|
||||
|
||||
fetchDetail(id) {
|
||||
if (typeof id !== "number") {
|
||||
id = parseInt(id);
|
||||
}
|
||||
return apolloWrapper.query(POI_TYPE_DETAIL, {id}).then(result => result.data.pointOfInterest);
|
||||
},
|
||||
fetch() {
|
||||
return apolloWrapper.query(POI_TYPE_LIST).then(result => {
|
||||
this.items = result.data.pointOfInterestTypes;
|
||||
return result.data.pointOfInterestTypes;
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -1,32 +1,39 @@
|
||||
import {defineStore} from 'pinia'
|
||||
import {apolloWrapper} from "src/graphql/apollo";
|
||||
import {POI_DETAIL, POI_LIST} from "src/graphql/queries/poi";
|
||||
import {EDIT_POI} from "src/graphql/mutations/poi";
|
||||
import {CREATE_POI, EDIT_POI} from "src/graphql/mutations/poi";
|
||||
import {updateInItems} from "stores/helpers";
|
||||
|
||||
|
||||
export const usePointsOfInterestStore = defineStore('PointsOfInterest', {
|
||||
state: () => ({
|
||||
items: []
|
||||
items: [],
|
||||
isMutationRunning: false,
|
||||
}),
|
||||
|
||||
getters: {
|
||||
getDetail: (state) => (poiId) => {
|
||||
console.log(poiId, state.items, state.items.length);
|
||||
const item = state.items.find(p => {
|
||||
console.log(p, poiId);
|
||||
return p.id === poiId
|
||||
}
|
||||
);
|
||||
console.log('item', item);
|
||||
return item;
|
||||
return state.items.find(p => p.id === poiId);
|
||||
},
|
||||
},
|
||||
|
||||
actions: {
|
||||
create(input) {
|
||||
this.isMutationRunning = true;
|
||||
return apolloWrapper.mutate(CREATE_POI, {input}).then((data) => {
|
||||
const poi = data.data.createPointOfInterest;
|
||||
this.items.push(poi);
|
||||
return poi;
|
||||
}).finally(() => this.isMutationRunning = false);
|
||||
},
|
||||
update(id, input) {
|
||||
this.isMutationRunning = true;
|
||||
|
||||
return apolloWrapper.mutate(EDIT_POI, {id, input}).then((data) => {
|
||||
console.log("Pridat update POI ve store");
|
||||
return data.data.editPointOfInterest;
|
||||
})
|
||||
const poi = data.data.editPointOfInterest;
|
||||
updateInItems(this.items, "id", poi);
|
||||
return poi;
|
||||
}).finally(() => this.isMutationRunning = false);
|
||||
},
|
||||
|
||||
fetchDetail(id) {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
export const updateInItems = (items, key, data) => {
|
||||
const idx = items.findIndex(i => i[key] === data[key]);
|
||||
if (idx >= 0)
|
||||
items[idx] = data;
|
||||
else items.push(data);
|
||||
}
|
||||
|
||||
export const deleteFromItems = (items, key, value) => {
|
||||
const idx = items.findIndex(a => a[key] === value);
|
||||
if (idx < 0) return;
|
||||
|
||||
items.splice(idx, 1);
|
||||
}
|
||||
Reference in New Issue
Block a user