diff --git a/src/app/typingV2/page.tsx b/src/app/typingV2/page.tsx index f84e4f4..0a1cb20 100644 --- a/src/app/typingV2/page.tsx +++ b/src/app/typingV2/page.tsx @@ -1,203 +1,173 @@ -"use client"; +// "use client"; -import { useEffect, useState } from "react"; -import { quotes } from "@/app/quotes"; -import Image from "next/image"; -import { Poppins, Hahmlet } from "next/font/google"; -import chevLeft from "../../public/chev-left.svg"; -import chevRight from "../../public/chev-right.svg"; -import Link from "next/link"; -import IdStore from ".././store"; +// import { useEffect, useRef, useState } from "react"; +// import { quotes } from "@/app/quotes"; +// import Image from "next/image"; +// import chevLeft from "../../../public/chevron-left.svg"; +// import chevRight from "../../../public/chevron-right.svg"; +// import Link from "next/link"; -interface Word { - content: string; - sentenceIndex: number; -} +// interface Word { +// content: string; +// sentenceIndex: number; +// } -interface Letter extends Word { - wordIndex: number; - letters: string[]; -} -type QUOTE = { - title: string; - author: string; - content: string; -}; +// interface Letter extends Word { +// wordIndex: number; +// } +// type QUOTE = { +// title: string; +// author: string; +// content: string; +// }; -export default function Home() { - const [sentenceCurrent, setSentenceCurrent] = useState(0); //sentence Current position - const [textValue, setTextValue] = useState(""); //for the print text - const [inputCollection, setInputCollection] = useState([]); - const [quoteNumber, setQuoteNumber] = useState(0); - const [quote, setQuote] = useState(quotes[0]); - const [userName, setUserName] = useState(""); - const { id, setId } = IdStore(); - const testName = "test"; +// export default function Home() { +// const [textValue, setTextValue] = useState(""); //for the print text +// const [quoteNumber, setQuoteNumber] = useState(0); +// const [quote, setQuote] = useState(quotes[0]); +// const [letterIndex, setLetterIndex] = useState(0); +// useEffect(() => { +// setQuote(quotes[quoteNumber]); +// }, [quoteNumber]); +// // const quote = { +// // title: "작별하지 않는다", +// // author: "한강", +// // content: "상대의 가장 연한 부분을 베기 위해.", +// // }; - useEffect(() => { - setTextValue(""); - setQuote(quotes[quoteNumber]); - setId(testName); - setUserName(id); - }, [quoteNumber, id, setId]); +// const textAreaRef = useRef(null); - console.log(userName); +// const handleTextArea = (e: React.ChangeEvent) => { +// setTextValue(e.currentTarget.value); +// setLetterIndex(e.currentTarget.value.length); +// }; - const sentences = quote.content.split("\n"); +// const handleKeyDown = (e: React.KeyboardEvent) => { +// const key = e.key; +// if (letterIndex == quote.content.length) { +// alert("End"); +// } +// if (key == " " || key == "Spacebar") { +// } +// if (key == "Backspace") { +// if (textValue == "") { +// e.preventDefault(); +// return; +// } +// } +// if (key == "Enter") { +// e.preventDefault(); +// alert("You Cannot Skip the line"); +// } +// }; - const handleTextArea = (e: React.ChangeEvent) => { - let targetValue = e.currentTarget.value.split("\n"); - let targetLength = targetValue[sentenceCurrent].length; - if (targetLength == sentences[sentenceCurrent].length) { - setInputCollection((prev: string[]) => { - if (prev[sentenceCurrent] == undefined || prev.length == 0) { - return [...prev, targetValue[sentenceCurrent]]; - } else { - let newInputCollection: string[] = [...prev]; - newInputCollection[sentenceCurrent] = targetValue[sentenceCurrent]; - return newInputCollection; - } - }); - e.currentTarget.value += "\n"; - if (sentenceCurrent + 1 >= sentences.length) { - alert("The End"); - } - setSentenceCurrent((prev) => ++prev); - } - setTextValue(e.currentTarget.value); - }; +// const LetterGenerator = ({ wordIndex, content, sentenceIndex }: Letter) => { +// if (wordIndex != 0 && content == " ") { +// return  ; +// } +// let testInput = textValue.split(""); +// return ( +// +// {testInput[wordIndex] ? ( +// testInput[wordIndex] != content && wordIndex !== letterIndex ? ( +// +// {testInput[wordIndex]} +// +// ) : ( +// {content} +// ) +// ) : ( +// {content} +// )} +// {letterIndex == wordIndex && ( +// +// )} +// +// ); +// }; - const handleKeyDown = (e: React.KeyboardEvent) => { - const key = e.key; - if (key == " " || key == "Spacebar") { - } - if (key == "Backspace") { - //Prevent From going over empty text area - if (textValue == "") { - e.preventDefault(); - return; - } - //if the whole length is smaller - let inputSentence = textValue.split("\n"); - //If current Sentence Have Empty string - //then Skip to the previous sentence - if (inputSentence[sentenceCurrent] == "") { - setTextValue((prev) => { - return prev.slice(0, -1); - }); - setSentenceCurrent((prev) => (prev -= 1)); - } - } - if (key == "Enter") { - e.preventDefault(); - alert("You Cannot Skip the line"); - } - }; - const LetterGenerator = ({ - wordIndex, - content, - sentenceIndex, - letters, - }: Letter) => { - if (wordIndex != 0 && content == " ") { - return  ; - } - if (sentenceIndex < sentenceCurrent) { - let previousInputValue = inputCollection[sentenceIndex].split(""); - return previousInputValue[wordIndex] == content ? ( - {content} - ) : ( - {previousInputValue[wordIndex]} - ); - } - let testInput = textValue.split("\n"); - let testInputLetter = testInput[sentenceCurrent].split(""); +// const WordGenerator = ({ content, sentenceIndex }: Word) => { +// let letters = content.split(""); +// return ( +//
+// {letters.map((value, index) => { +// return ( +// +// ); +// })} +//
+// ); +// }; - return sentenceCurrent == sentenceIndex && testInputLetter[wordIndex] ? ( - testInputLetter[wordIndex] == content ? ( - {content} - ) : testInputLetter[wordIndex] == " " ? ( - {content} - ) : ( - {testInputLetter[wordIndex]} - ) - ) : ( - {content} - ); - }; +// const handleNextClick = () => { +// if (quoteNumber + 1 >= quotes.length) { +// setQuoteNumber(0); +// } else setQuoteNumber((prev) => ++prev); +// setQuote(quotes[quoteNumber]); +// }; - const WordGenerator = ({ content, sentenceIndex }: Word) => { - //Split into letters - let letters = content.split(""); - return ( -
- {letters.map((value, index) => { - //Generate Each Letters - return ( - - ); - })} -
- ); - }; +// const handlePrevClick = () => { +// if (quoteNumber <= 0) { +// setQuoteNumber(quotes.length - 1); +// } else setQuoteNumber((prev) => --prev); +// setQuote(quotes[quoteNumber]); +// }; +// const handlePrintClick = () => { +// if (textAreaRef.current) { +// textAreaRef.current.focus(); +// } +// }; - const handleNextClick = () => { - if (quoteNumber + 1 >= quotes.length) { - setQuoteNumber(0); - } else setQuoteNumber((prev) => ++prev); - setQuote(quotes[quoteNumber]); - }; - const handlePrevClick = () => { - if (quoteNumber <= 0) { - setQuoteNumber(quotes.length - 1); - } else setQuoteNumber((prev) => --prev); - setQuote(quotes[quoteNumber]); - }; - - return ( -
-
-
- {sentences.map((value, index) => { - return ( - //Each Word generate - - ); - })} -
- -
-
-
- -
-
{"저자 : " + quote.author}
-
{"제목 : " + quote.title}
-
- -
- Leave Us a feedback=== -
-
-
- ); -} +// return ( +//
+//
+//
+// +//
+// +//
+//
+//
+// +//
+//
+//
저자 :
+//
{quote.author}
+//
+//
+//
제목 :
+//
{quote.title}
+//
+//
+// +//
+// Leave Us a feedback=== +//
+//
+//
+// ); +// }