40 });
41
42 // Fetch products on component mount
43 useEffect(() => {
44 fetch(import.meta.url, { method: 'GET' })
45 .then(response => response.json())
46 .then(data => setProducts(data.products));
82 e.preventDefault();
83 try {
84 const response = await fetch(import.meta.url, {
85 method: 'POST',
86 headers: { 'Content-Type': 'application/json' },
296 }
297
298 // Handle GET request to fetch products
299 if (request.method === 'GET') {
300 const productsResult = await sqlite.execute(`SELECT * FROM ${KEY}_products`);
12 useEffect(() => {
13 const timer = setInterval(() => setCurrentTime(new Date()), 1000);
14 fetchRecentRecords();
15 return () => clearInterval(timer);
16 }, []);
17
18 const fetchRecentRecords = async () => {
19 try {
20 const response = await fetch('/recent-records');
21 const records = await response.json();
22 setRecentRecords(records);
23 } catch (error) {
24 console.error('Failed to fetch recent records', error);
25 }
26 };
33
34 try {
35 const response = await fetch('/clock-action', {
36 method: 'POST',
37 headers: {
43 setStatus(result.status);
44 setLastClockIn(result.timestamp);
45 fetchRecentRecords();
46 } catch (error) {
47 console.error('Clock action failed', error);
51 const handleExportToExcel = async () => {
52 try {
53 const response = await fetch('/export-excel');
54 const blob = await response.blob();
55 const url = window.URL.createObjectURL(blob);
173 }
174
175 // Fetch recent records
176 if (request.method === 'GET' && new URL(request.url).pathname === '/recent-records') {
177 const recentRecords = await sqlite.execute(`
20
21 useEffect(() => {
22 fetch('/username')
23 .then(response => response.text())
24 .then(name => {
25 if (name) {
26 setUsername(name);
27 fetchArticles();
28 }
29 });
30 }, []);
31
32 const fetchArticles = () => {
33 fetch('/articles')
34 .then(response => response.json())
35 .then(data => setArticles(data));
46 const handleUsernameSubmit = () => {
47 if (editingUsername.trim()) {
48 fetch('/username', {
49 method: 'POST',
50 body: editingUsername.trim()
54 setUsername(name);
55 setShowWelcome(false);
56 fetchArticles();
57 });
58 }
66 const handleUsernameSave = () => {
67 if (editingUsername.trim()) {
68 fetch('/username', {
69 method: 'POST',
70 body: editingUsername.trim()
13
14 useEffect(() => {
15 fetchShifts();
16 }, []);
17
18 const fetchShifts = async () => {
19 const response = await fetch("/shifts");
20 const data = await response.json();
21 setShifts(data);
29 const addShift = async (e) => {
30 e.preventDefault();
31 await fetch("/shifts", {
32 method: "POST",
33 headers: { "Content-Type": "application/json" },
34 body: JSON.stringify(newShift)
35 });
36 fetchShifts();
37 setNewShift({ employeeName: "", date: "", startTime: "", endTime: "" });
38 };
39
40 const deleteShift = async (id) => {
41 await fetch(`/shifts/${id}`, { method: "DELETE" });
42 fetchShifts();
43 };
44
116
117 try {
118 const response = await fetch("/submit-contact", {
119 method: "POST",
120 headers: {
90
91 try {
92 const response = await fetch('/chat', {
93 method: 'POST',
94 headers: { 'Content-Type': 'application/json' },
11
12 constructor() {}
13 async fetch(req: Request): Promise<Response> {
14 if (new URL(req.url).pathname === "/robots.txt") {
15 return new Response("User-agent: *\nDisallow: /");
234const sc = new StaticChess();
235
236export default analyticsHandlerWrapper(sc.fetch.bind(sc));
10 const handleSubmit = async (e) => {
11 e.preventDefault();
12 const response = await fetch("/jobs", {
13 method: "POST",
14 headers: { "Content-Type": "application/json" },
55
56 useEffect(() => {
57 fetchMessages();
58 const interval = setInterval(fetchMessages, 5000);
59 return () => clearInterval(interval);
60 }, []);
61
62 const fetchMessages = async () => {
63 const response = await fetch("/messages");
64 if (response.ok) {
65 const data = await response.json();
70 const sendMessage = async (e) => {
71 e.preventDefault();
72 const response = await fetch("/messages", {
73 method: "POST",
74 headers: { "Content-Type": "application/json" },
77 if (response.ok) {
78 setNewMessage("");
79 fetchMessages();
80 }
81 };
107 const [jobs, setJobs] = useState([]);
108
109 const fetchJobs = async () => {
110 const response = await fetch("/jobs");
111 if (response.ok) {
112 const data = await response.json();
116
117 useEffect(() => {
118 fetchJobs();
119 }, []);
120
125 <div className="job-section">
126 <h2>Post a Job</h2>
127 <JobPostingForm onSubmit={fetchJobs} />
128 <div className="job-list">
129 <h2>Current Openings</h2>
59 }
60
61 // Fetch and process birthdays
62 const result = await sqlite.execute(`
63 SELECT name, birthday, email, reminder_days
239
240 // Inject data to avoid extra round-trips
241 const initialData = await fetchInitialData();
242 const dataScript = `<script>
243 window.__INITIAL_DATA__ = ${JSON.stringify(initialData)};
286
2875. **API Design:**
288 - `fetch` handler is the entry point for HTTP vals
289 - Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`
290
291