Skip to content

Commit afa0b43

Browse files
authored
Merge pull request #304 from UW-Macrostrat/search
Add lexicon search
2 parents 8714816 + 6e9fb48 commit afa0b43

File tree

4 files changed

+151
-42
lines changed

4 files changed

+151
-42
lines changed

pages/+Page.module.sass

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535

3636
.hero-content
3737
text-align: center
38+
display: flex
39+
flex-direction: column
40+
gap: 1em
3841

3942

4043
.cover-image
@@ -391,4 +394,4 @@
391394
.rock-info
392395
display: flex
393396
align-items: center
394-
gap: .5em
397+
gap: .5em

pages/+Page.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Image, Navbar, Footer, SiteTitle } from "~/components/general";
1+
import { Image, Navbar, Footer, SiteTitle, SearchBar } from "~/components/general";
22
import h from "./+Page.module.sass";
33
import { LinkCard } from "~/components/cards";
44
import { useData } from "vike-react/useData";
@@ -152,4 +152,4 @@ function MacrostratStats() {
152152
h("span.top-stat-label", {}, "Projects"),
153153
]),
154154
]);
155-
}
155+
}

pages/lex/+Page.module.sass

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,35 @@
1111

1212
.stat:first-child
1313
border-left: 1px solid var(--text-color)
14-
14+
15+
16+
.search-container
17+
18+
.search-results
19+
background-color: var(--panel-background-color)
20+
21+
.category
22+
text-align: left
23+
background-color: var(--accent-secondary-color)
24+
padding: 5px 10px
25+
margin: 0
26+
border-top: solid var(--panel-background-color) 2px
27+
28+
.items
29+
display: flex
30+
flex-direction: column
31+
32+
.item
33+
text-align: left
34+
padding: 2px 20px
35+
cursor: pointer
36+
width: 100%
37+
text-decoration: none
38+
39+
&:hover
40+
background-color: var(--accent-secondary-hover-color)
41+
42+
.content-page
43+
display: flex
44+
flex-direction: column
45+
gap: 1em

pages/lex/+Page.ts

Lines changed: 113 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ import { apiV2Prefix } from "@macrostrat-web/settings";
44
import { useAPIResult } from "@macrostrat/ui-components";
55
import h from "./+Page.module.sass";
66
import { useData } from "vike-react/useData";
7-
import { Loading, Footer } from "~/components/general";
7+
import { Footer } from "~/components/general";
8+
import { SearchBar } from "~/components/general";
9+
import { useState } from "react";
810

