Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 🚀 Responsive Enhancements and File Separation for #1 #3

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_RANDOM_WORD_API_URL=""
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ dist-ssr
*.njsproj
*.sln
*.sw?

# Local Environment Variables
.env.local
.env
73 changes: 8 additions & 65 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,75 +1,18 @@
import Button from "./Button/Button.jsx";
import { useEffect, useState } from "react";
import { useState } from "react";
import Home from "./components/Ui/Home/Home.jsx";

function App() {
const [words, setWords] = useState("25");
const [arrayword, setArrayWord] = useState([]);
const [wpm, setWpm] = useState(0);
let [loading, setLoading] = useState(false);

function handleRadio(e) {
setWords(e.target.value);
document.querySelector("#typeInput").focus();
const radios = document.querySelectorAll(".labelRadio");
radios.forEach((element) => (element.className = "labelRadio"));
e.target.parentElement.className += " radio-bg";
}

useEffect(() => {
let mounted = true;
setLoading(true);

const fetchWords = async () => {
try {
const response = await fetch(`https://random-word-api.herokuapp.com/word?number=${words}`);
const data = await response.json();
if (mounted) {
setArrayWord(data);
}
setLoading(false);
} catch (error) {
console.error("Error fetching words:", error);
}
};

fetchWords();

return () => {
mounted = false;
};
}, [words]);

return (
<>
<h1>Have Fun Typing!</h1>
<div className="container hight-30">
<div className="Panel">
<div className="wordContContainer">
<label htmlFor="twentyFive" className="labelRadio radio-bg">
<input type="radio" id="twentyFive" className="Radio" value="25" checked={words == "25"} onChange={handleRadio} />
25
</label>
<label htmlFor="Fifty" className="labelRadio">
<input type="radio" id="Fifty" className="Radio" value="50" checked={words == "50"} onChange={handleRadio} />
50
</label>
<label htmlFor="oneHundred" className="labelRadio">
<input type="radio" id="oneHundred" className="Radio" value="100" checked={words == "100"} onChange={handleRadio} />
100
</label>
<label htmlFor="oneFifty" className="labelRadio">
<input type="radio" id="oneFifty" className="Radio" value="150" checked={words == "150"} onChange={handleRadio} />
150
</label>
</div>
<p>WPM: {wpm}</p>
<div className="app-container">
<div className="wrapper">
<h1>Have Fun Typing!</h1>
<div className="main-content">
<Home loading={loading} setLoading={setLoading} />
</div>
</div>

<div className="container">
<Button word={arrayword} wpm={setWpm} setword={setWords} loading={loading} setLoading={setLoading} />
</div>
</>
</div>
);
}

Expand Down
180 changes: 0 additions & 180 deletions src/Button/Button.jsx

This file was deleted.

Loading