Homepage, lepsi POI
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user