import { Hono } from "npm:hono@3";
import { getAllPageEntriesDb, getLatestPageEntryDb } from "https://esm.town/v/rwev/pageEntriesDb";
import { renderToString } from "npm:react-dom/server";
const app = new Hono();
const stylesheet = (
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
/>
);
app.get("/entry", async () => {
return new Response(
renderToString(
<>
{stylesheet}
<main class="container-fluid">
<form action="https://rwev-handleSavePageForm.web.val.run/" method="post">
<textarea id="text" placeholder="New entry" name="text"></textarea>
<input type="submit" value="Submit" />
</form>
</main>
</>,
),
{
headers: {
"Content-Type": "text/html",
},
},
);
});
app.get("/", async () => {
const allEntries = await getAllPageEntriesDb();
return new Response(
renderToString(
<>
{stylesheet}
<header class="container-fluid">
<a role="button" href="/entry">New entry</a>
</header>
<main class="container-fluid">
{allEntries.map((entry) => (
<article>
<header>#{entry.id} {entry.dt}</header>
<p>{entry.value}</p>
</article>
))}
</main>
</>,
),
{
headers: {
"Content-Type": "text/html",
},
},
);
});
export default app.fetch;