Skip to content

Commit

Permalink
Use sources api v3 for edit tables
Browse files Browse the repository at this point in the history
  • Loading branch information
CannonLock committed Dec 21, 2023
1 parent 0f2d997 commit 2ea0b01
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
22 changes: 14 additions & 8 deletions src/pages/maps/@id/edit/index.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@ import { SETTINGS } from "~/settings";
import h from "@macrostrat/hyper";
import { ClientOnly } from "~/renderer/client-only";

const apiAddress = SETTINGS.apiDomain + "/api/v2/defs/sources";
const apiAddress = import.meta.env.VITE_MACROSTRAT_INGEST_API + "/sources/";

export async function onBeforeRender(pageContext: PageContextBuiltInServer) {
const { id } = pageContext.routeParams;

const params = new URLSearchParams({
format: "geojson",
source_id: id,
});
const response = await fetch(apiAddress + "?" + params);
const response = await fetch(apiAddress + id);
const data: any = await response.json();
const map = data?.success?.data?.features[0];
const map = {
"type": "Feature",
"geometry": {
...data.geometry
},
properties: {
...data
}
}

console.log(map, apiAddress + id, map.type)

return {
pageContext: {
Expand All @@ -24,7 +30,7 @@ export async function onBeforeRender(pageContext: PageContextBuiltInServer) {
},
documentProps: {
// The page's <title>
title: map.properties.name,
title: data.name,
},
},
};
Expand Down
12 changes: 8 additions & 4 deletions src/pages/maps/index.page.server.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import fetch from "node-fetch";
import { SETTINGS } from "~/settings";

const apiAddress = SETTINGS.apiDomain + "/api/v2/defs/sources";
const apiAddress = import.meta.env.VITE_MACROSTRAT_INGEST_API + "/sources";

export async function onBeforeRender(pageContext) {
// `.page.server.js` files always run in Node.js; we could use SQL/ORM queries here.
const response = await fetch(apiAddress + "?format=json");
const res = await response.json();
let sources = res.success.data;
const url = new URL(apiAddress);
url.searchParams.set("page_size", "9999");



const response = await fetch(url.toString());
const sources = await response.json();
sources.sort((a, b) => a.source_id - b.source_id);

const pageProps = { sources };
Expand Down

0 comments on commit 2ea0b01

Please sign in to comment.