18
19 const handleGenerate = async () => {
20 const response = await fetch("/generate", {
21 method: "POST",
22 headers: { "Content-Type": "application/json" },
19 const usernameInputRef = useRef(null);
20
21 const fetchMessages = useCallback(async () => {
22 try {
23 const response = await fetch("/messages");
24 const data = await response.json();
25 setMessages(data);
29 }
30 } catch (error) {
31 console.error("Failed to fetch messages:", error);
32 }
33 }, []);
34
35 const fetchJobs = useCallback(async () => {
36 try {
37 const response = await fetch("/jobs");
38 const data = await response.json();
39 setJobs(data);
40 } catch (error) {
41 console.error("Failed to fetch jobs:", error);
42 }
43 }, []);
44
45 useEffect(() => {
46 fetchMessages();
47 fetchJobs();
48
49 const messageInterval = setInterval(fetchMessages, 3000);
50 const jobInterval = setInterval(fetchJobs, 3000);
51 return () => {
52 clearInterval(messageInterval);
53 clearInterval(jobInterval);
54 };
55 }, [fetchMessages, fetchJobs]);
56
57 async function submitMessage(e) {
63
64 try {
65 const response = await fetch("/chat", {
66 method: "POST",
67 headers: { "Content-Type": "application/json" },
94
95 try {
96 const response = await fetch("/jobs", {
97 method: "POST",
98 headers: { "Content-Type": "application/json" },
31
32 try {
33 const response = await fetch(import.meta.url, {
34 method: "POST",
35 body: JSON.stringify({ campaignType, targetAudience }),
32export async function getSites(): Promise<Site[]> {
33 try {
34 const response = await fetch(`${API_ROOT}/sites.json`);
35 const parsedData = await response.json() as RegionsResponse;
36 return parsedData.Items;
92): Promise<Location[]> {
93 try {
94 const response = await fetch(`${API_ROOT}/locations/${siteId}.json`);
95 const parsedData = await response.json() as LocationsResponse;
96 return parsedData.Items;
21 if (hasRecordedAudio && mediaBlobUrl && !audioBase64) {
22 const processRecording = async () => {
23 // Fetch the blob from mediaBlobUrl
24 const response = await fetch(mediaBlobUrl);
25 const audioBlob = await response.blob();
26
13
14 useEffect(() => {
15 fetchJobPostings();
16 fetchChatMessages();
17 }, []);
18
19 const fetchJobPostings = async () => {
20 const response = await fetch("/job-postings");
21 const data = await response.json();
22 setJobPostings(data);
23 };
24
25 const fetchChatMessages = async () => {
26 const response = await fetch("/chat-messages");
27 const data = await response.json();
28 setChatMessages(data);
31 const submitJobPosting = async (e) => {
32 e.preventDefault();
33 await fetch("/job-postings", {
34 method: "POST",
35 headers: { "Content-Type": "application/json" },
38 setNewJobTitle("");
39 setNewJobDescription("");
40 fetchJobPostings();
41 };
42
47 return;
48 }
49 await fetch("/chat-messages", {
50 method: "POST",
51 headers: { "Content-Type": "application/json" },
56 });
57 setNewChatMessage("");
58 fetchChatMessages();
59 };
60
31 .get("/", (c) => c.redirect("/words"));
32
33export default app.fetch;
34
11
12 useEffect(() => {
13 fetchUserData();
14 }, []);
15
16 const fetchUserData = async () => {
17 try {
18 const response = await fetch('/user-data');
19 const data = await response.json();
20 setUser(data.user);
22 setBalance(data.balance);
23 } catch (error) {
24 console.error('Error fetching user data', error);
25 }
26 };
10 const handleSubmit = async (e) => {
11 e.preventDefault();
12 const response = await fetch("/job", {
13 method: "POST",
14 headers: { "Content-Type": "application/json" },
53 const [jobs, setJobs] = useState([]);
54
55 const fetchJobs = async () => {
56 const response = await fetch("/jobs");
57 const data = await response.json();
58 setJobs(data);
60
61 useEffect(() => {
62 fetchJobs();
63 }, []);
64
127 const [username, setUsername] = useState("");
128
129 const fetchMessages = async () => {
130 const response = await fetch("/messages");
131 const data = await response.json();
132 setMessages(data);
144 if (!username) return;
145
146 const response = await fetch("/chat", {
147 method: "POST",
148 headers: { "Content-Type": "application/json" },
154 if (response.ok) {
155 setNewMessage("");
156 fetchMessages();
157 }
158 };
159
160 useEffect(() => {
161 fetchMessages();
162 const interval = setInterval(fetchMessages, 5000);
163 return () => clearInterval(interval);
164 }, []);
1import { fetch } from "https://esm.town/v/std/fetch";
2
3export const simpleSurf = (async () => {
4 // fetch these from the surfline page
5 const spotIds = [
6 "5842041f4e65fad6a770883f",
11 ];
12 const spots = spotIds.join(",");
13 const surfForecast = await fetch(
14 `https://services.surfline.com/kbyg/spots/batch?units%5BswellHeight%5D=FT&units%5Btemperature%5D=F&units%5BtideHeight%5D=FT&units%5BwaveHeight%5D=FT&units%5BwindSpeed%5D=KTS&spotIds=${spots}`,
15 ).then((r) => r.json()).then((d) => d.data);