Skip to content

Commit 06018b4

Browse files
committed
add data
1 parent e5c7b8d commit 06018b4

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
import { usePageContext } from "vike-react/usePageContext";
21
import { IndividualPage } from "../../../lex/index";
2+
import { useData } from "vike-react/useData";
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 { res, fossilRes, colData, taxaData } = useData();
6+
7+
return IndividualPage(
8+
res[0].col_group_id,
9+
"groups",
10+
res,
11+
fossilRes,
12+
colData,
13+
taxaData
14+
);
815
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { apiV2Prefix } from "@macrostrat-web/settings";
2+
import { fetchAPIData } 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 [res, fossilRes, colData] = await Promise.all([
9+
fetchAPIData("/defs/groups", { col_group_id }),
10+
(await fetch(apiV2Prefix + "/fossils?col_group_id=" + col_group_id)).json(),
11+
(
12+
await fetch(
13+
apiV2Prefix +
14+
"/columns?col_group_id=" +
15+
col_group_id +
16+
"&response=long&format=geojson"
17+
)
18+
).json(),
19+
]);
20+
21+
const cols = colData.success.data.features
22+
?.map((feature) => feature.properties.col_id)
23+
?.join(",");
24+
25+
let taxaData = null;
26+
if (cols) {
27+
const response = await fetch(
28+
`https://paleobiodb.org/data1.2/occs/prevalence.json?limit=5&coll_id=${cols}`
29+
);
30+
taxaData = await response.json();
31+
}
32+
33+
return { res, fossilRes, colData, taxaData };
34+
}

0 commit comments

Comments
 (0)