From 91b5a92d9fac564510a5c231aa68e4b40c23c721 Mon Sep 17 00:00:00 2001 From: Dominik Natter Date: Fri, 28 Mar 2025 09:56:55 +0100 Subject: [PATCH] Finished, responsive --- package.json | 1 + src/app/natter-black.svg | 24 +++++++++++++ src/app/page.tsx | 62 ++++++++++++++++++++++++++------ src/components/Header.tsx | 9 +++-- src/components/LetterDensity.tsx | 23 +++++++++++- src/components/Stats.tsx | 2 +- 6 files changed, 106 insertions(+), 15 deletions(-) create mode 100644 src/app/natter-black.svg diff --git a/package.json b/package.json index 68b0ff8..cdaa25a 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "lint": "next lint" }, "dependencies": { + "@radix-ui/react-accordion": "^1.2.3", "@radix-ui/react-checkbox": "^1.1.4", "@radix-ui/react-dropdown-menu": "^2.1.6", "@radix-ui/react-progress": "^1.1.2", diff --git a/src/app/natter-black.svg b/src/app/natter-black.svg new file mode 100644 index 0000000..6323d22 --- /dev/null +++ b/src/app/natter-black.svg @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/app/page.tsx b/src/app/page.tsx index 74fc91b..d3ee09a 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -5,6 +5,7 @@ import { Textarea } from "@/components/ui/textarea"; import { Checkbox } from "@/components/ui/checkbox"; import { Stats } from "@/components/Stats"; import LetterDensity from "@/components/LetterDensity"; +import { Input } from "@/components/ui/input"; const config = { includeSpaces: true, @@ -16,6 +17,21 @@ export default function Home() { const [text, setText] = useState(""); const [analysis, setAnalysis] = useState(null); const [includeSpaces, setIncludeSpaces] = useState(true); + const [useCustomLimit, setUseCustomLimit] = useState(false); + const [charLimit, setCharLimit] = useState(config.charLimit); + + const handleTextChange = (e: React.ChangeEvent) => { + const newText = e.target.value; + const limitToUse = useCustomLimit ? charLimit : config.charLimit; + + const currentLength = includeSpaces + ? newText.length + : newText.replace(/\s/g, "").length; + + if (currentLength <= limitToUse) { + setText(newText); + } + }; useEffect(() => { const result: any = {}; @@ -24,7 +40,10 @@ export default function Home() { result.charCount = includeSpaces ? inputText.length : inputText.replace(/\s/g, "").length; result.wordCount = (inputText.match(/[a-zA-ZäöüÄÖÜß]+/g) || []).length; result.sentenceCount = (inputText.match(/[\w\s][.?!](?=\s|$)/g) || []).length; - result.exceedsLimit = result.charCount > config.charLimit; + + const limitToUse = useCustomLimit ? charLimit : config.charLimit; + result.exceedsLimit = result.charCount > limitToUse; + result.readingTimeMinutes = Math.ceil(result.wordCount / 200); const letters = inputText.toLowerCase().match(/[a-z]/g) || []; @@ -40,28 +59,51 @@ export default function Home() { } setAnalysis(result); - }, [text, includeSpaces]); + }, [text, includeSpaces, useCustomLimit, charLimit]); return ( -
-

+
+

Analyze your Text
in real-time.