import { useState, useEffect } from "react";
import { Textarea } from "@/components/ui/textarea";
import { Button } from "@/components/ui/button";
import { Card, CardContent } from "@/components/ui/card";
import { Loader2 } from "lucide-react";
import { motion } from "framer-motion";
export default function AIProofreadingTool() {
const [text, setText] = useState("");
const [loading, setLoading] = useState(false);
const [correctedText, setCorrectedText] = useState("");
const [rewrittenText, setRewrittenText] = useState("");
const [wordCount, setWordCount] = useState({});
const [searchWord, setSearchWord] = useState("");
const [foundWords, setFoundWords] = useState([]);
const [keywords, setKeywords] = useState([]);
useEffect(() => {
setTimeout(() => {
setLoading(false);
}, 2000);
}, []);
const handleProofread = async () => {
setLoading(true);
setCorrectedText(
text.replace(/\bteh\b/g, "the").replace(/\brecieve\b/g, "receive")
);
setLoading(false);
};
const handleRewrite = async () => {
setLoading(true);
setRewrittenText(
"Here is a rewritten version of your text: " + text.split(" ").reverse().join(" ")
);
setLoading(false);
};
const handleWordCount = () => {
const words = text.split(/\s+/).filter(word => word);
const count = {};
words.forEach(word => {
count[word] = (count[word] || 0) + 1;
});
setWordCount(count);
};
const handleWordSearch = () => {
if (!searchWord) return;
const regex = new RegExp(`\\b${searchWord}\\b`, "gi");
const matches = text.match(regex) || [];
setFoundWords(matches);
};
const handleKeywordExtraction = () => {
const commonWords = new Set(["the", "is", "in", "and", "to", "of", "a", "that", "it", "on", "for", "with", "as", "was", "at", "by", "an", "be", "this", "which", "or", "from", "but", "not", "are", "we", "they", "you", "he", "she", "my", "our", "their"]);
const words = text.split(/\s+/).filter(word => word && !commonWords.has(word.toLowerCase()));
const uniqueKeywords = Array.from(new Set(words));
setKeywords(uniqueKeywords);
};
return (
AI Proofreading, Rewriting, Word Counter, Word Finder & Keyword Extractor
{loading ? : "Proofread"}
{loading ? : "Rewrite"}
Count Words
Extract Keywords
setText("")}>Clear
setSearchWord(e.target.value)}
/>
Find Word
{correctedText && (
Corrected Text
{correctedText}
)}
{rewrittenText && (
Rewritten Text
{rewrittenText}
)}
);
}
0 Comments