keenanzucker-blobcommentsreact.web.val.run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/** @jsxImportSource https://esm.sh/react */
import { Hono } from "https://esm.sh/hono";
import React, { useEffect, useState } from "https://esm.sh/react";
import { hydrateRoot } from "https://esm.sh/react-dom/client";
import { renderToReadableStream } from "https://esm.sh/react-dom/server";
import { blob } from "https://esm.town/v/std/blob?v=10";
function App() {
const [data, setData] = useState();
useEffect(() => {
async function fetchSchedule() {
await fetch("/schedule")
.then(response => {
return response.json();
})
.then(data => {
console.log("DATA: ", data);
setData(data);
});
}
fetchSchedule();
}, []);
return (
<html>
<head>
<title>Comments</title>
<link rel="stylesheet" href="https://unpkg.com/tailwindcss@2.2.19/dist/tailwind.min.css" />
</head>
<body>
<div className="max-w-md mx-auto mt-8 p-4 bg-gray-100 rounded-lg">
<h1 className="text-2xl font-bold mb-4">Comments</h1>
{data
? data.map((shift) => (
<div key={shift.id} className="bg-white p-2 rounded flex justify-between items-center">
{shift}
</div>
))
: "Loading..."}
</div>
</body>
</html>
);
}
if (typeof document !== "undefined") {
hydrateRoot(document, <App />);
}
const app = new Hono();
app.get("/", async (c) => {
// const comments = await blob.getJSON("comments") || [];
const stream = await renderToReadableStream(<App />, { bootstrapModules: [import.meta.url] });
return new Response(stream, { headers: { "content-type": "text/html" } });
});
app.get("/schedule", async (c) => {
const today = new Date();
const tomorrow = new Date(today);
tomorrow.setDate(tomorrow.getDate() + 1);
const data = await fetch(
`https://api.stage.teamsurfboard.com/api/v1/schedule?start=${today.toISOString()}&end=${tomorrow.toISOString()}`,
{
headers: {
// ADD YOUR API TOKEN INTO THE ENV VARIABLES
"Authorization": `Bearer ${Deno.env.get("TEAMSURFBOARD_API_TOKEN")}`,
},
},
)
.then((res) => res.json())
.then((data) => data);
return c.json(data.data);
});
export default app.fetch;
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
July 25, 2024