1- import hyper from "@macrostrat/hyper" ;
21import { LngLatCoords } from "@macrostrat/map-interface" ;
3- import { useEffect , useState , useRef } from 'react' ;
2+ import { useState , useCallback } from 'react' ;
43import 'mapbox-gl/dist/mapbox-gl.css' ;
5- import { BlankImage , imageExists , Footer , getProfilePicUrl , useRockdAPI , getImageUrl } from "../index " ;
4+ import { BlankImage , imageExists , Footer , getProfilePicUrl , getImageUrl } from "~/components/general " ;
65import { Icon } from "@blueprintjs/core" ;
7- import styles from ". ./main.module.sass" ;
6+ import h from "./main.module.sass" ;
87import { SETTINGS } from "@macrostrat-web/settings" ;
9- import "./main.sass" ;
108import "@macrostrat/style-system" ;
9+ import { Overlay2 } from "@blueprintjs/core" ;
1110import { MapAreaContainer , MapView , MapMarker } from "@macrostrat/map-interface" ;
1211import 'mapbox-gl/dist/mapbox-gl.css' ;
1312import { MapPosition } from "@macrostrat/mapbox-utils" ;
1413import { PanelCard } from "@macrostrat/map-interface" ;
1514import { LithologyList } from "@macrostrat/data-components" ;
15+ import { ClientOnly } from "vike-react/ClientOnly" ;
1616
17- const h = hyper . styled ( styles ) ;
17+ function Map ( props ) {
18+ return h (
19+ ClientOnly ,
20+ {
21+ load : ( ) => import ( "./map.client" ) . then ( ( d ) => d . MapContainer ) ,
22+ fallback : h ( "div.loading" , "Loading map..." ) ,
23+ } ,
24+ ( component ) => h ( component , props )
25+ ) ;
26+ }
1827
19- export function Checkins ( { checkinID } ) {
20- const checkinData = useRockdAPI ( "/protected/checkins?checkin_id=" + checkinID ) ;
21- const [ overlayOpen , setOverlayOpen ] = useState ( false ) ;
22- const [ showMap , setShowMap ] = useState ( false ) ;
28+ export function Checkins ( { checkin } ) {
29+ /*
30+ const [isOpen, setIsOpen ] = useState(false);
31+ const toggleOverlay = useCallback(() => setIsOpen(open => !open), [setIsOpen] );
2332
24- if ( ! checkinData ) {
25- return h ( "div" , { className : 'loading' } , [
26- h ( "h1" , "Loading checkin..." ) ,
27- ] ) ;
28- }
33+ return h("div.container", [
34+ h('button', {
35+ className: "bp3-button bp3-intent-primary",
36+ onClick: toggleOverlay
37+ }, "Open Overlay"),
38+ h(Overlay2,
39+ {
40+ isOpen,
41+ onClose: toggleOverlay,
42+ className: "checkin-overlay",
43+ usePortal: true,
44+ canEscapeKeyClose: true,
45+ canOutsideClickClose: true,
46+ hasBackdrop: true,
47+ }, "hello"
48+
49+ )
50+ ]);
51+ */
2952
30- if ( checkinData . success . data . length == 0 ) {
31- return h ( "div" , { className : 'error' } , [
32- h ( BlankImage , { className : "error-img" , src : "https://rockd.org/assets/img/404.jpg" } ) ,
33- h ( "h1" , "Checkin " + checkinID + " not found!" ) ,
34- ] ) ;
35- }
53+ const [ overlayOpen , setOverlayOpen ] = useState ( false ) ;
54+ const [ showMap , setShowMap ] = useState ( false ) ;
3655
37- const checkin = checkinData . success . data [ 0 ] ;
3856 const center = {
3957 lat : checkin . lat ,
4058 lng : checkin . lng
@@ -96,26 +114,36 @@ export function Checkins({checkinID}) {
96114 zoom : 10
97115 } ;
98116
99- // overlay
100- let overlay = h ( 'div' , { className : 'overlay' } , [
101- h ( 'div.overlay-header' , [
102- h ( Icon , { className : "back-arrow" , icon : "arrow-left" , iconSize : "5vh" , style : { color : 'black' } ,
103- onClick : ( ) => {
104- setOverlayOpen ( ! overlayOpen ) ;
105- }
106- } ) ,
107- ] ) ,
108- ] ) ;
109-
110- const map = h ( Map , { center, showMap, setShowMap} ) ;
111117
112118 let main = h ( 'div' , { className : "container" } , [
113119 h ( 'div' , { className : showMap ? 'hide' : 'main' } , [
114120 h ( 'div' , { className : "checkin-head" } , [
115121 h ( 'h1' , checkin . notes ) ,
116122 ] ) ,
117- h ( BlankImage , { className : "location-img" , src : "https://api.mapbox.com/styles/v1/jczaplewski/cje04mr9l3mo82spihpralr4i/static/geojson(%7B%22type%22%3A%22Point%22%2C%22coordinates%22%3A%5B" + checkin . lng + "%2C" + checkin . lat + "%5D%7D)/" + checkin . lng + "," + checkin . lat + ",5,0/1200x400?access_token=" + SETTINGS . mapboxAccessToken } ) ,
118- h ( 'div' , { className : 'stop-header' , onClick : ( ) => { setShowMap ( true ) ; console . log ( "center" , center ) } } , [
123+ h ( Overlay , {
124+ checkin,
125+ center,
126+ LngLatProps,
127+ ratingArr,
128+ profile_pic,
129+ } ) ,
130+ h ( 'div' , { className : 'observations' } , observations ) ,
131+ ] ) ,
132+ h ( 'div' , { className : showMap ? 'hide' : 'bottom' } , [
133+ h ( Footer ) ,
134+ ] ) ,
135+ ] )
136+
137+ return main ;
138+ }
139+
140+ function Overlay ( { checkin, center, LngLatProps, ratingArr, profile_pic} ) {
141+ const [ overlayOpen , setOverlayOpen ] = useState ( false ) ;
142+ const map = h ( Map , { center, setOverlayOpen} ) ;
143+
144+ return h ( 'div.overlay' , [
145+ h . if ( ! overlayOpen ) ( BlankImage , { className : "location-img" , src : "https://api.mapbox.com/styles/v1/jczaplewski/cje04mr9l3mo82spihpralr4i/static/geojson(%7B%22type%22%3A%22Point%22%2C%22coordinates%22%3A%5B" + checkin . lng + "%2C" + checkin . lat + "%5D%7D)/" + checkin . lng + "," + checkin . lat + ",5,0/1200x400?access_token=" + SETTINGS . mapboxAccessToken } ) ,
146+ h . if ( ! overlayOpen ) ( 'div' , { className : 'stop-header' , onClick : ( ) => { setOverlayOpen ( true ) ; console . log ( "center" , center ) } } , [
119147 profile_pic ,
120148 h ( 'div' , { className : 'stop-main-info' } , [
121149 h ( 'h3' , { className : 'name' } , checkin . first_name + " " + checkin . last_name ) ,
@@ -127,16 +155,16 @@ export function Checkins({checkinID}) {
127155 h ( 'h3' , { className : 'rating' } , ratingArr ) ,
128156 ] ) ,
129157 ] ) ,
130- h ( 'div' , { className : 'observations' } , observations ) ,
131- ] ) ,
132- h ( 'div' , { className : showMap ? 'hide' : 'bottom' } , [
133- h ( Footer ) ,
134- ] ) ,
135- h ( 'div' , { className : ! showMap ? 'hide' : 'map' } , map )
136- ] )
137-
138-
139- return overlayOpen ? overlay : main ;
158+ h ( Overlay2 , {
159+ isOpen : overlayOpen ,
160+ onClose : ( ) => setOverlayOpen ( false ) ,
161+ className : "map" ,
162+ usePortal : true ,
163+ canEscapeKeyClose : true ,
164+ canOutsideClickClose : true ,
165+ hasBackdrop : false ,
166+ } , map ) ,
167+ ] )
140168}
141169
142170function observationFooter ( observation ) {
@@ -227,45 +255,4 @@ function observationFooter(observation) {
227255 h ( 'p' , { className : "notes" } , rocks . notes ) ,
228256 ] ) ,
229257 ] ) ;
230- }
231-
232- function Map ( { center, showMap, setShowMap} ) {
233- const [ style , setStyle ] = useState ( "mapbox://styles/jczaplewski/cje04mr9l3mo82spihpralr4i" ) ;
234- const [ styleText , setStyleText ] = useState ( "Show Satelite" ) ;
235-
236- const newMapPosition : MapPosition = {
237- camera : {
238- lat : center . lat , // Latitude
239- lng : center . lng , // Longitude
240- altitude : 300000 , // Altitude (height from the Earth's surface)
241- } ,
242- } ;
243-
244- const sateliteStyle = 'mapbox://styles/mapbox/satellite-v9' ;
245- const whiteStyle = "mapbox://styles/jczaplewski/cje04mr9l3mo82spihpralr4i" ;
246- const whiteText = "Show White" ;
247- const sateliteText = "Show Satelite" ;
248-
249- let map = h ( "div.map" , [
250- h ( MapAreaContainer , { style : { height : "93vh" , top : "7vh" } } ,
251- [
252- h ( MapView , { style : style , mapboxToken : SETTINGS . mapboxAccessToken , mapPosition : newMapPosition } , [
253- h ( MapMarker , {
254- position : center ,
255- } ) ,
256- ] ) ,
257- ]
258- ) ,
259- h ( 'div' , { className : 'banner' } , [
260- h ( Icon , { className : "banner-arrow" , icon : "arrow-left" , iconSize : "4vh" , style : { color : 'black' } , onClick : ( ) => {
261- setShowMap ( ! showMap ) ;
262- } } ) ,
263- h ( PanelCard , { className : "banner-button" , onClick : ( ) => {
264- setStyle ( style == whiteStyle ? sateliteStyle : whiteStyle ) ;
265- setStyleText ( styleText == whiteText ? sateliteText : whiteText ) ;
266- } } , styleText ) ,
267- ] ) ,
268- ] )
269-
270- return map ;
271258}
0 commit comments