15
16 useEffect(() => {
17 fetchWorks();
18 }, []);
19
20 const fetchWorks = async () => {
21 const response = await fetch("/works");
22 const data = await response.json();
23 setWorks(data);
35 }
36
37 await fetch("/works", {
38 method: "POST",
39 body: formData,
40 });
41 fetchWorks();
42 setNewWork({ title: "", author: "", genre: "poem", content: "", file: null });
43 };
48
49 const downloadWork = async (workId) => {
50 const response = await fetch(`/download/${workId}`);
51 const blob = await response.blob();
52 const url = window.URL.createObjectURL(blob);
11 try {
12 // Use a relative URL to ensure correct routing
13 const response = await fetch('.', {
14 method: 'POST',
15 body: JSON.stringify({ email }),
28 : { username, password, fullName };
29
30 const response = await fetch(endpoint, {
31 method: 'POST',
32 headers: { 'Content-Type': 'application/json' },
115
116 useEffect(() => {
117 async function fetchDashboardData() {
118 try {
119 const [studentsResponse, coursesResponse] = await Promise.all([
120 fetch('/teacher-students'),
121 fetch('/teacher-courses')
122 ]);
123
128 setCourses(coursesData);
129 } else {
130 setError('Failed to fetch dashboard data');
131 }
132 } catch (err) {
135 }
136
137 fetchDashboardData();
138 }, []);
139
141 e.preventDefault();
142 try {
143 const response = await fetch('/enter-grades', {
144 method: 'POST',
145 headers: { 'Content-Type': 'application/json' },
494 });
495 } catch (error) {
496 console.error('Fetch students error:', error);
497 return new Response(JSON.stringify({
498 error: 'Failed to fetch students',
499 details: error.message
500 }), {
516 });
517 } catch (error) {
518 console.error('Fetch courses error:', error);
519 return new Response(JSON.stringify({
520 error: 'Failed to fetch courses',
521 details: error.message
522 }), {
8
9 useEffect(() => {
10 async function fetchWeather() {
11 try {
12 const response = await fetch(
13 `https://api.open-meteo.com/v1/forecast?latitude=${location.latitude}&longitude=${location.longitude}¤t_weather=true&hourly=temperature_2m,weathercode&daily=weathercode,temperature_2m_max,temperature_2m_min&timezone=auto`
14 );
16 setWeather(data);
17 } catch (error) {
18 console.error("Failed to fetch weather", error);
19 }
20 }
21
22 fetchWeather();
23 }, [location]);
24
131
132 try {
133 const response = await fetch('/generate-question', {
134 method: 'POST',
135 headers: { 'Content-Type': 'application/json' },
92 setIsLoading(true);
93 try {
94 const response = await fetch('/generate', {
95 method: 'POST',
96 headers: { 'Content-Type': 'application/json' },
10 try {
11 // Send SMS
12 const smsResponse = await fetch('/send-sms', { method: 'POST' });
13 const smsResult = await smsResponse.text();
14 console.log(smsResult);
15
16 // Send Email
17 const emailResponse = await fetch('/send-email', { method: 'POST' });
18 const emailResult = await emailResponse.text();
19 console.log(emailResult);
20
21 // Send Notification
22 const notificationResponse = await fetch('/send-notification', { method: 'POST' });
23 const notificationResult = await notificationResponse.text();
24 console.log(notificationResult);
15
16 useEffect(() => {
17 fetchJobs();
18 fetchMessages();
19 }, []);
20
21 async function fetchJobs() {
22 try {
23 const response = await fetch('/jobs');
24 const data = await response.json();
25 setJobs(data);
26 } catch (error) {
27 console.error('Failed to fetch jobs', error);
28 }
29 }
30
31 async function fetchMessages() {
32 try {
33 const response = await fetch('/messages');
34 const data = await response.json();
35 setMessages(data);
36 } catch (error) {
37 console.error('Failed to fetch messages', error);
38 }
39 }
42 e.preventDefault();
43 try {
44 const response = await fetch('/jobs', {
45 method: 'POST',
46 headers: { 'Content-Type': 'application/json' },
48 });
49 if (response.ok) {
50 fetchJobs();
51 setNewJob({ title: '', company: '', description: '', location: '' });
52 }
59 e.preventDefault();
60 try {
61 const response = await fetch('/messages', {
62 method: 'POST',
63 headers: { 'Content-Type': 'application/json' },
65 });
66 if (response.ok) {
67 fetchMessages();
68 setNewMessage('');
69 }
15
16 useEffect(() => {
17 fetchJobs();
18 fetchMessages();
19 }, []);
20
21 async function fetchJobs() {
22 try {
23 const response = await fetch('/jobs');
24 const data = await response.json();
25 setJobs(data);
26 } catch (error) {
27 console.error('Failed to fetch jobs', error);
28 }
29 }
30
31 async function fetchMessages() {
32 try {
33 const response = await fetch('/messages');
34 const data = await response.json();
35 setMessages(data);
36 } catch (error) {
37 console.error('Failed to fetch messages', error);
38 }
39 }
42 e.preventDefault();
43 try {
44 const response = await fetch('/jobs', {
45 method: 'POST',
46 headers: { 'Content-Type': 'application/json' },
48 });
49 if (response.ok) {
50 fetchJobs();
51 setNewJob({ title: '', company: '', description: '', location: '' });
52 }
59 e.preventDefault();
60 try {
61 const response = await fetch('/messages', {
62 method: 'POST',
63 headers: { 'Content-Type': 'application/json' },
65 });
66 if (response.ok) {
67 fetchMessages();
68 setNewMessage('');
69 }
20 const [error, setError] = useState<string | null>(null);
21
22 const fetchContributions = async () => {
23 setLoading(true);
24 setError(null);
25 try {
26 const response = await fetch(`/contributions?username=${username}`);
27 if (!response.ok) throw new Error("Failed to fetch contributions");
28 const data = await response.json();
29 setContributions(data);
47 />
48 <button
49 onClick={fetchContributions}
50 disabled={loading}
51 style={styles.button}
66 : (
67 <p style={styles.noContributions}>
68 {loading ? "Fetching contributions..." : "No recent contributions"}
69 </p>
70 )}
151 const url = new URL(request.url);
152
153 // Contributions fetching endpoint
154 if (url.pathname === "/contributions") {
155 const username = url.searchParams.get("username") || "Joshuakibwage";
157
158 try {
159 const response = await fetch(GITHUB_API_URL);
160 const events: GitHubEvent[] = await response.json();
161
184 });
185 } catch (error) {
186 return new Response(JSON.stringify({ error: "Failed to fetch contributions" }), {
187 status: 500,
188 headers: { "Content-Type": "application/json" },