Skip to content

Commit

Permalink
Update Home.jsx
Browse files Browse the repository at this point in the history
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
rishi457 committed Oct 29, 2023
1 parent d1cc221 commit 709e698
Showing 1 changed file with 56 additions and 41 deletions.
97 changes: 56 additions & 41 deletions src/pages/Home/Home.jsx
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;

0 comments on commit 709e698

Please sign in to comment.