Skip to content

Commit f8ebdf9

Browse files
committed
move functions out explore page
1 parent f721dd3 commit f8ebdf9

File tree

1 file changed

+4
-205
lines changed

1 file changed

+4
-205
lines changed

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

Lines changed: 4 additions & 205 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,14 @@ import {
1212
} from "@macrostrat/map-interface";
1313
import { buildMacrostratStyle } from "@macrostrat/map-styles";
1414
import { mergeStyles } from "@macrostrat/mapbox-utils";
15-
import {
16-
useAPIResult,
17-
useDarkMode,
18-
} from "@macrostrat/ui-components";
15+
import { useDarkMode } from "@macrostrat/ui-components";
1916
import mapboxgl from "mapbox-gl";
2017
import { useCallback, useEffect, useState } from "react";
2118
import { tileserverDomain } from "@macrostrat-web/settings";
2219
import "./main.styl";
23-
import { BlankImage, Image } from "../index";
2420

25-
import {} from "./storybook";
26-
import { get } from "underscore";
21+
import { getCheckins, createFeaturedCheckins, getSelectedCheckins, formatCoordinates } from "./storybook"; // test for storybook
22+
2723

2824
let count = 0;
2925

@@ -93,29 +89,6 @@ function weaverStyle(type: object) {
9389
};
9490
}
9591

