Skip to content

Commit

Permalink
Update Ingest Page
Browse files Browse the repository at this point in the history
  • Loading branch information
CannonLock committed Aug 7, 2024
1 parent 29e649d commit da377ba
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
39 changes: 21 additions & 18 deletions pages/maps/ingestion/+Page.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AnchorButton } from "@blueprintjs/core";
import { ingestPrefix } from "@macrostrat-web/settings";
import hyper from "@macrostrat/hyper";
import { useEffect, useState } from "react";
import react, { useCallback, useEffect, useState } from "react";
import { PageBreadcrumbs } from "~/components";
import { usePageProps } from "~/renderer/usePageProps";
import { usePageContext } from "vike-react/usePageContext";
import { IngestProcessCard } from "./components";
import styles from "./main.module.sass";
import { AuthStatus } from "@macrostrat/auth-components";
Expand All @@ -14,39 +14,42 @@ import Tag from "./components/Tag";
const h = hyper.styled(styles);

export function Page() {
const { user, url } = usePageProps();
const { user } = usePageContext();

const [ingestProcess, setIngestProcess] = useState<IngestProcess[]>([]);
const [ingestFilter, setIngestFilter] = useState<URLSearchParams>(undefined);
const [tags, setTags] = useState<string[]>([]);

const updateTags = useCallback(() => {
getTags().then((tags) => setTags(tags));
}, []);

const updateIngestProcesses = useCallback(() => {
getIngestProcesses(ingestFilter).then((ingestProcesses) => {
setIngestProcess(ingestProcesses);
});
}, [ingestFilter]);

// Get the initial data with the filter from the URL
useEffect(() => {
react.useEffect(() => {
// Get the ingest process data
const url = new URL(window.location.href);
const searchParams = new URLSearchParams(url.search);
searchParams.set("state", "not.eq.abandoned");
setIngestFilter(searchParams);
getIngestProcesses(searchParams).then((ingestProcesses) => {
setIngestProcess(ingestProcesses);
});

// Get the current set of tags
getTags().then((tags) => setTags(tags));
updateIngestProcesses();
updateTags();

// Set up the popstate event listener
window.onpopstate = () => {
getIngestProcesses(ingestFilter).then((ingestProcesses) => {
setIngestProcess(ingestProcesses);
});
updateIngestProcesses();
};
}, []);

// Re-fetch data when the filter changes
useEffect(() => {
react.useEffect(() => {
if (ingestFilter) {
getIngestProcesses(ingestFilter).then((ingestProcesses) => {
setIngestProcess(ingestProcesses);
});
updateIngestProcesses();
}
}, [ingestFilter]);

Expand Down Expand Up @@ -76,7 +79,7 @@ export function Page() {
ingestProcess: d,
user: user,
// What is this doing?
onUpdate: () => getTags().then((tags) => setTags(tags)),
onUpdate: updateTags,
});
})
),
Expand Down
6 changes: 6 additions & 0 deletions pages/maps/ingestion/+config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// /pages/+config.js

export default {
// Applies to all pages
ssr: false,
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ingestPrefix } from "@macrostrat-web/settings";

export async function onBeforeRender(pageContext) {
export async function data(pageContext) {
const pageProps = {
user: pageContext.user,
ingest_api: ingestPrefix,
Expand Down
2 changes: 0 additions & 2 deletions pages/maps/ingestion/components/ingest-process-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ export function IngestProcessCard({
onUpdate();
}, []);

console.log("ingestProcess", ingestProcess);

const { id, tags } = _ingestProcess;
const { slug, name, source_id, scale, raster_url } = _ingestProcess.source;
const edit_href = `/maps/ingestion/${source_id}`;
Expand Down

0 comments on commit da377ba

Please sign in to comment.