Skip to content

Commit 033928a

Browse files
authored
Merge pull request #293 from UW-Macrostrat/data-handler
Lex Pages Data Handlers
2 parents 1a02793 + 5cf0b62 commit 033928a

File tree

48 files changed

+598
-238
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+598
-238
lines changed

packages/column-builder/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,4 @@ export interface ColSectionI {
178178
unit_count: number;
179179
top: string;
180180
bottom: string;
181-
}
181+
}
File renamed without changes.
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
import { usePageContext } from "vike-react/usePageContext";
2-
import { IndividualPage } from "../../../../src/components/lex/index";
1+
import { useData } from "vike-react/useData";
2+
import { LexItemPage } from "~/components/lex";
33

44
export function Page() {
5-
const pageContext = usePageContext();
6-
const id = parseInt(pageContext.urlParsed.pathname.split("/")[3]);
7-
return IndividualPage(id, "col_group_id", "groups");
5+
const { resData, colData, taxaData, refs } = useData();
6+
7+
return LexItemPage({
8+
id: resData.col_group_id,
9+
header: "groups",
10+
resData,
11+
colData,
12+
taxaData,
13+
refs
14+
});
815
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { pbdbDomain } from "@macrostrat-web/settings";
2+
import { fetchAPIData, fetchAPIRefs } from "~/_utils";
3+
4+
export async function data(pageContext) {
5+
const col_group_id = parseInt(pageContext.urlParsed.pathname.split("/")[3]);
6+
7+
// Await all API calls
8+
const [resData, colData, refs1, refs2] = await Promise.all([
9+
fetchAPIData("/defs/groups", { col_group_id }),
10+
fetchAPIData("/columns", { col_group_id, response: "long", format: "geojson" }),
11+
fetchAPIRefs("/fossils", { col_group_id }),
12+
fetchAPIRefs("/columns", { col_group_id }),
13+
]);
14+
15+
const refValues1 = Object.values(refs1)
16+
const refValues2 = Object.values(refs2)
17+
const refs = [...refValues1, ...refValues2]
18+
19+
const cols = colData?.features
20+
?.map((feature) => feature.properties.col_id)
21+
?.join(",");
22+
23+
let taxaData = null;
24+
if (cols) {
25+
const response = await fetch(
26+
`${pbdbDomain}/data1.2/occs/prevalence.json?limit=5&coll_id=${cols}`
27+
);
28+
taxaData = await response.json();
29+
}
30+
31+
return { resData: resData[0], colData, taxaData, refs };
32+
}

pages/lex/+Page.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ import { ContentPage } from "~/layouts";
33
import { apiV2Prefix } from "@macrostrat-web/settings";
44
import { useAPIResult } from "@macrostrat/ui-components";
55
import h from "./+Page.module.sass";
6+
import { useData } from "vike-react/useData";
67
import { Loading, Footer } from "~/components/general";
78

89
export function Page() {
9-
const res = useAPIResult(apiV2Prefix + "/stats?all")?.success?.data;
10-
11-
if (!res) return h(ContentPage, Loading);
10+
const { res } = useData();
1211

1312
const seen = new Set();
1413
const stats = res.filter((project) => {
@@ -17,8 +16,6 @@ export function Page() {
1716
return true;
1817
});
1918

20-
console.log("Lexicon stats", stats);
21-
2219
let columns = 0,
2320
packages = 0,
2421
units = 0,

pages/lex/+data.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { fetchAPIData } from "~/_utils";
2+
3+
export async function data() {
4+
const res = await fetchAPIData(`/stats`, { all: true });
5+
6+
return { res };
7+
}
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
import h from "./main.module.scss";
2-
import { useAPIResult } from "@macrostrat/ui-components";
3-
import { SETTINGS } from "@macrostrat-web/settings";
42
import { PageBreadcrumbs, StickyHeader } from "~/components";
5-
import { Card, Popover } from "@blueprintjs/core";
3+
import { Popover } from "@blueprintjs/core";
64
import { useState } from "react";
75
import { ContentPage } from "~/layouts";
86
import { asChromaColor } from "@macrostrat/color-utils";
7+
import { useData } from "vike-react/useData";
98
import { Loading, SearchBar } from "~/components/general";
109

1110
export function Page() {
1211
const [input, setInput] = useState("");
13-
const res = useAPIResult(SETTINGS.apiV2Prefix + "/defs/econs?all")?.success
14-
.data;
15-
16-
if (res == null) return h(Loading);
17-
18-
console.log(res);
12+
const { res } = useData();
1913

2014
const handleChange = (event) => {
2115
setInput(event.toLowerCase());

pages/lex/economics/+data.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { fetchAPIData } from "~/_utils";
2+
3+
export async function data() {
4+
const res = await fetchAPIData(`/defs/econs`, { all: true });
5+
6+
return { res };
7+
}

0 commit comments

Comments
 (0)