Skip to content

Commit 7a9c024

Browse files
authored
Merge pull request #288 from UW-Macrostrat/strat-name-prototype
Strat Name Prototype
2 parents e554184 + bef9a2c commit 7a9c024

File tree

9 files changed

+125
-291
lines changed

9 files changed

+125
-291
lines changed

pages/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import h from "./layout.module.sass";
22
import { MacrostratIcon } from "~/components";
33
import { SETTINGS } from "@macrostrat-web/settings";
44
import { DarkModeButton, useAPIResult } from "@macrostrat/ui-components";
5-
import { Spinner } from "@blueprintjs/core";
5+
import { Spinner, Card, Icon } from "@blueprintjs/core";
66

77
export function Image({ src, className, width, height }) {
88
const srcWithAddedPrefix =
@@ -76,3 +76,14 @@ export function BlankImage({ src, className, width, height }) {
7676
export function Loading() {
7777
return h("div.loading", h(Spinner));
7878
}
79+
80+
export function SearchBar({ onChange, placeholder = "Search..." }) {
81+
return h(Card, { className: "search-bar" }, [
82+
h(Icon, { icon: "search" }),
83+
h("input", {
84+
type: "text",
85+
placeholder,
86+
onChange: (e) => onChange(e.target.value),
87+
}),
88+
])
89+
}

pages/layout.module.sass

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,23 @@
9797
display: flex
9898
flex-direction: column
9999
gap: 2em
100+
101+
.search-bar
102+
display: flex
103+
gap: 5px
104+
align-items: center
105+
justify-content: center
106+
107+
input
108+
width: 100%
109+
padding: 0.5em
110+
border-radius: 0.2em
111+
border: none
112+
background-color: var(--background-color)
113+
color: var(--text-emphasized-color)
114+
font-size: 1em
115+
margin: 3px
116+
117+
&:focus
118+
outline: none
119+
box-shadow: 0 0 0.2em var(--text-emphasized-color)

pages/lex/+Page.mdx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,11 @@ the USGS's [Geolex](https://ngmdb.usgs.gov/Geolex/search), and other
99
sources. The lexicon is continually updated in partnership with
1010
researchers and data providers.
1111

12-
## Stratigraphic names
12+
## Dictionaries
1313

1414
<LinkCard href="/lex/strat-names" title="Stratigraphic names">
15-
Names of rock units, organized hierarchically
16-
</LinkCard>
17-
<LinkCard href="/lex/strat-name-concepts" title="Stratigraphic concepts">
18-
Concepts that capture relationships between differently-named rock units
15+
Names of rock units, organized hierarchically as well as concepts that capture relationships between differently-named rock units
1916
</LinkCard>
20-
21-
## Dictionaries
22-
2317
<LinkCard href="/lex/intervals" title="Intervals">
2418
Time intervals
2519
</LinkCard>
Lines changed: 3 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,5 @@
1-
import h from "./main.module.scss";
2-
import {
3-
useAPIResult,
4-
InfiniteScroll,
5-
LoadingPlaceholder,
6-
} from "@macrostrat/ui-components";
7-
import { SETTINGS } from "@macrostrat-web/settings";
8-
import {
9-
PageHeader,
10-
Link,
11-
AssistantLinks,
12-
DevLinkButton,
13-
LinkCard,
14-
PageBreadcrumbs,
15-
} from "~/components";
16-
import { Card, Icon, Spinner, RangeSlider } from "@blueprintjs/core";
17-
import { useState, useEffect, useRef } from "react";
18-
import { ContentPage } from "~/layouts";
19-
import { Loading } from "../../index";
1+
import { StratPage } from "../strat-names/+Page.client";
202

213
export function Page() {
22-
const [input, setInput] = useState("");
23-
const [lastID, setLastID] = useState(0);
24-
const [data, setData] = useState([]);
25-
const pageSize = 20;
26-
const result = useStratData(lastID, input, pageSize);
27-
28-
useEffect(() => {
29-
if (result) {
30-
setData((prevData) => [...prevData, ...result]);
31-
}
32-
}, [result]);
33-
34-
useEffect(() => {
35-
// Example: Reset data if lastID changes
36-
setData([]);
37-
}, [input]);
38-
39-
if (data == null) return h(Loading);
40-
41-
const handleChange = (event) => {
42-
setInput(event.target.value.toLowerCase());
43-
};
44-
45-
return h(ContentPage, [
46-
h(PageBreadcrumbs, { title: "Strat Name Concepts" }),
47-
h("div.sift-link", [
48-
h("p", "This page is is in development."),
49-
h(
50-
"a",
51-
{ href: "/sift/definitions/strat_name_concepts", target: "_blank" },
52-
"View in Sift"
53-
),
54-
]),
55-
h(Card, { className: "filters" }, [
56-
h("h2", "Filter"),
57-
h("div.search-bar", [
58-
h(Icon, { icon: "search" }),
59-
h("input", {
60-
type: "text",
61-
placeholder: "Filter by name...",
62-
onChange: handleChange,
63-
}),
64-
]),
65-
]),
66-
h(
67-
"div.strat-list",
68-
h(
69-
"div.strat-items",
70-
data.map((data) => h(StratItem, { data }))
71-
)
72-
),
73-
LoadMoreTrigger({ data, setLastID, pageSize, result }),
74-
]);
75-
}
76-
77-
function StratItem({ data }) {
78-
const { name, concept_id } = data;
79-
80-
return h(LinkCard, { href: "/lex/strat-name-concepts/" + concept_id }, name);
81-
}
82-
83-
function useStratData(lastID, input, pageSize) {
84-
const result = useAPIResult(
85-
`${SETTINGS.apiV2Prefix}/defs/strat_name_concepts?page_size=${pageSize}&last_id=${lastID}&concept_like=${input}`
86-
);
87-
return result?.success?.data;
88-
}
89-
90-
function LoadMoreTrigger({ data, setLastID, pageSize, result }) {
91-
const ref = useRef(null);
92-
93-
useEffect(() => {
94-
if (!ref.current) return;
95-
96-
const observer = new IntersectionObserver(([entry]) => {
97-
if (entry.isIntersecting) {
98-
if (data.length > 0) {
99-
setLastID(data[data.length - 1].concept_id);
100-
}
101-
}
102-
});
103-
104-
observer.observe(ref.current);
105-
106-
return () => observer.disconnect();
107-
}, [data, setLastID]);
108-
109-
return h.if(result?.length == pageSize)("div.load-more", { ref }, h(Spinner));
110-
}
4+
return StratPage({ show: true });
5+
}

pages/lex/strat-name-concepts/@id/+Page.client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ export function Page() {
55
const pageContext = usePageContext();
66
const id = parseInt(pageContext.urlParsed.pathname.split("/")[3]);
77
return IndividualPage(id, "concept_id", "strat_name_concepts");
8-
}
8+
}

pages/lex/strat-name-concepts/@id/main.scss

Lines changed: 0 additions & 70 deletions
This file was deleted.

pages/lex/strat-name-concepts/main.module.scss

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)