911
export function Page() {
1012
const { res } = useData();
13+
const [ showBody, setShowBody ] = useState(true);
1114

1215
const seen = new Set();
1316
const stats = res.filter((project) => {
@@ -29,9 +32,8 @@ export function Page() {
2932
});
3033

3134
return h("div", [
32-
h(ContentPage, [
35+
h(ContentPage, { className: "content-page" }, [
3336
h(PageHeader, { title: "Lexicon" }),
34-
3537
h("p", [
3638
"This is the homepage of Macrostrat's geological lexicons, which are assembled from many data sources including Canada's ",
3739
h(
@@ -50,42 +52,46 @@ export function Page() {
5052
h("p.stat", `${formatNumber(measurements)} measurements`),
5153
]),
5254

53-
h("h2", "Dictionaries"),
54-
h(
55-
LinkCard,
56-
{ href: "/lex/strat-names", title: "Stratigraphic names" },
57-
"Names of rock units, organized hierarchically and concepts that capture relationships between differently-named rock units"
58-
),
59-
60-
h(
61-
LinkCard,
62-
{ href: "/lex/intervals", title: "Intervals" },
63-
"Time intervals"
64-
),
65-
h(
66-
LinkCard,
67-
{ href: "/lex/timescales", title: "Timescales" },
68-
"Continuous representations of relative geologic time"
69-
),
70-
h(
71-
LinkCard,
72-
{ href: "/lex/lithology", title: "Lithologies" },
73-
"Names of geologic materials"
74-
),
75-
h(
76-
LinkCard,
77-
{ href: "/lex/environments", title: "Environments" },
78-
"Depositional environments and formation mechanisms"
79-
),
80-
h(
81-
LinkCard,
82-
{ href: "/lex/economics", title: "Economics" },
83-
"Economic uses of geologic materials"
84-
),
55+
h(SearchContainer, { setShowBody}),
56+
57+
h.if(showBody)('div.body-content', [
58+
h("h2", "Dictionaries"),
59+
h(
60+
LinkCard,
61+
{ href: "/lex/strat-names", title: "Stratigraphic names" },
62+
"Names of rock units, organized hierarchically and concepts that capture relationships between differently-named rock units"
63+
),
8564

86-
h("p", [
87-
h("strong", h("a", { href: "/sift" }, "Sift")),
88-
", Macrostrat's legacy lexicon app, is still available for use as it is gradually brought into this new framework.",
65+
h(
66+
LinkCard,
67+
{ href: "/lex/intervals", title: "Intervals" },
68+
"Time intervals"
69+
),
70+
h(
71+
LinkCard,
72+
{ href: "/lex/timescales", title: "Timescales" },
73+
"Continuous representations of relative geologic time"
74+
),
75+
h(
76+
LinkCard,
77+
{ href: "/lex/lithology", title: "Lithologies" },
78+
"Names of geologic materials"
79+
),
80+
h(
81+
LinkCard,
82+
{ href: "/lex/environments", title: "Environments" },
83+
"Depositional environments and formation mechanisms"
84+
),
85+
h(
86+
LinkCard,
87+
{ href: "/lex/economics", title: "Economics" },
88+
"Economic uses of geologic materials"
89+
),
90+
91+
h("p", [
92+
h("strong", h("a", { href: "/sift" }, "Sift")),
93+
", Macrostrat's legacy lexicon app, is still available for use as it is gradually brought into this new framework.",
94+
]),
8995
]),
9096
]),
9197
h(Footer),
@@ -95,3 +101,72 @@ export function Page() {
95101
function formatNumber(num) {
96102
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
97103
}
104+
105+
function SearchContainer({setShowBody}) {
106+
const [input, setInput] = useState("");
107+
const url = apiV2Prefix + "/defs/autocomplete?query=" + input;
108+
const data = useAPIResult(url)?.success?.data || [];
109+
110+
111+
if(data && input.length > 0) {
112+
setShowBody(false);
113+
} else {
114+
setShowBody(true);
115+
}
116+
117+
118+
return h("div.search-container", [
119+
h(SearchBar, {
120+
placeholder: "Search the geologic lexicon...",
121+
onChange: (e) => setInput(e),
122+
}),
123+
h(SearchResults, { data }),
124+
]);
125+
}
126+
127+
function SearchResults({ data }) {
128+
129+
const categories = [
130+
"columns",
131+
"econs",
132+
// "econ_types",
133+
// "econ_classes",
134+
"environments",
135+
// "environment_types",
136+
// "environment_classes",
137+
"groups",
138+
"intervals",
139+
"lithologies",
140+
// "lithology_types",
141+
// "lithology_classes",
142+
// "lithology_attributes",
143+
"projects",
144+
"strat_name_concepts",
145+
// "strat_name_orphans",
146+
// "structures",
147+
// "minerals",
148+
];
149+
150+
return h.if(Object.keys(data).length > 0)("div.search-results", [
151+
categories?.map((category) => {
152+
const items = data?.[category];
153+
if (!items || items?.length === 0) return;
154+
155+
const link = category === "econs" ?
156+
"economics" :
157+
category === "lithologies" ?
158+
"lithology" :
159+
category === "strat_name_concepts" ?
160+
"strat-name-concepts" : category
161+
162+
return h("div.search-category", [
163+
h("h3.category", (category.charAt(0).toUpperCase() + category.slice(1)).replace(/_/g, " ")),
164+
h('div.items', items?.map((item) => {
165+
const { name } = item;
166+
return h("a.item", { href: `/lex/${link}/${item.id}` }, name.charAt(0).toUpperCase() + name.slice(1));
167+
})),
168+
]);
169+
}),
170+
])
171+
172+
}

0 commit comments

Comments
 (0)