1+ import h from "./main.module.sass" ;
2+ import { StickyHeader , LinkCard , PageBreadcrumbs , Footer , BetaTag } from "~/components" ;
3+ import { ContentPage } from "~/layouts" ;
4+ import { usePageContext } from "vike-react/usePageContext" ;
5+ import { PostgRESTInfiniteScrollView } from "@macrostrat/ui-components" ;
6+ import { postgrestPrefix , apiDomain } from "@macrostrat-web/settings" ;
7+ import { LithologyTag , FlexRow , ExpansionPanel } from "~/components/lex/tag" ;
8+
9+ export function Page ( ) {
10+ const url = usePageContext ( ) . urlOriginal . split ( "?" ) [ 1 ] ;
11+
12+ if ( ! url ) {
13+ return h ( Base ) ;
14+ }
15+
16+ const params = getUrlParams ( url ) ;
17+ const idType = params . idType ;
18+ const id = params [ idType ] ;
19+ const color = params . color ;
20+ const name = params . name ;
21+
22+
23+ return h ( ContentPage , [
24+ h ( Header , { name, color, idType, id } ) ,
25+ h ( FilterData ) ,
26+ ] ) ;
27+ }
28+
29+ function Header ( { name, color, idType, id } ) {
30+ const map = {
31+ 'int_id' : "intervals" ,
32+ 'lith_id' : "lithologies" ,
33+ 'econ_id' : "economics" ,
34+ 'environ_id' : "environments" ,
35+ 'strat_name_id' : "strat-names" ,
36+ }
37+
38+ return h ( StickyHeader , { className : "header" } , [
39+ h ( PageBreadcrumbs , {
40+ title : h ( FlexRow , { gap : ".5em" , alignItems : "center" } , [
41+ h ( 'p.title' , 'Legends for ' ) ,
42+ h ( LithologyTag , { data : { name, color } , href : `/lex/${ map [ idType ] } /${ id } ` } ) ,
43+ ] ) ,
44+ } ) ,
45+ h ( BetaTag )
46+ ] ) ;
47+ }
48+
49+ function getUrlParams ( urlString ) {
50+ const params = new URLSearchParams ( urlString ) ;
51+ const result = { } ;
52+
53+ for ( const [ key , value ] of params . entries ( ) ) {
54+ result [ key ] = value ;
55+
56+ if ( key . toLowerCase ( ) . includes ( 'id' ) ) {
57+ result . idType = key ;
58+ }
59+ }
60+
61+ return result ;
62+ }
63+
64+ function Base ( ) {
65+ return h ( ContentPage , { className : 'page' } , [
66+ h ( StickyHeader , { className : "header" } , h ( PageBreadcrumbs , { title : "Legends" } ) ) ,
67+ h ( PostgRESTInfiniteScrollView , {
68+ route : postgrestPrefix + '/legend_liths' ,
69+ id_key : 'legend_id' ,
70+ limit : 20 ,
71+ itemComponent : LegendItem ,
72+ filterable : true ,
73+ searchColumns : [ { value : "map_unit_name" , label : "Map unit name" } ] ,
74+ } ) ,
75+ ] ) ;
76+ }
77+
78+ function BaseUnitItem ( { data } ) {
79+ const { id, col_id, strat_name } = data ;
80+
81+ return h ( LinkCard , {
82+ href : `/columns/${ col_id } #unit=${ id } ` ,
83+ title : strat_name ,
84+ } )
85+ }
86+
87+ function FilterData ( ) {
88+ const params = usePageContext ( ) . urlParsed . href . split ( "?" ) [ 1 ] . split ( "=" )
89+ const id = params [ 1 ] . split ( "&" ) [ 0 ]
90+
91+ return h ( PostgRESTInfiniteScrollView , {
92+ route : postgrestPrefix + `/legend_liths` ,
93+ id_key : "legend_id" ,
94+ limit : 20 ,
95+ extraParams : {
96+ lith_ids : `cs.{${ id } }` ,
97+ } ,
98+ filterable : true ,
99+ searchColumns : [ { value : "map_unit_name" , label : "Map unit name" } ] ,
100+ itemComponent : LegendItem ,
101+ } ) ;
102+ }
103+
104+ function LegendItem ( { data } ) {
105+ const { map_unit_name, legend_id, source_id } = data ;
106+
107+ return h ( LinkCard , {
108+ href : `/maps/${ source_id } ?legend_id=${ legend_id } ` ,
109+ title : h ( "div.title" , map_unit_name ) ,
110+ } ) ;
111+ }
0 commit comments