plantprofileApp.tsx10 matches
25const [isEditing, setIsEditing] = useState(false);
2627// Fetch all plants on component mount
28useEffect(() => {
29fetchPlants();
30}, []);
3132const fetchPlants = async () => {
33try {
34setIsLoading(true);
35const response = await fetch("/api/plants");
36const data = await response.json();
37
39setPlants(data.data || []);
40} else {
41setError(data.error || "Failed to fetch plants");
42}
43} catch (err) {
52try {
53setIsLoading(true);
54const response = await fetch(`/api/plants/${id}`);
55const data = await response.json();
56
58setSelectedPlant(data.data);
59} else {
60setError(data.error || "Failed to fetch plant details");
61}
62} catch (err) {
71try {
72setIsLoading(true);
73const response = await fetch("/api/plants", {
74method: "POST",
75headers: {
99try {
100setIsLoading(true);
101const response = await fetch(`/api/plants/${id}`, {
102method: "PUT",
103headers: {
131try {
132setIsLoading(true);
133const response = await fetch(`/api/plants/${id}`, {
134method: "DELETE",
135});
plantprofileplants.ts4 matches
17return c.json({ success: true, data: profiles });
18} catch (error) {
19console.error("Error fetching plant profiles:", error);
20return c.json({ success: false, error: "Failed to fetch plant profiles" }, 500);
21}
22});
37return c.json({ success: true, data: profile });
38} catch (error) {
39console.error("Error fetching plant profile:", error);
40return c.json({ success: false, error: "Failed to fetch plant profile" }, 500);
41}
42});
FirstProjectindex.ts1 match
4445// Export the Hono app
46export default app.fetch;
FirstProjectindex.js21 matches
55};
5657// Fetch job listings
58const fetchJobs = async () => {
59try {
60const response = await fetch('/api/jobs');
61if (!response.ok) throw new Error('Failed to fetch jobs');
62
63const jobs = await response.json();
81`).join('');
82} catch (error) {
83console.error('Error fetching jobs:', error);
84jobListings.innerHTML = '<p class="text-red-500">Failed to load jobs. Please try again later.</p>';
85}
104};
105
106const response = await fetch('/api/jobs', {
107method: 'POST',
108headers: {
119// Reset form and refresh job listings
120jobForm.reset();
121await fetchJobs();
122
123// Show success message
132});
133134// Fetch chat messages
135const fetchChatMessages = async () => {
136try {
137const response = await fetch('/api/chat');
138if (!response.ok) throw new Error('Failed to fetch chat messages');
139
140const messages = await response.json();
166chatMessages.scrollTop = chatMessages.scrollHeight;
167} catch (error) {
168console.error('Error fetching chat messages:', error);
169chatMessages.innerHTML = '<p class="text-red-500">Failed to load messages. Please try again later.</p>';
170}
188document.getElementById('message').focus();
189
190// Fetch messages and start polling
191fetchChatMessages();
192startPolling();
193});
202
203try {
204const response = await fetch('/api/chat', {
205method: 'POST',
206headers: {
218}
219
220// Clear input and fetch new messages
221messageInput.value = '';
222await fetchChatMessages();
223} catch (error) {
224console.error('Error sending message:', error);
231if (pollingInterval) clearInterval(pollingInterval);
232
233pollingInterval = setInterval(fetchChatMessages, 3000);
234};
235243const init = async () => {
244setViewSourceLink();
245await fetchJobs();
246
247// If on chat tab and username is set, fetch messages and start polling
248if (currentUsername && !chatContent.classList.contains('hidden')) {
249await fetchChatMessages();
250startPolling();
251}
FirstProjectchat.ts2 matches
12return c.json(messages);
13} catch (error) {
14console.error("Error fetching chat messages:", error);
15return c.json({ error: "Failed to fetch chat messages" }, 500);
16}
17});
FirstProjectjobs.ts2 matches
11return c.json(jobPostings);
12} catch (error) {
13console.error("Error fetching job postings:", error);
14return c.json({ error: "Failed to fetch job postings" }, 500);
15}
16});
3233try {
34// 1. Fetch suggestions
35const suggestUrl = `https://api.lyrics.ovh/suggest/${encodeURIComponent(query)}`;
36console.log(`Fetching suggestions from: ${suggestUrl}`);
37const suggestResponse = await fetch(suggestUrl);
3839if (!suggestResponse.ok) {
40console.error(`Error fetching suggestions: ${suggestResponse.status} ${suggestResponse.statusText}`);
41const errorBody = await suggestResponse.text();
42console.error(`Error body: ${errorBody}`);
43return c.json({ error: 'Failed to fetch song suggestions', details: errorBody }, suggestResponse.status);
44}
4558console.log(`Found song: Title - ${actualTitle}, Artist - ${actualArtist}`);
5960// 3. Fetch lyrics
61const lyricsUrl = `https://api.lyrics.ovh/v1/${encodeURIComponent(actualArtist)}/${encodeURIComponent(actualTitle)}`;
62console.log(`Fetching lyrics from: ${lyricsUrl}`);
63const lyricsResponse = await fetch(lyricsUrl);
6465if (!lyricsResponse.ok) {
66console.error(`Error fetching lyrics: ${lyricsResponse.status} ${lyricsResponse.statusText}`);
67const errorBody = await lyricsResponse.text();
68console.error(`Error body: ${errorBody}`);
72return c.json({ error: errorJson.error || 'Lyrics not found for this song' }, 404);
73}
74return c.json({ error: 'Failed to fetch lyrics', details: errorBody }, lyricsResponse.status);
75}
76125});
126127// Export the fetch handler for the worker
128export default app.fetch;
JobPlatformindex.ts1 match
4142// This is the entry point for HTTP vals
43export default app.fetch;
JobPlatformapp.js8 matches
85async function loadJobs() {
86try {
87const response = await fetch('/api/jobs');
88if (!response.ok) throw new Error('Failed to fetch jobs');
89
90const jobs = await response.json();
120};
121
122const response = await fetch('/api/jobs', {
123method: 'POST',
124headers: {
187async function loadChatMessages() {
188try {
189const response = await fetch('/api/chat');
190if (!response.ok) throw new Error('Failed to fetch chat messages');
191
192const messages = await response.json();
235if (lastChatTimestamp) {
236try {
237const response = await fetch(`/api/chat/recent?since=${lastChatTimestamp}`);
238if (!response.ok) throw new Error('Failed to fetch recent messages');
239
240const newMessages = await response.json();
278
279try {
280const response = await fetch('/api/chat', {
281method: 'POST',
282headers: {
JobPlatformchat.ts4 matches
12return c.json(messages);
13} catch (error) {
14console.error("Error fetching chat messages:", error);
15return c.json({ error: "Failed to fetch chat messages" }, 500);
16}
17});
28return c.json(messages);
29} catch (error) {
30console.error("Error fetching recent chat messages:", error);
31return c.json({ error: "Failed to fetch recent chat messages" }, 500);
32}
33});