()
| 16 | : null; |
| 17 | |
| 18 | const Footer = () => { |
| 19 | const [email, setEmail] = useState(""); |
| 20 | const [isLoading, setIsLoading] = useState(false); |
| 21 | const [version, setVersion] = useState(""); |
| 22 | useEffect(() => { |
| 23 | async function fetchVersion() { |
| 24 | try { |
| 25 | const res = await fetch( |
| 26 | "https://raw.githubusercontent.com/CodeGraphContext/CodeGraphContext/main/README.md" |
| 27 | ); |
| 28 | if (!res.ok) throw new Error("Failed to fetch README"); |
| 29 | |
| 30 | const text = await res.text(); |
| 31 | const match = text.match( |
| 32 | /\*\*Version:\*\*\s*([0-9]+\.[0-9]+\.[0-9]+)/i |
| 33 | ); |
| 34 | setVersion(match ? match[1] : "N/A"); |
| 35 | } catch (err) { |
| 36 | console.error(err); |
| 37 | setVersion("N/A"); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | fetchVersion(); |
| 42 | }, []); |
| 43 | const handleNewsletterSubmit = async (e: React.FormEvent) => { |
| 44 | e.preventDefault(); |
| 45 | |
| 46 | if (!email) { |
| 47 | toast.error("Please enter your email address"); |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | if (!/\S+@\S+\.\S+/.test(email)) { |
| 52 | toast.error("Please enter a valid email address"); |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | // Check if Supabase is configured |
| 57 | if (!supabase) { |
| 58 | toast.error( |
| 59 | "Newsletter subscription is currently unavailable. Please try again later." |
| 60 | ); |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | setIsLoading(true); |
| 65 | |
| 66 | try { |
| 67 | const { data, error } = await supabase |
| 68 | .from("subscribers") |
| 69 | .insert([{ email }]); |
| 70 | |
| 71 | if (error) { |
| 72 | if (error.code === "23505") { |
| 73 | // Duplicate email |
| 74 | toast("You are already subscribed!"); |
| 75 | } else { |
nothing calls this directly
no test coverage detected