diff --git a/.gitignore b/.gitignore index a547bf3..310530e 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ dist-ssr *.njsproj *.sln *.sw? + +# Other +TODO.txt \ No newline at end of file diff --git a/src/App.tsx b/src/App.tsx index a7324f5..3ae726b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -3,13 +3,14 @@ import reactLogo from './assets/react.svg' import './App.css' import { Routes, Route, Router, BrowserRouter } from 'react-router-dom' import Home from './pages/Home' +import Duplicates from './pages/Duplicates' function App() { return (
- Valid Input}> + }> }> diff --git a/src/components/Card.tsx b/src/components/Card.tsx new file mode 100644 index 0000000..b53ef86 --- /dev/null +++ b/src/components/Card.tsx @@ -0,0 +1,37 @@ +import { useState } from "react"; + +function Card({ + value, + index, + input, + setInput, + setHasNoDuplicates, + setFirstRender +}) { + + const handleCloseButton = ev => { + const cardElement = ev.target.nextSibling + const selectedChar = cardElement.innerText; + const indexSelectedChar = index + + console.log({ selectedChar, indexSelectedChar }) + const removedDuplicates = Array.from(input) + .filter((char, index) => + char !== selectedChar || index === indexSelectedChar) + .join(""); + setInput(removedDuplicates) + setHasNoDuplicates(new Set(removedDuplicates).size === removedDuplicates.length) + setFirstRender(true) + } + + return ( +
+ +
+ ) +} + +export default Card; \ No newline at end of file diff --git a/src/pages/Duplicates.tsx b/src/pages/Duplicates.tsx new file mode 100644 index 0000000..d9042ca --- /dev/null +++ b/src/pages/Duplicates.tsx @@ -0,0 +1,49 @@ +import { useLocation, useNavigate } from "react-router-dom"; +import Card from "../components/Card"; +import { useState } from "react" + +function Duplicates() { + const navigate = useNavigate() + const location = useLocation(); + const [input, setInput] = useState(location.state.originalInput); + const [hasNoDuplicates, setHasNoDuplicates] = useState(false) + const [isFirstRender, setIsFirstRender] = useState(false) + + function Prompt() { + return ( +
+ {hasNoDuplicates + ?

NO DUPLICATES 😁

+ :

Still Duplicates 😭

} +
+ ) + } + + return ( +
+ +

You're in the second page

+

Heres your ORIGINAL input {location.state.originalInput}

+

Heres your CURRENT input {input}

+ + { + isFirstRender + ? + : null + } +
+ {Array.from(input).map((char, index) => )} +
+
+ ) +} + +export default Duplicates; \ No newline at end of file diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx index 962d743..098558f 100644 --- a/src/pages/Home.tsx +++ b/src/pages/Home.tsx @@ -2,17 +2,17 @@ import React, { useState } from "react"; import { useNavigate } from "react-router-dom"; const Home = () => { - const [input, setInput] = useState(""); + const [originalInput, setOriginalInput] = useState(""); const navigate = useNavigate(); const handleChange = (ev: React.FormEvent) => { - setInput(ev.currentTarget.value); + setOriginalInput(ev.currentTarget.value.trim()); } const handleSubmit = (ev: React.SyntheticEvent) => { ev.preventDefault(); - validateInput(input) - ? navigate("/validated") + validateInput(originalInput) + ? navigate("/validated", { state: { originalInput } }) : alert("Can't process empty input") } @@ -27,7 +27,7 @@ const Home = () => {
handleSubmit(ev)}> - handleChange(ev)} /> + handleChange(ev)} />