Skip to content

Commit 06b9a18

Browse files
committed
handle clicks
1 parent 5ac7179 commit 06b9a18

File tree

4 files changed

+38
-7
lines changed

4 files changed

+38
-7
lines changed

pages/lex/timescales/+Page.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export function Page() {
1515
const [clickedInterval, setClickedInterval] = useState(null);
1616
const res = useAPIResult(SETTINGS.apiV2Prefix + "/defs/timescales?all")?.success.data;
1717

18-
console.log("clickedInterval", clickedInterval);
1918
useEffect(() => {
2019
if (!clickedInterval) return;
2120

@@ -35,7 +34,7 @@ export function Page() {
3534

3635
fetchInterval();
3736
}, [clickedInterval]);
38-
37+
3938
if (res == null) return h("div", "Loading...");
4039

4140
const handleChange = (event) => {
@@ -99,7 +98,15 @@ export function Page() {
9998
},
10099
}),
101100
]),
102-
h(Timescale, { length: timescaleWidth, levels: [1,5], ageRange: [age[0], age[1]], absoluteAgeScale: true, onClick: handleClick })
101+
h('div.timescale',
102+
h(Timescale, {
103+
length: timescaleWidth,
104+
levels: [1,5],
105+
ageRange: [age[0], age[1]],
106+
absoluteAgeScale: true,
107+
onClick: handleClick
108+
}
109+
))
103110
]),
104111
h(Divider),
105112
h('div.timescale-list', filtered.map((data) => TimescaleItem({ data }))),

pages/lex/timescales/@id/+Page.client.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import { ContentPage } from "~/layouts";
77
import { usePageContext } from 'vike-react/usePageContext';
88
import { Timescale } from "@macrostrat/timescale";
99
import { titleCase } from "../../index";
10+
import { useState, useEffect } from "react";
1011

1112

1213
export function Page() {
1314
const pageContext = usePageContext();
1415
const id = parseInt(pageContext.urlParsed.pathname.split("/")[3]);
1516
const res = useAPIResult(SETTINGS.apiV2Prefix + "/defs/timescales?all")?.success.data;
17+
const [clickedInterval, setClickedInterval] = useState(null);
1618

1719
if (res == null) return h("div", "Loading...");
1820

@@ -22,15 +24,33 @@ export function Page() {
2224
if (timeRes == null) return h("div", "Timescale not found");
2325

2426
const { min_age, max_age, timescale } = timeRes;
25-
const width = window.screen.width;
26-
const timescaleWidth = width * .6;
27+
28+
const handleClick = (timescale) => {
29+
console.log("Clicked timescale:", timescale);
30+
/*
31+
const parent = timescale.target.parentElement;
32+
let selected;
33+
34+
// container clicked
35+
const containerClickedData = parent.className.split(" ")[1];
36+
37+
if(containerClickedData === "interval-label") {
38+
const labelClickedData = parent.parentElement.parentElement.className.split(" ")[1];
39+
selected = labelClickedData
40+
} else {
41+
selected = containerClickedData
42+
}
43+
44+
setClickedInterval(selected);
45+
*/
46+
}
2747

2848
return h(ContentPage, [
2949
h(PageBreadcrumbs, { title: "#" + id }),
3050
h('div.timescale-content', [
3151
h('h1', titleCase(timescale)),
3252
h('h3', max_age + " - " + min_age + " Ma"),
33-
h(Timescale, { levels: [0,5], ageRange: [min_age, max_age], orientation: "vertical" }),
53+
h('div.timescale', h(Timescale, { levels: [0,5], ageRange: [min_age, max_age], orientation: "vertical"})),
3454
])
3555
]);
3656
}

pages/lex/timescales/@id/main.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ tspan {
1616

1717
.visx-line {
1818
stroke: var(--text-color);
19-
}
19+
}

pages/lex/timescales/main.module.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,8 @@ h3, h2, h1 {
7070

7171
ul, li {
7272
margin: 0;
73+
}
74+
75+
.timescale {
76+
cursor: pointer;
7377
}

0 commit comments

Comments
 (0)