Display image.

This commit is contained in:
James Pace 2026-03-02 12:34:20 +00:00
parent d5c158024f
commit bb35a80e97
1 changed files with 29 additions and 1 deletions

View File

@ -1,12 +1,40 @@
import { AppNav, Footer } from "./AppNav.tsx"; import { AppNav, Footer } from "./AppNav.tsx";
import { Container, Row, Col, Image } from "react-bootstrap"; import { Container, Row, Col, Image } from "react-bootstrap";
import { atom, useAtom } from "jotai";
import { atomWithQuery } from "jotai-tanstack-query";
const costmapImageQuery = async () => {
const resp = await fetch("api/costmap_image");
if (!resp.ok) {
throw new Error("Network response was not ok");
}
const blob = await resp.blob();
return URL.createObjectURL(blob);
};
const costmapImageAtom = atomWithQuery(() => ({
queryKey: ["costmap_image"],
queryFn: costmapImageQuery,
refetchInterval: 1000 // 1s
}));
export function Home() { export function Home() {
const [{ data, isPending, isError }] = useAtom(costmapImageAtom);
let costmapImage = () => {
if (isPending) {
return (<p>"Loading..."</p>);
}
if (isError) {
return(<p>"Error!"</p>);
}
return (<Image src={data} />);
};
return ( return (
<div> <div>
<AppNav /> <AppNav />
<Container> <Container>
<p> Hello World! </p> { costmapImage() }
</Container> </Container>
<Footer /> <Footer />
</div> </div>