"use client"; import { useState, useEffect, FormEvent } from "react"; import { Button } from "@/components/ui/button"; import { Textarea } from "@/components/ui/textarea"; import { Card, CardHeader, CardContent } from "@/components/ui/card"; import { Alert } from "@/components/ui/alert"; interface Thought { id: number; author_id: number; content: string; created_at: string; } export default function Home() { const [thoughts, setThoughts] = useState([]); const [newThoughtContent, setNewThoughtContent] = useState(""); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); const fetchFeed = async () => { try { setError(null); const response = await fetch("http://localhost:8000/feed"); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); setThoughts(data.thoughts || []); } catch (e: unknown) { console.error("Failed to fetch feed:", e); setError( "Could not load the feed. The backend might be busy. Please try refreshing." ); } finally { setIsLoading(false); } }; useEffect(() => { fetchFeed(); }, []); const handleSubmitThought = async (e: FormEvent) => { e.preventDefault(); if (!newThoughtContent.trim()) return; try { const response = await fetch("http://localhost:8000/thoughts", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ content: newThoughtContent, author_id: 1 }), }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } setNewThoughtContent(""); fetchFeed(); } catch (e: unknown) { console.error("Failed to post thought:", e); setError("Failed to post your thought. Please try again."); } }; return (
{/* Header */}

Thoughts

Your space on the decentralized web.

{/* New Thought Form */}