Homepage, lepsi POI

This commit is contained in:
Michal Kváček
2023-08-23 21:40:32 +02:00
parent 8c3b8d19dd
commit 19b078b43c
33 changed files with 370 additions and 141 deletions
+20 -13
View File
@@ -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) {