-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chakra UI Integration: Incorporated Chakra UI components such as Container, Divider, and adjusted text styling to improve the UI. Optimized Loader Position: Ensured the loader's proper positioning and adjusted the styling for better visibility during loading. Enhanced Code Readability: Improved code structure, added comments for better readability, and optimized component organization. Improved Responsiveness: Applied Chakra UI's responsive styles and adjusted container padding for better alignment and UI consistency. These changes aim to provide an enhanced user interface with better styling and improved visual feedback during loading and quiz selection, facilitating a more user-friendly experience on the web page.
- Loading branch information
Showing
1 changed file
with
56 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,66 @@ | ||
import React, { useContext, useState } from 'react' | ||
import Form from '../../components/Form/Form' | ||
import QuizArea from '../QuizArea/QuizArea' | ||
import quizContext from '../../context/quizContext' | ||
# Home Component: UI Enhancement and Optimization | ||
|
||
## Changes Made: | ||
|
||
### Chakra UI Integration | ||
- Integrated Chakra UI components such as `Container`, `Divider`, and adjusted text styling to enhance the UI. | ||
|
||
### Loader Optimization | ||
- Ensured proper positioning of the loading spinner and adjusted styling for better visibility during loading. | ||
|
||
### Code Readability | ||
- Improved code structure, added comments for better readability, and optimized component organization. | ||
|
||
### Responsive Design | ||
- Applied Chakra UI's responsive styles and adjusted container padding for improved alignment and UI consistency. | ||
--- | ||
```javascript | ||
import React, { useContext, useState } from 'react'; | ||
import Form from '../../components/Form/Form'; | ||
import QuizArea from '../QuizArea/QuizArea'; | ||
import quizContext from '../../context/quizContext'; | ||
import { HashLoader } from 'react-spinners'; | ||
import { Text } from '@chakra-ui/react' | ||
import { Text, Container, Divider } from '@chakra-ui/react'; | ||
|
||
const Home = () => { | ||
const context = useContext(quizContext) | ||
const { setUrl, url, fetchQuestions, setLoading, loading, questions } = context | ||
const [formData, setFormData] = useState({ number: '', category: '', difficulty: '', type: '' }) | ||
const context = useContext(quizContext); | ||
const { setUrl, url, fetchQuestions, setLoading, loading, questions } = context; | ||
const [formData, setFormData] = useState({ number: '', category: '', difficulty: '', type: '' }); | ||
|
||
const handleSubmit = (e) => { | ||
e.preventDefault(); | ||
const { number, category, difficulty, type } = formData | ||
setUrl(`https://opentdb.com/api.php?amount=${number}&category=${category}&difficulty=${difficulty}&type=${type}`, fetchQuestions(url)) | ||
setLoading(true) | ||
} | ||
const { number, category, difficulty, type } = formData; | ||
setUrl(`https://opentdb.com/api.php?amount=${number}&category=${category}&difficulty=${difficulty}&type=${type}`); | ||
fetchQuestions(url); | ||
setLoading(true); | ||
}; | ||
|
||
const onChange = (e) => { | ||
setFormData({ ...formData, [e.target.name]: e.target.value }) | ||
} | ||
setFormData({ ...formData, [e.target.name]: e.target.value }); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className="d-flex justify-content-center align-items-center"> | ||
<HashLoader | ||
color={'#3585c1'} | ||
loading={loading} | ||
size={100} | ||
aria-label="Loading Spinner" | ||
data-testid="loader" | ||
style={{ backgroundColor: '#4d4d4dcc', width: '100%', height: '100vh', position: 'absolute', top: '13%' }} | ||
/> | ||
</div> | ||
{ | ||
(url === '' || questions.length === 0) | ||
? | ||
<div className="container my-3"> | ||
<Text mb={'4'} fontSize='4xl'>Start your Quiz Now</Text> | ||
<hr /> | ||
<Form handleSubmit={handleSubmit} onChange={onChange} /> | ||
</div> | ||
: | ||
<QuizArea /> | ||
} | ||
</> | ||
) | ||
} | ||
|
||
export default Home | ||
<Container maxW="lg" py="6"> | ||
{loading && ( | ||
<div style={{ position: 'relative', minHeight: '200px' }}> | ||
<HashLoader color="#3585c1" loading={loading} size={100} /> | ||
</div> | ||
)} | ||
{!url || questions.length === 0 ? ( | ||
<div> | ||
<Text fontSize="2xl" mb="4"> | ||
Start your Quiz Now | ||
</Text> | ||
<Divider mb="4" /> | ||
<Form handleSubmit={handleSubmit} onChange={onChange} /> | ||
</div> | ||
) : ( | ||
<QuizArea /> | ||
)} | ||
</Container> | ||
); | ||
}; | ||
|
||
export default Home; |