@@ -4,10 +4,13 @@ import { apiV2Prefix } from "@macrostrat-web/settings";
44import { useAPIResult } from "@macrostrat/ui-components" ;
55import h from "./+Page.module.sass" ;
66import { 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
911export 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() {
95101function 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