16
17 useEffect(() => {
18 fetchDailyPrompt();
19 }, []);
20
21 async function fetchDailyPrompt() {
22 try {
23 const response = await fetch("/get-daily-prompt");
24 const data = await response.json();
25 setPrompt(data.prompt);
26 } catch (error) {
27 console.error("Error fetching prompt:", error);
28 }
29 }
33 try {
34 // Track mood on server
35 await fetch("/track-mood", {
36 method: "POST",
37 body: JSON.stringify({ mood: moodLevel }),
39
40 // Get initial companion response based on mood
41 const response = await fetch("/initial-mood-response", {
42 method: "POST",
43 body: JSON.stringify({ mood: moodLevel }),
75
76 try {
77 const response = await fetch("/companion-chat", {
78 method: "POST",
79 body: JSON.stringify({
135
136 try {
137 const response = await fetch("/upload-voice-note", {
138 method: "POST",
139 body: formData,
149
150 // Transcribe and get companion response
151 const transcribeResponse = await fetch("/transcribe-voice", {
152 method: "POST",
153 body: formData,
156
157 // Companion responds to transcribed text
158 const companionResponse = await fetch("/companion-chat", {
159 method: "POST",
160 body: JSON.stringify({ prompt: transcribeData.transcription }),
181
182 try {
183 const response = await fetch("/", {
184 method: "POST",
185 body: JSON.stringify({
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({