import { useEffect, useState } from "react"; import "./App.css"; import { ArrowUpIcon } from "lucide-react"; import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupTextarea, } from "@/components/ui/input-group"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card"; const baseUrl = "http://localhost:8080"; const username = "ratludu"; type Note = { id: string; content: string; title: string; }; export function InputGroupDemo({ onSent }): { onSent?: (note: Note) => void; } { const [text, setText] = useState(""); const [isSending, setIsSending] = useState(false); const [error, setError] = useState(null); const isEmpty = text.trim().length === 0; async function handleSend() { const value = text.trim(); if (!value || isSending) return; try { setIsSending(true); setError(null); const resp = await fetch(`${baseUrl}/content`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ username: username, content: value, }), }); if (!resp.ok) { const msg = await resp.text().catch(() => "An error occurred"); throw new Error(msg || "Unknown error"); } const created = { id: crypto.randomUUID(), content: String(value), title: "Note", }; onSent?.(created); setText(""); } catch (e) { const msg = e instanceof Error ? e.message : "Unknown error"; setError(msg); } finally { setIsSending(false); } setText(""); } function handleKeyDown(event: React.KeyboardEvent) { if (event.key === "Enter" && !event.shiftKey) { event.preventDefault(); handleSend(); } } return (
) => setText(e.target.value) } onKeyDown={handleKeyDown} /> Send
); } function NotesList({ notes }: { notes: Note[] }) { if (!notes.length) { return

No notes yet.

; } return (
{notes.map((note) => (

{note.content}

))}
); } function App() { const [notes, setNotes] = useState([]); function handleSend(newNote: Note) { setNotes((prev) => [newNote, ...prev]); } return (
); } export default App;