diff --git a/front/src/pages/maps/index.astro b/front/src/pages/maps/index.astro index 40221f8..eeb716e 100644 --- a/front/src/pages/maps/index.astro +++ b/front/src/pages/maps/index.astro @@ -4,20 +4,42 @@ import 'leaflet/dist/leaflet.css' import 'leaflet-geosearch/dist/geosearch.css' import CheckBox from 'components/CheckBox.astro' import Radios from 'components/Radios.astro' +import ListResult, { type RecordModel } from 'pocketbase' +import { Expand, Trash } from 'lucide-astro' + +const pb = Astro.locals.pb +const connected = pb.authStore.isValid const metadata = { title: 'Maps', ignoreTitleTemplate: true, } + +let fav = new Array + +if(connected){ + try { + const request = await pb.collection('user_poi').getList(1,10,{filter:`owner="${pb.authStore.model!.id}"`, expand:"poi_list"}) + request.items.forEach(element => { + fav.push(element.expand!.poi_list.Poi) + }); + } catch (error) { + console.log(error); + } +} + +console.log(fav); + + --- -
+

Filtre :

-
+

note minimal :

-
+

Source :

+ {connected && ( +
+

Favori :

+ {fav.map(val =>( +
+

{val.properties.name}

+ +
+ ))} +
+ )}
-
-
+
+
- +
@@ -65,6 +98,10 @@ const metadata = { import { OpenStreetMapProvider } from 'leaflet-geosearch' import { GeoSearchControl } from 'leaflet-geosearch' + const showFav = document.querySelectorAll(".poi-favori") + const trashFav = document.querySelectorAll(".poi-trash") + const favDiv = document.querySelector('#fav-div') + const icon = {icon: new L.Icon({iconUrl: markerIcon.src, shadowUrl: markerShadow.src, iconAnchor: [13,41]})} const BACK_URL = "http://localhost:3001/" //XXX : mettre url de prod @@ -97,6 +134,38 @@ const metadata = { }), ) + async function saveToFav(element: any, save: boolean){ + const url = '/maps/save_poi'; + const options = { + method: 'POST', + body: JSON.stringify({Poi : element, save: save}) + }; + + try { + const response = await fetch(url, options); + const data = await response.json(); + console.log(data); + } catch (error) { + console.error(error); + } + } + + function eventGotoFav(e: Element){ + e.addEventListener('click', () =>{ + const pose = e.getAttribute('data-pos')?.split(',') + map.panTo(new L.LatLng(parseFloat(pose![1]),parseFloat(pose![0]))) + }) + } + + function eventRemoveFav(e: Element){ + e.addEventListener('click', () => { + saveToFav({id:e.id, type:"Feature"},false) + }) + } + + showFav.forEach(e => {eventGotoFav(e)}) + trashFav.forEach(e => {eventRemoveFav(e)}) + let poiMarkers = new Array let minimalNote = "1" let drink = true @@ -130,11 +199,12 @@ const metadata = { tags += "- " + element + "
" }) const poiMarker = L.marker([element.geometry.coordinates[1],element.geometry.coordinates[0]],icon) - .bindPopup(`${prop.name}
note : ${prop.rate}
tags:
${tags}

favori :

`) + .bindPopup(`${prop.name}
note : ${prop.rate}
tags:
${tags}

favori :

`) .on("click", () => { document.querySelectorAll('input[name="like"]').forEach(e => { e.addEventListener("click", () => { - console.log("poeut"); + console.log(element) + saveToFav(element, e.checked) }) }) }) diff --git a/front/src/pages/maps/save_poi.astro b/front/src/pages/maps/save_poi.astro index df7120f..c8a5f82 100644 --- a/front/src/pages/maps/save_poi.astro +++ b/front/src/pages/maps/save_poi.astro @@ -34,10 +34,10 @@ await AstroUtils.wrap(async () => { try { if(poiJson.save){ - pb.collection('user_poi').create({owner: pb.authStore.model!.id, poi_list:record!.id}) + await pb.collection('user_poi').create({owner: pb.authStore.model!.id, poi_list:record!.id}) }else{ record = await pb.collection('user_poi').getFirstListItem(`poi_list="${record!.id}"&&owner="${pb.authStore.model!.id}"`) - pb.collection('user_poi').delete(record.id) + await pb.collection('user_poi').delete(record.id) } } catch (error) { console.log(error)