Skip to content

Commit 1a148df

Browse files
authored
Merge pull request #65 from UW-Macrostrat/checkin-linking
Litholgies, strat names, and intervals clickable
2 parents c9fc7a8 + aa69915 commit 1a148df

File tree

5 files changed

+312
-81
lines changed

5 files changed

+312
-81
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"@macrostrat-web/utility-functions": "workspace:*",
5555
"@macrostrat/color-utils": "^1.0.0",
5656
"@macrostrat/corelle": "^2.0.1",
57-
"@macrostrat/data-components": "latest",
57+
"@macrostrat/data-components": "^0.2.0",
5858
"@macrostrat/form-components": "^0.1.2",
5959
"@macrostrat/hyper": "^3.0.6",
6060
"@macrostrat/map-interface": "^1.2.2",

packages/settings/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { getRuntimeConfig } from "./utils";
33

44
export const rockdApiURL = getRuntimeConfig("ROCKD_API_URL");
5+
export const macrostratApiURL = getRuntimeConfig("MACROSTRAT_API_DOMAIN");
56
export const rockdApiOldURL = "https://rockd.org/api/v2/";
67

78
export const darkMapURL =

pages/checkin/index.ts

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import 'mapbox-gl/dist/mapbox-gl.css';
44
import { BlankImage, Footer, getProfilePicUrl, getImageUrl, Comments } from "~/components/general";
55
import { Icon, Divider, H2 } from "@blueprintjs/core";
66
import h from "./main.module.sass";
7-
import { SETTINGS } from "@macrostrat-web/settings";
7+
import { rockdApiOldURL, SETTINGS } from "@macrostrat-web/settings";
88
import "@macrostrat/style-system";
99
import { Overlay2 } from "@blueprintjs/core";
1010
import { LithologyList } from "@macrostrat/data-components";
1111
import { ClientOnly } from "vike-react/ClientOnly";
12+
import { macrostratApiURL } from "@macrostrat-web/settings";
1213

