Skip to content

Commit ca3937d

Browse files
authored
Merge pull request #31 from davidsklar99/master
Final Forked Merge
2 parents ab75e90 + 76eec9b commit ca3937d

File tree

1 file changed

+48
-49
lines changed

1 file changed

+48
-49
lines changed

pages/dev/test-site/explore/+Page.client.ts

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
ExpansionPanel,
2020
buildInspectorStyle,
2121
} from "@macrostrat/map-interface";
22-
import { useMapRef } from "@macrostrat/mapbox-react";
2322
import { buildMacrostratStyle } from "@macrostrat/mapbox-styles";
2423
import { mergeStyles } from "@macrostrat/mapbox-utils";
2524
import {
@@ -34,6 +33,7 @@ import { mapboxAccessToken, tileserverDomain } from "@macrostrat-web/settings";
3433
import "./main.styl";
3534
import { BlankImage, Image } from "../index";
3635
import { M } from "vite/dist/node/types.d-aGj9QkWt";
36+
import { map } from "underscore";
3737

3838
export function Page() {
3939
return h(
@@ -65,9 +65,6 @@ function weaverStyle(type: object) {
6565
weaver: {
6666
type: "vector",
6767
tiles: [ tileserverDomain + "/checkins/tiles/{z}/{x}/{y}"],
68-
cluster: true,
69-
clusterMaxZoom: 14,
70-
clusterRadius: 50,
7168
},
7269
},
7370
layers: [
@@ -130,20 +127,30 @@ function getCheckins(lat1, lat2, lng1, lng2) {
130127
function FeatureDetails() {
131128
const mapRef = useMapRef();
132129
let checkins = [];
133-
const bounds = mapRef.current?.getBounds();
130+
let result;
134131

135-
// change use map coords
136-
let result = getCheckins(bounds.getSouth(), bounds.getNorth(), bounds.getEast(), bounds.getWest());
132+
if(mapRef == null) {
133+
result = getCheckins(0, 100, 0, 100);
134+
} else {
135+
let bounds = mapRef.current?.getBounds();
136+
137+
// change use map coords
138+
result = getCheckins(bounds.getSouth(), bounds.getNorth(), bounds.getEast(), bounds.getWest());
139+
}
137140

138141
if (result == null) return h(Spinner);
139142
result = result.success.data;
140143

141144
result.forEach((checkin) => {
142-
// format rating
143-
let ratingArr = [];
144-
for(var i = 0; i < checkin.rating; i++) {
145-
ratingArr.push(h(Image, {className: "star", src: "blackstar.png"}));
146-
}
145+
// format rating
146+
let ratingArr = [];
147+
for(var i = 0; i < checkin.rating; i++) {
148+
ratingArr.push(h(Image, {className: "star", src: "blackstar.png"}));
149+
}
150+
151+
for(var i = 0; i < 5 - checkin.rating; i++) {
152+
ratingArr.push(h(Image, {className: "star", src: "emptystar.png"}));
153+
}
147154
let image;
148155

149156
if (imageExists("https://rockd.org/api/v1/protected/image/" + checkin.person_id + "/thumb_large/" + checkin.photo)) {
@@ -172,28 +179,18 @@ function FeatureDetails() {
172179

173180

174181
return h("div", {className: 'checkin-container'}, [
175-
h("h3", "Featured Checkins"),
176182
h('div', checkins)
177183
]);
178184
}
179185

180186
function WeaverMap({
181-
title = "Explore",
182-
headerElement = null,
183187
mapboxToken,
184188
}: {
185189
headerElement?: React.ReactElement;
186190
title?: string;
187191
children?: React.ReactNode;
188192
mapboxToken?: string;
189193
}) {
190-
/* We apply a custom style to the panel container when we are interacting
191-
with the search bar, so that we can block map interactions until search
192-
bar focus is lost.
193-
We also apply a custom style when the infodrawer is open so we can hide
194-
the search bar on mobile platforms
195-
*/
196-
197194
const [isOpen, setOpen] = useState(false);
198195

199196
const [type, setType] = useState(types[0]);
@@ -220,8 +217,6 @@ function WeaverMap({
220217
},
221218
position: inspectPosition,
222219
},
223-
224-
h(FeatureDetails)
225220
);
226221

227222
// Left Panel
@@ -235,6 +230,10 @@ function WeaverMap({
235230
for(var i = 0; i < checkin.rating; i++) {
236231
ratingArr.push(h(Image, {className: "star", src: "blackstar.png"}));
237232
}
233+
234+
for(var i = 0; i < 5 - checkin.rating; i++) {
235+
ratingArr.push(h(Image, {className: "star", src: "emptystar.png"}));
236+
}
238237
let image;
239238

240239
if (imageExists("https://rockd.org/api/v1/protected/image/" + checkin.person_id + "/thumb_large/" + checkin.photo)) {
@@ -265,18 +264,25 @@ function WeaverMap({
265264
}
266265
}
267266

268-
let overlay = h("div.overlay-div", h(ExpansionPanel, {title: "Selected Checkins"},
269-
h('h1', { className: 'no-checkins' }, "No Checkin(s) Selected")
270-
));
271-
if (selectedCheckin) {
272-
console.log("CHECKINS LENGTH: " + checkins.length)
267+
// TODO: have run depend on changing mapRef
268+
let featuredCheckin = h(FeatureDetails);
269+
270+
let overlay = h("div.overlay-div", [
271+
h(ExpansionPanel, {title: "Selected Checkins"}, h('h1', { className: 'no-checkins' }, "No Checkin(s) Selected")),
272+
h(ExpansionPanel, {title: "Featured Checkins"}, featuredCheckin),
273+
]);
274+
275+
if (checkins.length > 0) {
273276
overlay = h(
274277
"div.overlay-div",
275278
[
276279
h(ExpansionPanel, {title: "Selected Checkins"}, selectedCheckin),
280+
h(ExpansionPanel, {title: "Featured Checkins"}, featuredCheckin),
277281
]);
278282
}
279283

284+
if(style == null) return null;
285+
280286
return h(
281287
"div.map-container",
282288
[
@@ -294,11 +300,11 @@ function WeaverMap({
294300
setPosition: onSelectPosition,
295301
}),
296302
]),
303+
304+
// The Overlay Div
305+
overlay,
297306
]
298307
),
299-
300-
// The Overlay Div
301-
overlay,
302308
]
303309
);
304310

@@ -313,25 +319,18 @@ function useMapStyle(type, mapboxToken) {
313319
? "mapbox://styles/mapbox/dark-v10"
314320
: "mapbox://styles/mapbox/light-v10";
315321

316-
const [actualStyle, setActualStyle] = useState(baseStyle);
322+
const [actualStyle, setActualStyle] = useState(null);
317323

318324
// Auto select sample type
319-
const overlayStyle = mergeStyles(_macrostratStyle, weaverStyle(types[0]));
320-
buildInspectorStyle(baseStyle, overlayStyle, {
321-
mapboxToken,
322-
inDarkMode: isEnabled,
323-
}).then((s) => {
324-
setActualStyle(s);
325-
});
326-
327325
useEffect(() => {
328326
const overlayStyle = mergeStyles(_macrostratStyle, weaverStyle(types[0]));
329-
buildInspectorStyle(baseStyle, overlayStyle, {
330-
mapboxToken,
331-
inDarkMode: isEnabled,
332-
}).then((s) => {
333-
setActualStyle(s);
334-
});
335-
}, [baseStyle, mapboxToken, isEnabled, type]);
327+
buildInspectorStyle(baseStyle, overlayStyle, {
328+
mapboxToken,
329+
inDarkMode: isEnabled,
330+
}).then((s) => {
331+
setActualStyle(s);
332+
});
333+
}, []);
334+
336335
return actualStyle;
337-
}
336+
}

0 commit comments

Comments
 (0)