Skip to content

Commit 5f6bdc1

Browse files
authored
Merge pull request #56 from UW-Macrostrat/checkin-comments
Checkin comments
2 parents 3dc7de1 + 397fb28 commit 5f6bdc1

File tree

11 files changed

+160
-59
lines changed

11 files changed

+160
-59
lines changed

pages/checkin/@id/+Page.client.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Checkins } from "../index";
33
import { useData } from "vike-react/useData";
44

55
export function Page() {
6-
const { checkin } = useData();
7-
console.log("Checkin data:", checkin);
8-
return h(Checkins, { checkin });
6+
const { checkin, comments } = useData();
7+
return h(Checkins, { checkin, comments });
98
}

pages/checkin/@id/+data.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,14 @@ export async function data(pageContext) {
1111
}
1212
return response.json();
1313
});
14-
return { checkin: data.success.data[0] };
14+
15+
const comments = await fetch(
16+
`${rockdApiURL}/protected/comments?checkin_id=${id}`
17+
).then((response) => {
18+
if (!response.ok) {
19+
throw new Error(`HTTP error! status: ${response.status}`);
20+
}
21+
return response.json();
22+
});
23+
return { checkin: data.success.data[0], comments: comments.success.data };
1524
}

pages/checkin/index.ts

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { LngLatCoords } from "@macrostrat/map-interface";
22
import { useState, useCallback } from 'react';
33
import 'mapbox-gl/dist/mapbox-gl.css';
4-
import { BlankImage, Footer, getProfilePicUrl, getImageUrl } from "~/components/general";
5-
import { Icon } from "@blueprintjs/core";
4+
import { BlankImage, Footer, getProfilePicUrl, getImageUrl, Comments } from "~/components/general";
5+
import { Icon, Divider, H2 } from "@blueprintjs/core";
66
import h from "./main.module.sass";
77
import { SETTINGS } from "@macrostrat-web/settings";
88
import "@macrostrat/style-system";
@@ -21,34 +21,7 @@ function Map(props) {
2121
);
2222
}
2323

