21 const loadRecentShipments = async () => {
22 try {
23 const response = await fetch('/api/shipments?limit=5');
24 const result = await response.json();
25 if (result.success) {
34 html = html.replace("</head>", `${dataScript}</head>`);
35 } catch (error) {
36 // If there's an error fetching initial data, just serve the page without it
37 console.error("Failed to fetch initial data:", error);
38 }
39
41});
42
43export default app.fetch;
44
45export default app.fetch;
29 const loadDashboardStats = async () => {
30 try {
31 const response = await fetch('/api/tracking/dashboard/stats');
32 const result = await response.json();
33 if (result.success) {
35});
36
37export default app.fetch;
27 return c.json({
28 success: false,
29 error: "Failed to fetch businesses"
30 }, 500);
31 }
13
14 useEffect(() => {
15 fetchMessages();
16 // Set up polling for new messages every 3 seconds
17 const interval = setInterval(fetchMessages, 3000);
18 return () => clearInterval(interval);
19 }, []);
39 };
40
41 const fetchMessages = async () => {
42 try {
43 const response = await fetch('/api/chat/messages');
44 const result = await response.json();
45
47 setMessages(result.data);
48 } else {
49 setError(result.error || 'Failed to fetch messages');
50 }
51 } catch (err) {
64
65 try {
66 const response = await fetch('/api/chat/messages', {
67 method: 'POST',
68 headers: {
79 if (result.success) {
80 setNewMessage('');
81 // Fetch messages immediately to show the new message
82 await fetchMessages();
83 } else {
84 setError(result.error || 'Failed to send message');
11
12 useEffect(() => {
13 fetchJobs();
14 }, []);
15
16 const fetchJobs = async () => {
17 try {
18 const response = await fetch('/api/jobs');
19 const result = await response.json();
20
22 setJobs(result.data);
23 } else {
24 setError(result.error || 'Failed to fetch jobs');
25 }
26 } catch (err) {
42
43 try {
44 const response = await fetch(`/api/jobs/${jobId}`, {
45 method: 'DELETE',
46 });
18 setDeletingId(id);
19 try {
20 const response = await fetch(`/api/buses/${id}`, {
21 method: "DELETE",
22 });
26
27 try {
28 const response = await fetch('/api/jobs', {
29 method: 'POST',
30 headers: {
29
30 try {
31 const response = await fetch("/api/buses", {
32 method: "POST",
33 headers: {