INIT commit
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import {defineStore} from 'pinia'
|
||||
|
||||
export const usePointsOfInterestStore = defineStore('PointsOfInterest', {
|
||||
state: () => ({
|
||||
items: []
|
||||
}),
|
||||
|
||||
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;
|
||||
},
|
||||
pointTypeName() {
|
||||
return (typeName) => {
|
||||
const typeToNameMap = {
|
||||
poi: "General POI",
|
||||
airport: "Airport",
|
||||
}
|
||||
return typeToNameMap[typeName] || "Unknown";
|
||||
}
|
||||
},
|
||||
groupByTypes() {
|
||||
const groupedByType = {};
|
||||
for (const item of this.items) {
|
||||
if (!groupedByType[item.type]) groupedByType[item.type] = [];
|
||||
groupedByType[item.type].push(item);
|
||||
}
|
||||
return groupedByType;
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
fetchDetail(poiId) {
|
||||
console.log("fetch poi detail");
|
||||
this.items.push({id: poiId, "name": "Zamek " + poiId, "type": "poi", "location": {"lat": 50, "lng": 10}});
|
||||
},
|
||||
fetch() {
|
||||
console.log("fetch poi");
|
||||
this.items = [
|
||||
{id: 1, "name": "LKLT", private: false, "type": "airport", "location": {"lat": 50, "lng": 10}},
|
||||
{id: 2, "name": "Hrad", "type": "poi", "location": {"lat": 50, "lng": 10}},
|
||||
{id: 3, "name": "Zamek", "type": "poi", "location": {"lat": 50, "lng": 10}},
|
||||
]
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user