24-
export function Checkins({checkin}) {
25-
/*
26-
const [isOpen, setIsOpen] = useState(false);
27-
const toggleOverlay = useCallback(() => setIsOpen(open => !open), [setIsOpen]);
28-
29-
return h("div.container", [
30-
h('button', {
31-
className: "bp3-button bp3-intent-primary",
32-
onClick: toggleOverlay
33-
}, "Open Overlay"),
34-
h(Overlay2,
35-
{
36-
isOpen,
37-
onClose: toggleOverlay,
38-
className: "checkin-overlay",
39-
usePortal: true,
40-
canEscapeKeyClose: true,
41-
canOutsideClickClose: true,
42-
hasBackdrop: true,
43-
}, "hello"
44-
45-
)
46-
]);
47-
*/
48-
49-
const [overlayOpen, setOverlayOpen] = useState(false);
50-
const [showMap, setShowMap] = useState(false);
51-
24+
export function Checkins({checkin, comments}) {
5225
const center = {
5326
lat: checkin.lat,
5427
lng: checkin.lng
@@ -110,7 +83,7 @@ const [isOpen, setIsOpen] = useState(false);
11083

11184

11285
let main = h('div', { className: "container" }, [
113-
h('div', { className: showMap ? 'hide' : 'main'}, [
86+
h('div', { className: 'main'}, [
11487
h('div', { className: "checkin-head" }, [
11588
h('h1', checkin.notes),
11689
]),
@@ -123,9 +96,12 @@ const [isOpen, setIsOpen] = useState(false);
12396
}),
12497
h('div', { className: 'observations' }, observations),
12598
]),
126-
h('div', { className: showMap ? 'hide' : 'bottom' }, [
127-
h(Footer),
99+
h.if(comments?.length > 0)('div.comments-container', [
100+
h('h2', 'Comments'),
101+
h(Divider),
102+
h(Comments, { comments }),
128103
]),
104+
h(Footer),
129105
])
130106

131107
return main;

pages/checkin/main.module.sass

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,8 @@ h4
245245

246246
.error-img
247247
width: 50%
248-
text-align: center
248+
text-align: center
249+
250+
.comments-container
251+
width: 60%
252+
margin: 0 0 2em 20%

pages/terms/+Page.client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Footer } from "~/components/general";
22
import h from "./main.module.sass";
33
import "@macrostrat/style-system";
44

5-
export function Page() {
5+
export function Page() {
66
return h("div", { className: "main-page" }, [
77
h("div", { className: "content" }, [
88
h("div", { className: 'header' }, [

pages/trip/@id/+Page.client.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { Trips } from "../index";
33
import { useData } from "vike-react/useData";
44

55
export function Page() {
6-
const { data } = useData();
6+
const { data, commentsData } = useData();
7+
console.log("Trips data:", data);
8+
console.log("Comments data:", commentsData);
79

8-
return h(Trips, { data: data.success.data[0]});
10+
return h(Trips, { data: data.success.data[0], commentsData: commentsData.success.data });
911
}

pages/trip/@id/+data.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ export async function data(pageContext) {
1010
}
1111
return response.json();
1212
});
13-
14-
return { data}
13+
14+
const commentsData = await fetch(
15+
`${rockdApiURL}/protected/comments?trip_id=${pageContext.routeParams.id}`
16+
).then((response) => {
17+
if (!response.ok) {
18+
throw new Error(`HTTP error! status: ${response.status}`);
19+
}
20+
return response.json();
21+
});
22+
23+
return { data, commentsData }
1524
}

pages/trip/index.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import h from "./main.module.sass";
22
import { useState } from 'react';
33
import mapboxgl from 'mapbox-gl';
44
import 'mapbox-gl/dist/mapbox-gl.css';
5-
import { BlankImage, getProfilePicUrl, Image, createCheckins } from "~/components/general";
5+
import { BlankImage, getProfilePicUrl, Image, createCheckins, Comments } from "~/components/general";
66
import "@macrostrat/style-system";
7-
import { SETTINGS } from "@macrostrat-web/settings";
7+
import { rockdApiURL, SETTINGS } from "@macrostrat-web/settings";
88
import { DarkModeButton, useDarkMode } from "@macrostrat/ui-components";
9-
import { Divider, Icon, Spinner } from "@blueprintjs/core";
9+
import { Divider, Icon, Overlay2, Spinner } from "@blueprintjs/core";
1010
import {
1111
MapAreaContainer,
1212
MapMarker,
@@ -15,9 +15,10 @@ import {
1515
} from "@macrostrat/map-interface";
1616
import { useMapRef } from "@macrostrat/mapbox-react";
1717

18-
export function Trips({data}) {
18+
export function Trips({data, commentsData}) {
1919
const [showSatelite, setSatelite] = useState(false);
2020
console.log("Trips data:", data);
21+
console.log("Comments data:", commentsData);
2122

2223
const style = useMapStyle({showSatelite});
2324

@@ -28,7 +29,7 @@ export function Trips({data}) {
2829
data.updated = date.toLocaleDateString('en-US', options);
2930

3031
const toolbar = h(Toolbar, {showSatelite, setSatelite});
31-
const sidebar = h(SideBar, {data});
32+
const sidebar = h(SideBar, {data, commentsData});
3233

3334
if (!sidebar) {
3435
return h("div", { className: 'loading' }, [
@@ -101,11 +102,13 @@ function useMapStyle({showSatelite}) {
101102
return showSatelite ? SETTINGS.satelliteMapURL : useDarkMode()?.isEnabled ? SETTINGS.darkMapURL : SETTINGS.whiteMapURL;
102103
}
103104

104-
function SideBar({data}) {
105+
function SideBar({data, commentsData}) {
105106
const mapRef = useMapRef();
106107
const map = mapRef.current;
107108
const profile_pic = h(BlankImage, {src: getProfilePicUrl(data.person_id), className: "profile-pic-header"});
108109
const stops = data.stops;
110+
const [commentsOpen, setCommentsOpen] = useState(false);
111+
console.log("commentsOpen:", commentsOpen);
109112

110113
if(!map) return h("div", {className: "stop-container loading2"}, [
111114
h("h1", "Loading trip " + data.trip_id + "..."),
@@ -187,12 +190,34 @@ function SideBar({data}) {
187190
h('h4', {className: 'edited'}, "Edited " + data.updated),
188191
]),
189192
h('div', {className: 'download-button'}, [
190-
h('a', {className: 'kmz', href: import.meta.env.ROCKD_API_URL + "/trips/" + data.trip_id + "?format=kmz"}, "DOWNLOAD KMZ"),
193+
h('a', {className: 'kmz', href: rockdApiURL + "/trips/" + data.trip_id + "?format=kmz"}, "DOWNLOAD KMZ"),
191194
]),
192195
]),
193196
h("div.details", [
194197
h('h1', {className: 'park'}, data.name),
195198
h('p', {className: 'description'}, data.description),
199+
h.if(commentsData?.length > 0)('div', {className: 'download-button', onClick: () => setCommentsOpen(true)}, [
200+
h('div', {className: 'kmz'}, "View comments"),
201+
]),
202+
h.if(commentsData?.length > 0)(Overlay2, {className: 'overlay', isOpen: commentsOpen, usePortal: true}, [
203+
h('div', {className: 'overlay-content'}, [
204+
h('div.comments-container', [
205+
h('div.comments-header', [
206+
h('h2', {className: 'comments-title'}, "Comments"),
207+
h(Icon, {
208+
icon: "cross",
209+
className: "close-icon",
210+
onClick: () => {
211+
setCommentsOpen(false)
212+
},
213+
style: { cursor: "pointer", color: "red" },
214+
}),
215+
]),
216+
h(Divider),
217+
h(Comments, {comments: commentsData}),
218+
])
219+
])
220+
])
196221
]),
197222
]),
198223
h('div', { className: 'stop-bottom' }, [

pages/trip/main.module.sass

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
@each $name, $color in $colors
1313
--#{$name}: #{$color}
1414

15-
*
16-
padding: 0
17-
margin: 0
18-
1915
body
2016
&.bp5-dark
2117
color-scheme: dark
@@ -315,10 +311,12 @@ html, body, .wrapper, #react, .app, #map
315311
display: flex
316312
justify-content: center
317313
align-items: center
318-
a
314+
cursor: pointer
315+
316+
.kmz
319317
color: var(--text-emphasized-color)
320318

321-
a:hover
319+
.kmz:hover
322320
color: var(--text-emphasized-color)
323321
background-color: var(--scrollbar-thumb)
324322
text-decoration: none
@@ -386,3 +384,22 @@ html, body, .wrapper, #react, .app, #map
386384
#map
387385
width: 70%
388386
height: 100%
387+
388+
.overlay-content
389+
width: 70%
390+
height: 80vh
391+
display: flex
392+
justify-content: center
393+
align-items: center
394+
395+
h2
396+
margin: 0
397+
398+
.comments-container
399+
background-color: var(--background-color)
400+
width: 80%
401+
padding: 1em
402+
403+
.comments-header
404+
display: flex
405+
justify-content: space-between

src/components/general/index.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import {
55
useAPIResult,
66
useDarkMode,
77
} from "@macrostrat/ui-components";
8-
import { Icon } from "@blueprintjs/core";
8+
import { Icon, Divider } from "@blueprintjs/core";
99
import mapboxgl from "mapbox-gl";
1010
import { SETTINGS } from "@macrostrat-web/settings";
1111
import { rockdApiURL, rockdApiOldURL } from "@macrostrat-web/settings";
1212
import { useState } from "react";
13-
import { has } from "underscore";
1413

1514
export function Footer() {
1615
const isDarkMode = useDarkMode().isEnabled;
@@ -437,4 +436,40 @@ function Checkin({checkin, mapRef, setInspectPosition, len}) {
437436

438437
return temp
439438

439+
}
440+
441+
export function Comments({comments}) {
442+
const commentArr = [];
443+
444+
comments.forEach((item, index) => {
445+
const { created, comment, person_id, name, likes } = item;
446+
447+
const commentNode = h('div.comment', [
448+
h('div.comment-author', [
449+
h(BlankImage, {
450+
className: 'comment-pic',
451+
src: getProfilePicUrl(person_id),
452+
alt: "profile picture"
453+
}),
454+
h('p', { className: 'comment-author' }, name),
455+
]),
456+
h('p', { className: 'comment-text' }, comment),
457+
h('p', { className: 'comment-date' }, created),
458+
h('div.comment-likes', [
459+
h(Icon, { icon: 'thumbs-up', className: 'like-icon' }),
460+
h('p', { className: 'comment-likes' }, String(likes)),
461+
])
462+
]);
463+
464+
commentArr.push(commentNode);
465+
466+
// Add divider between comments (but not after the last one)
467+
if (index < comments.length - 1) {
468+
commentArr.push(h(Divider));
469+
}
470+
});
471+
472+
return h('div.comments', [
473+
...commentArr
474+
]);
440475
}

0 commit comments

Comments
 (0)