@@ -6,147 +6,111 @@ import {
66 FeatureProperties ,
77 LocationPanel ,
88} from "@macrostrat/map-interface" ;
9- import { useNearbyCheckins , useNearbySpots } from "./sidebar-data" ;
10- import { CheckinListing , SpotListing } from "@macrostrat/data-components" ;
119import { getColors } from "#/dev/map/rockd-strabospot/map-style" ;
1210import { useInDarkMode } from "@macrostrat/ui-components" ;
13- import { SaveLocationButton , SaveLocationForm } from "./save-location-form/save-location" ;
14- import { ViewLocations } from "./save-location-form/view-locations" ;
15- import { useAppState } from "#/map/map-interface/app-state" ;
16- import React , { useState } from "react" ;
11+ import { SaveLocationForm } from "./save-location" ;
12+ import React , { useState , useEffect } from "react" ;
1713
1814
1915
20- const h = hyper . styled ( styles ) ;
2116
17+ const h = hyper . styled ( styles ) ;
2218export function DetailsPanel ( { position, nearbyFeatures, onClose } ) {
23- console . log ( "position " , position )
24- console . log ( "features " , nearbyFeatures )
25- const [ showSaveLocationForm , setShowSaveLocationForm ] = useState ( false ) ;
26- const handleSaveLocationClick = ( ) => {
27- setShowSaveLocationForm ( ( prevState ) => ! prevState ) ;
28- } ;
2919 if ( position == null ) return null ;
20+ let count = 22 ;
21+
3022 return h (
3123 LocationPanel ,
3224 {
3325 onClose,
3426 position,
3527 } ,
3628 [
29+ h ( SaveLocationForm , { position, count } ) ,
30+ //h(CheckinsPanel, { nearbyFeatures }),
3731 h ( SpotsPanel , {
3832 nearbyFeatures,
3933 } ) ,
40- h ( SaveLocationButton , { onClick : handleSaveLocationClick , } ) ,
41- showSaveLocationForm && h ( SaveLocationForm , { onSubmit : handleFormSubmit , onViewLocations : handleViewLocationsForm } ) ,
42- //locations && h(ViewLocations, { locations }),
4334 ]
4435 ) ;
4536}
4637
47-
48-
38+ //implement tileserver api to reorient user to an exact location
4939/*
50- //import lat and lng from file1 or call function from file1 to obtain the lat and lng
51-
52- const [locations, setLocations] = useState(0)
53-
54-
55-
56- //id is a sequential serial within the database and webanon has to
57- //specify every column value in order for any payload to post to the
58- //saved locations table. TODO specify permissions and RLA in postgrest.
59- let count_id = 18
60- let position = useAppState((state) => state.core.infoMarkerPosition);
61- let lat = position.lat
62- let lng = position.lng
63-
64- const handleFormSubmit = async (formData) => {
65- count_id = count_id + 1;
66- const payload = {
67- id: count_id,
68- user_id: 46,
69- location_name: formData.location_name,
70- location_description: formData.location_description,
71- latitude: lat, //need latitude from state
72- longitude: lng, //need longitude from state
73- created_at: new Date().toISOString(),
74- updated_at: new Date().toISOString(),
75- category: formData.category
76- };
77- console.log("posting with this payload", payload)
78- const response = await fetch("https://dev2.macrostrat.org/api/pg/saved_locations", {
79- method: "POST",
80- headers: {
81- "Content-Type": "application/json",
82- },
83- body: JSON.stringify(payload),
84- });
85- console.log(response)
86- console.log(response.ok)
87- console.log(response.status)
88- console.log(response.statusText)
89- if (response.status != 201) {
90- alert(`Error ${response.status}: ${response.statusText}`)
91- }
92- else {
93- alert("Saved successfully")
94- }
95- setShowSaveLocationForm(false);
96- };
97-
98- //build own view locations component outside of geo-map
99- const handleViewLocationsForm = async () => {
100- const response = await fetch("https://dev2.macrostrat.org/api/pg/saved_locations", {
101- method: "GET",
102- headers: {
103- "Content-Type": "application/json",
104- },
40+ export function CheckinsPanel({ nearbyFeatures }) {
41+ const checkins = useNearbyCheckins(nearbyFeatures);
42+ const titleComponent = () =>
43+ h(PanelHeader, {
44+ title: "Checkins",
45+ sourceLink: h(SystemLink, { href: "https://rockd.org" }, "Rockd"),
46+ hasData: checkins.length != 0,
10547 });
10648
107- if (response.status !== 200) {
108- alert(`Error ${response.status}: ${response.statusText}`)
109- }
110- else {
111- const result = await response.json();
112- console.log(result)
113- setLocations(result);
114- }
115- };
116-
117-
118-
119- */
120-
121-
122-
49+ return h(FeatureTypePanel, {
50+ features: checkins,
51+ titleComponent,
52+ featureComponent: CheckinFeature,
53+ });
54+ }
55+ */
12356export function SpotsPanel ( { nearbyFeatures } ) {
124- // Here, we handle loading state for feature
125- const [ features , loading , error ] = useNearbySpots ( nearbyFeatures ) ;
57+ const [ features , setFeatures ] = useState ( [ ] ) ; // State to store features
58+ const [ loading , setLoading ] = useState ( true ) ; // State to track loading
59+ const [ error , setError ] = useState ( null ) ; // State to track errors
60+
61+ useEffect ( ( ) => {
62+ const fetchFeatures = async ( ) => {
63+ try {
64+ const response = await fetch (
65+ "https://dev2.macrostrat.org/api/pg/saved_locations"
66+ ) ;
67+ if ( ! response . ok ) {
68+ throw new Error ( `Error ${ response . status } : ${ response . statusText } ` ) ;
69+ }
70+ const data = await response . json ( ) ;
71+ setFeatures ( data ) ; // Update features state
72+ } catch ( err ) {
73+ setError ( err . message ) ; // Set error message
74+ } finally {
75+ setLoading ( false ) ; // Stop loading
76+ }
77+ } ;
78+
79+ fetchFeatures ( ) ;
80+ } , [ ] ) ;
12681
82+ console . log ( "features!!" , features )
12783
84+ const FeatureComponent = ( { data } ) => {
85+ return h ( "div.feature" , [
86+ h ( "h3.feature-title" , data . location_name ) ,
87+ h ( "p.feature-description" , data . location_description ) ,
88+ h ( "p.feature-coordinates" , [
89+ `Latitude: ${ data . latitude } , Longitude: ${ data . longitude } ` ,
90+ ] ) ,
91+ h ( "p.feature-category" , `Category: ${ data . category } ` ) ,
92+ h ( "p.feature-dates" , [
93+ `Created at: ${ new Date ( data . created_at ) . toLocaleString ( ) } ` ,
94+ `Updated at: ${ new Date ( data . updated_at ) . toLocaleString ( ) } ` ,
95+ ] ) ,
96+ ] ) ;
97+ } ;
12898 const titleComponent = ( ) =>
129- h ( PanelHeader , {
130- title : "Saved locations" ,
131- sourceLink : h (
132- SystemLink ,
133- { href : "https://strabospot.org" } ,
134- "StraboSpot"
135- ) ,
136- hasData : features . length != 0 ,
137- } ) ;
99+ h ( PanelHeader , {
100+ title : "My Saved Locations" ,
101+ hasData : features . length != 0 ,
102+ } ) ;
103+
138104
139105 return h ( FeatureTypePanel , {
140106 features,
141107 titleComponent,
142108 loading,
143109 error,
144- featureComponent : spotfeature ,
110+ featureComponent : FeatureComponent ,
145111 } ) ;
146112}
147113
148- const spotfeature = ( props ) => h ( SpotListing , { spot : props . data } ) ;
149-
150114function FeatureTypePanel ( {
151115 features,
152116 titleComponent,
@@ -162,11 +126,6 @@ function FeatureTypePanel({
162126 icon : "error" ,
163127 } ) ;
164128 }
165-
166- // if (features.length == 0) {
167- // return h("div.empty-list", h("p", "No nearby " + title));
168- // }
169-
170129 return h ( "div.feature-panel" , [
171130 h (
172131 ExpansionPanel ,
@@ -215,23 +174,9 @@ export function LegendList() {
215174 LegendItem ,
216175 {
217176 color : colors . checkins ,
218- name : "Checkins" ,
219- sourceLink : h ( SystemLink , { href : "https://rockd.org" } , "Rockd" ) ,
220- } ,
221- "Outcrops collected as part of a community-collaborative field guide."
222- ) ,
223- h (
224- LegendItem ,
225- {
226- color : colors . spots ,
227- name : "Spots" ,
228- sourceLink : h (
229- SystemLink ,
230- { href : "https://strabospot.org" } ,
231- "StraboSpot"
232- ) ,
177+ name : "My saved locations" ,
233178 } ,
234- "Sites collected for research purposes (filtered for general interest) ."
179+ "Will show the user locations on the map. Need to build it within the tileserver ."
235180 ) ,
236181 ] ) ;
237182}
@@ -259,3 +204,9 @@ function LegendHeader({ color, name, sourceLink = null }) {
259204function Swatch ( { color } ) {
260205 return h ( "span.swatch" , { style : { backgroundColor : color } } ) ;
261206}
207+
208+
209+
210+
211+
212+
0 commit comments