96-
function imageExists(image_url){
97-
var http = new XMLHttpRequest();
98-
99-
http.open('HEAD', image_url, false);
100-
http.send();
101-
102-
return http.status != 404;
103-
}
104-
105-
function getCheckins(lat1, lat2, lng1, lng2) {
106-
// abitrary bounds around click point
107-
let minLat = Math.floor(lat1 * 100) / 100;
108-
let maxLat = Math.floor(lat2 * 100) / 100;
109-
let minLng = Math.floor(lng1 * 100) / 100;
110-
let maxLng = Math.floor(lng2 * 100) / 100;
111-
112-
// change use map coords
113-
return useAPIResult("https://rockd.org/api/v2/protected/checkins?minlat=" + minLat +
114-
"&maxlat=" + maxLat +
115-
"&minlng=" + minLng +
116-
"&maxlng=" + maxLng);
117-
}
118-
11992
function FeatureDetails() {
12093
// return null;
12194
const mapRef = useMapRef();
@@ -242,157 +215,13 @@ function FeatureDetails() {
242215
if (result == null) return h("div.checkin-container",Spinner);
243216
result = result.success.data;
244217

245-
checkins = createCheckins(result, mapRef, true);
218+
checkins = createFeaturedCheckins(result, mapRef);
246219

247220
return h("div", {className: 'checkin-container'}, [
248221
h('div', checkins)
249222
]);
250223
}
251224

252-
function createCheckins(result, mapRef, showPin) {
253-
let checkins = [];
254-
let map = mapRef?.current;
255-
let stop = 0;
256-
257-
result.forEach((checkin) => {
258-
let pin = null;
259-
260-
if(showPin) {
261-
stop++;
262-
pin = h('div',
263-
{ src: "marker_container.png",
264-
className: "marker_container",
265-
onClick: () => {
266-
map.flyTo({center: [checkin.lng, checkin.lat], zoom: 12});
267-
}
268-
}, [
269-
h(Image, { src: "marker_red.png", className: "marker" }),
270-
h('span', { className: "marker-number" }, stop)
271-
])
272-
}
273-
274-
275-
// format rating
276-
let ratingArr = [];
277-
for(var i = 0; i < checkin.rating; i++) {
278-
ratingArr.push(h(Image, {className: "star", src: "blackstar.png"}));
279-
}
280-
281-
for(var i = 0; i < 5 - checkin.rating; i++) {
282-
ratingArr.push(h(Image, {className: "star", src: "emptystar.png"}));
283-
}
284-
let image;
285-
286-
if (imageExists("https://rockd.org/api/v1/protected/image/" + checkin.person_id + "/thumb_large/" + checkin.photo)) {
287-
image = h(BlankImage, {className: 'observation-img', src: "https://rockd.org/api/v1/protected/image/" + checkin.person_id + "/thumb_large/" + checkin.photo});
288-
} else {
289-
image = h(Image, { className: 'observation-img', src: "rockd.jpg"});
290-
}
291-
292-
293-
let temp = h('div', { className: 'checkin' }, [
294-
h('div', {className: 'checkin-header'}, [
295-
h('h3', {className: 'profile-pic'}, h(BlankImage, {src: "https://rockd.org/api/v2/protected/gravatar/" + checkin.person_id, className: "profile-pic"})),
296-
h('div', {className: 'checkin-info'}, [
297-
h('h3', {className: 'name'}, checkin.first_name + " " + checkin.last_name),
298-
h('h4', {className: 'edited'}, checkin.created),
299-
h('p', "Near " + checkin.near),
300-
h('h3', {className: 'rating'}, ratingArr),
301-
]),
302-
pin,
303-
]),
304-
h('p', {className: 'description'}, checkin.notes),
305-
h('a', {className: 'checkin-link', href: "/dev/test-site/checkin?checkin=" + checkin.checkin_id, target: "_blank"}, [
306-
image,
307-
h('div', {className: "image-details"}, [
308-
h('h1', "Details"),
309-
h(Image, {className: 'details-image', src: "explore/white-arrow.png"})
310-
])
311-
]),
312-
h('div', {className: 'checkin-footer'}, [
313-
h('div', {className: 'likes-container'}, [
314-
h(Image, {className: 'likes-image', src: "explore/thumbs-up.png"}),
315-
h('h3', {className: 'likes'}, checkin.likes),
316-
]),
317-
h('div', {className: 'observations-container'}, [
318-
h(Image, {className: 'observations-image', src: "explore/observations.png"}),
319-
h('h3', {className: 'comments'}, checkin.observations.length),
320-
]),
321-
h('div', {className: 'comments-container'}, [
322-
h(Image, {className: 'comments-image', src: "explore/comment.png"}),
323-
h('h3', {className: 'comments'}, checkin.comments),
324-
])
325-
]),
326-
]);
327-
328-
checkins.push(temp);
329-
});
330-
331-
return checkins;
332-
}
333-
334-
function createSelectedCheckins(result) {
335-
let checkins = [];
336-
337-
result.forEach((checkin) => {
338-
// format rating
339-
let ratingArr = [];
340-
for(var i = 0; i < checkin.rating; i++) {
341-
ratingArr.push(h(Image, {className: "star", src: "blackstar.png"}));
342-
}
343-
344-
for(var i = 0; i < 5 - checkin.rating; i++) {
345-
ratingArr.push(h(Image, {className: "star", src: "emptystar.png"}));
346-
}
347-
let image;
348-
349-
if (imageExists("https://rockd.org/api/v1/protected/image/" + checkin.person_id + "/thumb_large/" + checkin.photo)) {
350-
image = h(BlankImage, {className: 'observation-img', src: "https://rockd.org/api/v1/protected/image/" + checkin.person_id + "/thumb_large/" + checkin.photo});
351-
} else {
352-
image = h(Image, { className: 'observation-img', src: "rockd.jpg"});
353-
}
354-
355-
356-
let temp = h('div', { className: 'checkin' }, [
357-
h('div', {className: 'checkin-header'}, [
358-
h('h3', {className: 'profile-pic'}, h(BlankImage, {src: "https://rockd.org/api/v2/protected/gravatar/" + checkin.person_id, className: "profile-pic"})),
359-
h('div', {className: 'checkin-info'}, [
360-
h('h3', {className: 'name'}, checkin.first_name + " " + checkin.last_name),
361-
h('h4', {className: 'edited'}, checkin.created),
362-
h('p', "Near " + checkin.near),
363-
h('h3', {className: 'rating'}, ratingArr),
364-
]),
365-
]),
366-
h('p', {className: 'description'}, checkin.notes),
367-
h('a', {className: 'checkin-link', href: "/dev/test-site/checkin?checkin=" + checkin.checkin_id, target: "_blank"}, [
368-
image,
369-
h('div', {className: "image-details"}, [
370-
h('h1', "Details"),
371-
h(Image, {className: 'details-image', src: "explore/white-arrow.png"})
372-
])
373-
]),
374-
h('div', {className: 'checkin-footer'}, [
375-
h('div', {className: 'likes-container'}, [
376-
h(Image, {className: 'likes-image', src: "explore/thumbs-up.png"}),
377-
h('h3', {className: 'likes'}, checkin.likes),
378-
]),
379-
h('div', {className: 'observations-container'}, [
380-
h(Image, {className: 'observations-image', src: "explore/observations.png"}),
381-
h('h3', {className: 'comments'}, checkin.observations.length),
382-
]),
383-
h('div', {className: 'comments-container'}, [
384-
h(Image, {className: 'comments-image', src: "explore/comment.png"}),
385-
h('h3', {className: 'comments'}, checkin.comments),
386-
])
387-
]),
388-
]);
389-
390-
checkins.push(temp);
391-
});
392-
393-
return checkins;
394-
}
395-
396225
function WeaverMap({
397226
mapboxToken,
398227
}: {
@@ -486,24 +315,6 @@ function WeaverMap({
486315

487316
}
488317

489-
function getSelectedCheckins(result) {
490-
let checkins = [];
491-
492-
// Selected checkin
493-
if (result == null) {
494-
return null;
495-
} else {
496-
result = result.success.data;
497-
checkins = createSelectedCheckins(result);
498-
499-
if (checkins.length > 0) {
500-
return h("div", {className: 'checkin-container'}, checkins);
501-
} else {
502-
return null;
503-
}
504-
}
505-
}
506-
507318
function useMapStyle(type, mapboxToken) {
508319
const dark = useDarkMode();
509320
const isEnabled = dark?.isEnabled;
@@ -526,16 +337,4 @@ function useMapStyle(type, mapboxToken) {
526337
}, []);
527338

528339
return actualStyle;
529-
}
530-
531-
function formatCoordinates(latitude, longitude) {
532-
// Round latitude and longitude to 4 decimal places
533-
const roundedLatitude = latitude.toFixed(4);
534-
const roundedLongitude = longitude.toFixed(4);
535-
536-
const latitudeDirection = latitude >= 0 ? 'N' : 'S';
537-
const longitudeDirection = longitude >= 0 ? 'E' : 'W';
538-
539-
// Return the formatted string with rounded values
540-
return `${Math.abs(roundedLatitude)}° ${latitudeDirection}, ${Math.abs(roundedLongitude)}° ${longitudeDirection}`;
541340
}

0 commit comments

Comments
 (0)