1314
function Map(props) {
1415
return h(
@@ -59,14 +60,13 @@ export function Checkins({checkin, comments}) {
5960
checkin.observations.forEach(observation => {
6061
// if photo exists
6162
const imageSrc = getImageUrl(checkin.person_id, observation.photo);
62-
let observationBody = observationFooter(observation);
6363

6464
observations.push(
6565
h('div', {className: 'observation'}, [
6666
h('a', {href: "/photo/" + observation.photo},
6767
h(BlankImage, { className: 'observation-image', src: imageSrc })
6868
),
69-
observationBody,
69+
h(ObservationFooter, {observation}),
7070
])
7171
);
7272
});
@@ -136,7 +136,7 @@ function Overlay({checkin, center, LngLatProps, ratingArr, profile_pic}) {
136136
])
137137
}
138138

139-
function observationFooter(observation) {
139+
export function ObservationFooter({observation}) {
140140
const LngLatProps = {
141141
position: {
142142
lat: observation.lat,
@@ -172,22 +172,30 @@ function observationFooter(observation) {
172172
return `#${red}${green}${blue}`;
173173
}
174174

175-
let obsAge = observation.age_est ? observation.age_est.name + " (" + observation.age_est.b_age + " - " + observation?.age_est?.t_age + ")" : null;
176-
177175
let lithologies = [];
178176
rocks.liths?.forEach(lith => {
179177
if(!lith.color.includes("#")) {
180178
lithologies.push({
181-
name: lith.name,
182-
color: rgbaStringToHex(lith.color)});
179+
...lith,
180+
color: rgbaStringToHex(lith.color),
181+
});
183182
} else {
184183
lithologies.push(lith);
185184
}
186185
});
187186

187+
if(rocks.interval?.name) {
188+
lithologies.push({
189+
name: rocks.interval.name,
190+
int_id: rocks.interval.int_id,
191+
color: `rgba(${rocks.interval.color})`,
192+
})
193+
}
194+
188195
if (rocks.strat_name?.strat_name_long) {
189196
lithologies.push({
190197
name: rocks.strat_name?.strat_name_long,
198+
strat_id: rocks.strat_name?.strat_name_id
191199
})
192200
}
193201

@@ -197,16 +205,6 @@ function observationFooter(observation) {
197205
})
198206
}
199207

200-
if(obsAge) {
201-
lithologies.push({
202-
name: obsAge
203-
})
204-
}
205-
if(rocks.interval?.name) {
206-
lithologies.push({
207-
name: rocks.interval.name
208-
})
209-
}
210208
if(observation.orientation.feature?.name) {
211209
lithologies.push({
212210
name: observation.orientation.feature?.name
@@ -215,14 +213,26 @@ function observationFooter(observation) {
215213

216214
const show = lithologies.length > 0 || rocks?.notes?.length > 0 && observation.lat && rocks.strat_name?.strat_name_long;
217215

216+
const handleClick = (e, data) => {
217+
if (data.int_id) {
218+
window.open(macrostratApiURL + `/lex/intervals/${data.int_id}`, '_blank');
219+
}
220+
if (data.strat_id) {
221+
window.open(macrostratApiURL + `/lex/strat-names/${data.strat_id}`, '_blank');
222+
}
223+
if (data.lith_id) {
224+
window.open(macrostratApiURL + `/lex/lithology/${data.lith_id}`, '_blank');
225+
}
226+
};
227+
218228
// observation body
219229
return h.if(show)("div", {className: 'observation-body'}, [
220230
observation.lat && rocks.strat_name?.strat_name_long ? h('h4', {className: 'observation-header'}, [
221231
rocks.strat_name?.strat_name_long,
222232
observation.lat ? LngLatCoords(LngLatProps) : null,
223233
]) : null,
224234
h('div', {className: 'observation-details'}, [
225-
h(LithologyList, { lithologies }),
235+
h(LithologyList, { lithologies, onClickItem: handleClick }),
226236
h('p', {className: "notes"}, rocks.notes),
227237
]),
228238
]);

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

Lines changed: 51 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { LithologyList } from "@macrostrat/data-components";
1414
import { useDarkMode } from "@macrostrat/ui-components";
1515
import { usePageContext } from "vike-react/usePageContext";
1616
import { useData } from "vike-react/useData";
17+
import { macrostratApiURL } from "@macrostrat-web/settings";
18+
import { ObservationFooter } from "#/checkin";
1719

1820
export function Page() {
1921
const { checkin } = useData();
@@ -81,32 +83,44 @@ function ObservationContent({ observation, setBody }) {
8183
.padStart(2, "0")}${b.toString(16).padStart(2, "0")}`;
8284
}
8385

84-
let lithologies = [];
85-
rocks.liths?.forEach((lith) => {
86-
if (!lith.color.includes("#")) {
87-
lithologies.push({ name: lith.name, color: rgbaStringToHex(lith.color) });
88-
} else {
89-
lithologies.push(lith);
86+
let lithologies = [];
87+
rocks.liths?.forEach(lith => {
88+
if(!lith.color.includes("#")) {
89+
lithologies.push({
90+
...lith,
91+
color: rgbaStringToHex(lith.color),
92+
});
93+
} else {
94+
lithologies.push(lith);
95+
}
96+
});
97+
98+
if(rocks.interval?.name) {
99+
lithologies.push({
100+
name: rocks.interval.name,
101+
int_id: rocks.interval.int_id,
102+
color: `rgba(${rocks.interval.color})`,
103+
})
90104
}
91-
});
92105

93-
if (rocks.strat_name?.strat_name_long) {
94-
lithologies.push({ name: rocks.strat_name.strat_name_long });
95-
}
96-
if (rocks.map_unit?.unit_name) {
97-
lithologies.push({ name: rocks.map_unit.unit_name });
98-
}
99-
if (observation.age_est) {
100-
lithologies.push({
101-
name: `${observation.age_est.name} (${observation.age_est.b_age} - ${observation.age_est.t_age})`,
102-
});
103-
}
104-
if (rocks.interval?.name) {
105-
lithologies.push({ name: rocks.interval.name });
106-
}
107-
if (observation.orientation.feature?.name) {
108-
lithologies.push({ name: observation.orientation.feature.name });
109-
}
106+
if (rocks.strat_name?.strat_name_long) {
107+
lithologies.push({
108+
name: rocks.strat_name?.strat_name_long,
109+
strat_id: rocks.strat_name?.strat_name_id
110+
})
111+
}
112+
113+
if(rocks.map_unit?.unit_name) {
114+
lithologies.push({
115+
name: rocks.map_unit?.unit_name
116+
})
117+
}
118+
119+
if(observation.orientation.feature?.name) {
120+
lithologies.push({
121+
name: observation.orientation.feature?.name
122+
})
123+
}
110124

111125
const LngLatProps = {
112126
position: {
@@ -119,22 +133,25 @@ function ObservationContent({ observation, setBody }) {
119133

120134
const show = lithologies.length > 0 || rocks?.notes?.length > 0 && observation.lat && rocks.strat_name?.strat_name_long
121135

136+
const handleClick = (e, data) => {
137+
if (data.int_id) {
138+
window.open(macrostratApiURL + `/lex/intervals/${data.int_id}`, '_blank');
139+
}
140+
if (data.strat_id) {
141+
window.open(macrostratApiURL + `/lex/strat-names/${data.strat_id}`, '_blank');
142+
}
143+
if (data.lith_id) {
144+
window.open(macrostratApiURL + `/lex/lithology/${data.lith_id}`, '_blank');
145+
}
146+
};
147+
122148
return h.if(show)("div", { className: "observation-body" }, [
123149
h(Icon, {
124150
className: "close-body",
125151
icon: "ban-circle",
126152
onClick: () => setBody(false),
127153
}),
128-
observation.lat && rocks.strat_name?.strat_name_long
129-
? h("h4", { className: "observation-header" }, [
130-
rocks.strat_name.strat_name_long,
131-
LngLatCoords(LngLatProps),
132-
])
133-
: null,
134-
h.if(lithologies || rocks)("div", { className: "observation-details" }, [
135-
h(LithologyList, { lithologies }),
136-
h("p", { className: "notes" }, rocks.notes),
137-
]),
154+
h(ObservationFooter, { observation }),
138155
]);
139156
}
140157

0 commit comments

Comments
 (0)