-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from DadonStyle/dev
Dev
- Loading branch information
Showing
14 changed files
with
172 additions
and
153 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
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
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
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useState, useEffect } from "react"; | ||
import { useParams } from "react-router-dom"; | ||
import { QuestionType } from "../constants/types"; | ||
import { getShuffledQuestions } from "../utils/util"; | ||
|
||
const useGetQuestions = () => { | ||
const { category } = useParams<string>(); | ||
const [questions, setQuestions] = useState<QuestionType[] | null>(null); | ||
|
||
useEffect(() => { | ||
if (!category) return; | ||
const questions = getShuffledQuestions(category); | ||
setQuestions(questions); | ||
}, [category]); | ||
|
||
return { questions }; | ||
}; | ||
|
||
export default useGetQuestions; |
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
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { useState } from "react"; | ||
import Box from "@mui/material/Box"; | ||
import Button from "@mui/material/Button"; | ||
import { useNavigate } from "react-router-dom"; | ||
import QuestionsHandler from "../QuestionsHandler/QuestionsHandler"; | ||
import Streak from "../../components/Streak/Streak"; | ||
import MailDialog from "../../components/MailDialog/MailDialog"; | ||
import useGetQuestions from "../../hooks/useGetQuestions"; | ||
import "./QuestionsContainer.scss"; | ||
|
||
const QuestionsContainer = () => { | ||
const [streak, setStreak] = useState<number>(0); | ||
const navigate = useNavigate(); | ||
const { questions } = useGetQuestions(); | ||
const onBackClick = () => navigate("/"); | ||
|
||
return ( | ||
<Box className="question-section"> | ||
<Box className="question-top-section"> | ||
<Box className="question-top-left-buttons"> | ||
<Button className="back-button" onClick={onBackClick}> | ||
Back | ||
</Button> | ||
<MailDialog /> | ||
</Box> | ||
<Streak streak={streak} /> | ||
</Box> | ||
<Box className="question-bottom-section"> | ||
{questions && <QuestionsHandler questions={questions} setStreak={setStreak} />} | ||
</Box> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default QuestionsContainer; |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
.option-list { | ||
display: inline-flex; | ||
flex-direction: column; | ||
align-items: center; | ||
width: 100%; | ||
} | ||
|
||
.question-header { | ||
background-color: #e7f3fe; | ||
box-shadow: 0px 2px 4.1px 0px rgba(0, 0, 0, 0.25); | ||
border-radius: 14px; | ||
padding: 8px 16px; | ||
color: rgba(0, 0, 0); | ||
width: 100%; | ||
margin-bottom: 1rem; | ||
|
||
h3 { | ||
color: #000; | ||
font-family: 600; | ||
} | ||
} | ||
|
||
.submit-button { | ||
padding: 0.5rem 3rem; | ||
box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.25); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Dispatch, SetStateAction, useState } from "react"; | ||
import List from "@mui/material/List"; | ||
import ListItem from "@mui/material/ListItem"; | ||
import { Box, Button, Typography } from "@mui/material"; | ||
import OptionButton from "../../components/OptionButton/OptionButton"; | ||
import { QuestionType } from "../../constants/types"; | ||
import { prepSelection } from "../../utils/util"; | ||
import "./QuestionsHandler.scss"; | ||
|
||
interface QuestionsHandlerProps { | ||
questions: QuestionType[]; | ||
setStreak: Dispatch<SetStateAction<number>>; | ||
} | ||
|
||
const QuestionsHandler = ({ questions, setStreak }: QuestionsHandlerProps) => { | ||
const [options, setOptions] = useState(prepSelection(questions[0])); | ||
const [questionIndex, setQuestionIndex] = useState<number>(0); | ||
const [isAnySelected, setIsAnySelected] = useState<boolean>(false); | ||
|
||
const handleNextQuestion = () => { | ||
setIsAnySelected(false); | ||
setQuestionIndex((prevIndex) => { | ||
let newIndex = prevIndex + 1; | ||
if (newIndex > questions.length - 1) newIndex -= questions.length; | ||
setOptions(prepSelection(questions[newIndex])); | ||
return newIndex; | ||
}); | ||
}; | ||
|
||
const handleOptionSelection = (option: string) => () => { | ||
setIsAnySelected(true); | ||
if (option === questions[questionIndex].answer) { | ||
setStreak((prev: number) => prev + 1); | ||
return; | ||
} | ||
setStreak(0); | ||
}; | ||
|
||
return ( | ||
<Box> | ||
<Box className="question-header"> | ||
<Typography variant="h3">Question</Typography> | ||
<Typography paragraph>{questions[questionIndex].description}</Typography> | ||
</Box> | ||
<List className="option-list"> | ||
{options.map((option: string, index: number) => ( | ||
<ListItem className="option-list-item" key={option}> | ||
<OptionButton | ||
onClick={handleOptionSelection(option)} | ||
text={option} | ||
index={index} | ||
isCorrectAnswer={option === questions[questionIndex].answer} | ||
isAnySelected={isAnySelected} | ||
/> | ||
</ListItem> | ||
))} | ||
</List> | ||
<Button | ||
className="submit-button" | ||
type="submit" | ||
variant="contained" | ||
disabled={!isAnySelected} | ||
onClick={handleNextQuestion} | ||
> | ||
Next | ||
</Button> | ||
</Box> | ||
); | ||
}; | ||
export default QuestionsHandler; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.