import { useState } from "react"; import { Button } from "@/components/ui/button"; import { Textarea } from "@/components/ui/textarea"; import { Card, CardContent } from "@/components/ui/card"; import { motion } from "framer-motion"; import axios from "axios"; export default function UltimateNotepad() { const [text, setText] = useState(""); const [generatedText, setGeneratedText] = useState(""); const handleTextChange = (e) => { setText(e.target.value); }; const countWords = (text) => text.trim().length > 0 ? text.trim().split(/\s+/).length : 0; const countChars = (text) => text.length; const countSentences = (text) => text.split(/[.!?]+/).filter(Boolean).length; const generateText = async () => { try { const response = await axios.post("/api/generate", { prompt: text }); setGeneratedText(response.data.text); } catch (error) { console.error("Error generating text:", error); } }; return (
Ultimate Notepad
Words: {countWords(text)}
Characters: {countChars(text)}
Sentences: {countSentences(text)}
Generate with AI
{generatedText && (
Generated Text
{generatedText}
)}
); }