Back

Version 6

12/28/2024
/** @jsxImportSource https://esm.sh/react@18.2.0 */
import React, { useState, useCallback, useRef } from "https://esm.sh/react@18.2.0";
import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";

// OpenAI for image analysis
import { OpenAI } from "https://esm.town/v/std/openai";

// SQLite for data persistence
import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";

function WildlifeRescueApp() {
const [image, setImage] = useState<{ file: File | null, preview: string, base64: string }>({ file: null, preview: '', base64: '' });
const [location, setLocation] = useState<{ lat: number; lng: number }>({ lat: 0, lng: 0 });
const [animalType, setAnimalType] = useState<string>('');
const [injuryDescription, setInjuryDescription] = useState<string>('');
const [submitStatus, setSubmitStatus] = useState<string>('');
const fileInputRef = useRef<HTMLInputElement>(null);

const resetForm = useCallback(() => {
setImage({ file: null, preview: '', base64: '' });
setAnimalType('');
setInjuryDescription('');
setLocation({ lat: 0, lng: 0 });
setSubmitStatus('');
if (fileInputRef.current) {
fileInputRef.current.value = '';
}
}, []);

const handleImageUpload = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
if (file) {
// Enhanced file validation
if (file.size > 5 * 1024 * 1024) {
setSubmitStatus('File is too large. Maximum size is 5MB.');
return;
lilymachado-wildliferescueapp.web.val.run
Updated: December 28, 2024