10
11 useEffect(() => {
12 fetchSuggestions();
13 fetchMessages();
14 }, []);
15
16 const fetchSuggestions = async () => {
17 const response = await fetch("/suggestions");
18 const data = await response.json();
19 setSuggestions(data);
20 };
21
22 const fetchMessages = async () => {
23 const response = await fetch("/messages");
24 const data = await response.json();
25 setChatMessages(data);
28 const handleSuggestionSubmit = async (e) => {
29 e.preventDefault();
30 await fetch("/suggestions", {
31 method: "POST",
32 headers: { "Content-Type": "application/json" },
34 });
35 setNewSuggestion({ title: "", description: "" });
36 fetchSuggestions();
37 };
38
39 const handleMessageSubmit = async (e) => {
40 e.preventDefault();
41 await fetch("/messages", {
42 method: "POST",
43 headers: { "Content-Type": "application/json" },
45 });
46 setNewMessage("");
47 fetchMessages();
48 };
49
3import React, { useEffect, useRef, useState } from "https://esm.sh/react@18.2.0";
4
5// Trivia questions (can be expanded or fetched from an API later)
6const TRIVIA_QUESTIONS = [
7 {
1import addCreation from "./addCreation";
2import fetchCreations from "./fetchCreations";
3import getCreation from "./getCreation";
4import updateTable from "./updateTable";
13 return getCreation(req);
14 if (req.method == "GET" && url.pathname == "/creations")
15 return fetchCreations(req);
16 if (req.method == "POST" && url.pathname == "/updateTable")
17 return updateTable(req);
1import { blob } from "https://esm.town/v/std/blob";
2import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
3import { TABLE_NAME } from "./updateTable";
4
5export default async function(req: Request): Promise<Response> {
155 async function loadNewIdeas(direction, centerIdea) {
156 gridContainer.style.opacity = 0.5;
157 const response = await fetch(\`?center=\${encodeURIComponent(centerIdea)}&direction=\${direction}\`);
158 if (response.ok) {
159 const html = await response.text();
181
182 try {
183 const response = await fetch("/", {
184 method: "POST",
185 body: JSON.stringify({
12
13 useEffect(() => {
14 fetchJobs();
15 fetchMessages();
16 const jobInterval = setInterval(fetchJobs, 30000);
17 const messageInterval = setInterval(fetchMessages, 5000);
18 return () => {
19 clearInterval(jobInterval);
22 }, []);
23
24 const fetchJobs = async () => {
25 try {
26 const response = await fetch("/jobs");
27 const data = await response.json();
28 setJobs(data);
29 } catch (error) {
30 console.error("Failed to fetch jobs", error);
31 }
32 };
33
34 const fetchMessages = async () => {
35 try {
36 const response = await fetch("/messages");
37 const data = await response.json();
38 setMessages(data);
39 } catch (error) {
40 console.error("Failed to fetch messages", error);
41 }
42 };
45 e.preventDefault();
46 try {
47 const response = await fetch("/jobs", {
48 method: "POST",
49 headers: { "Content-Type": "application/json" },
51 });
52 if (response.ok) {
53 fetchJobs();
54 setNewJob({ title: "", company: "", description: "" });
55 }
66 }
67 try {
68 const response = await fetch("/messages", {
69 method: "POST",
70 headers: { "Content-Type": "application/json" },
75 });
76 if (response.ok) {
77 fetchMessages();
78 setNewMessage("");
79 }
181
182 try {
183 const response = await fetch("/", {
184 method: "POST",
185 body: JSON.stringify({
70
71async function performDailyReconciliation(KEY: string) {
72 // Fetch today's sales
73 const salesResult = await sqlite.execute(`
74 SELECT
82 `);
83
84 // Fetch current inventory
85 const inventoryResult = await sqlite.execute(`
86 SELECT
19 const [error, setError] = useState<string | null>(null);
20
21 async function fetchTweets() {
22 try {
23 const res = await fetch("/tweets");
24 if (!res.ok) throw new Error("Failed to fetch tweets");
25 const data = await res.json();
26 setTweets(data);
34 async function downloadCSV() {
35 try {
36 const res = await fetch("/export-csv");
37 if (!res.ok) throw new Error("Failed to download CSV");
38 const blob = await res.blob();
49
50 useEffect(() => {
51 fetchTweets();
52 }, []);
53