Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b70bce9
Initial setup
noraterbocs Apr 11, 2023
948081b
Restructured files to render them based on quizOver state
noraterbocs Apr 11, 2023
d5c78a2
Added logic for button click, restructured components and added progr…
noraterbocs Apr 12, 2023
8a3280a
Progress bar without props
Joanna-Philips Apr 12, 2023
a205af6
Created components for Summary page, added accordion for wrong answers
noraterbocs Apr 12, 2023
b7ea96a
Basic container
Joanna-Philips Apr 12, 2023
1dfd72d
Added icon to summary page
noraterbocs Apr 12, 2023
f61a3a3
Partly done start page
Joanna-Philips Apr 12, 2023
8e94a52
Added countdown for questions
noraterbocs Apr 12, 2023
b060fbb
Reusable button done
Joanna-Philips Apr 12, 2023
9f2096a
Reusable title, image and button done
Joanna-Philips Apr 12, 2023
c4b2d91
Merge pull request #1 from noraterbocs/start-page
Joanna-Philips Apr 12, 2023
69170e0
Merging summary branch and resolved conflicts
noraterbocs Apr 12, 2023
94e280a
Fixed typo
noraterbocs Apr 12, 2023
380e9e2
update my branch
Yu-Miao222 Apr 13, 2023
988e178
Merge branch 'master' into YU
Yu-Miao222 Apr 13, 2023
bfd8b11
Merge pull request #2 from noraterbocs/YU
Yu-Miao222 Apr 13, 2023
e806ca8
Fixed auto errors
Joanna-Philips Apr 13, 2023
25be880
Added some styling to align resuable components
noraterbocs Apr 13, 2023
2d1f64d
Attempting images in answer options
Joanna-Philips Apr 13, 2023
a8b3ccc
Updates to image options + but not fully done
Joanna-Philips Apr 13, 2023
690540e
Trying another way
Joanna-Philips Apr 13, 2023
690902f
Image options fixed
Joanna-Philips Apr 13, 2023
f43ca1d
Updated to summary page to display images for image option question
Joanna-Philips Apr 13, 2023
1ad0bde
Displays right answer in window alert
Joanna-Philips Apr 13, 2023
e1bec66
Merge pull request #3 from noraterbocs/image-options
Joanna-Philips Apr 13, 2023
567efbd
total time works now
Yu-Miao222 Apr 14, 2023
8832756
Merge branch 'master' into style/currentquestion
Yu-Miao222 Apr 14, 2023
636a3e4
Merge pull request #4 from noraterbocs/style/currentquestion
Yu-Miao222 Apr 14, 2023
3137de1
fix question images
Yu-Miao222 Apr 14, 2023
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
4 changes: 4 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
"allowSingleLine": true
}
],
"linebreak-style":[
"off",
"unix"
],
"comma-dangle": [
"error",
"never"
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ Describe how you approached to problem, and what tools and techniques you used t
## View it live

Every project should be deployed somewhere. Be sure to include the link to the deployed project so that the viewer can click around and see what it's all about.

## Image credits
German Flag - Photo by <a href="https://unsplash.com/@enginakyurt?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">engin akyurt</a> on <a href="https://unsplash.com/photos/qQomkOCpkes?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>

Paella - Photo by <a href="https://unsplash.com/ko/@dougglaslopez?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Douglas Lopez</a> on <a href="https://unsplash.com/photos/4B0cLMtJxWw?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>

393 changes: 348 additions & 45 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@
"private": true,
"dependencies": {
"@babel/eslint-parser": "^7.18.9",
"@reduxjs/toolkit": "^1.8.3",
"@reduxjs/toolkit": "^1.9.3",
"eslint": "^8.21.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsx-a11y": "^6.6.1",
"eslint-plugin-react": "^7.30.1",
"eslint-plugin-react-hooks": "^4.6.0",
"rc-progress": "^3.4.1",
"react": "^18.2.0",
"react-accessible-accordion": "^5.0.0",
"react-countdown": "^2.3.5",
"react-dom": "^18.2.0",
"react-icons": "^4.8.0",
"react-moving-text": "^0.0.7",
"react-redux": "^8.0.2",
"react-scripts": "^5.0.1"
"styled-components": "^5.3.9"
},
"scripts": {
"start": "react-scripts start",
Expand All @@ -36,6 +41,6 @@
]
},
"devDependencies": {
"react-scripts": "5.0.1"
"react-scripts": "^5.0.1"
}
}
Binary file added public/images/logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/option1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/option2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/option3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/option4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/questionImg1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/questionImg2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/questionImg3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/questionImg4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/questionImg5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/questionImg6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/questionImg7.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/questionImg8.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/questionImg9.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 18 additions & 12 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!--
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Expand All @@ -13,13 +13,19 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Technigo React App</title>
</head>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link
href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,500;1,300;1,400;1,500&display=swap"
rel="stylesheet">
<link rel="icon" href="./images/logo.jpg">
<title>Quiz!</title>
</head>

<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

Expand All @@ -29,6 +35,6 @@
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</body>

</html>
</html>
8 changes: 5 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { Provider } from 'react-redux';
import { combineReducers, configureStore } from '@reduxjs/toolkit';
import { quiz } from 'reducers/quiz';

import { CurrentQuestion } from 'components/CurrentQuestion';
import { Main } from 'components/Main';
import { GlobalStyle } from 'components/GlobalStyle';

const reducer = combineReducers({
quiz: quiz.reducer
Expand All @@ -14,7 +15,8 @@ const store = configureStore({ reducer });
export const App = () => {
return (
<Provider store={store}>
<CurrentQuestion />
<GlobalStyle />
<Main />
</Provider>
);
}
}
16 changes: 0 additions & 16 deletions src/components/CurrentQuestion.js

This file was deleted.

74 changes: 74 additions & 0 deletions src/components/CurrentQuestion/CurrentQuestion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

/* eslint-disable max-len */
import React, { useState, useRef } from 'react'
import { useSelector, useDispatch } from 'react-redux'
import { quiz } from 'reducers/quiz'
// import { Timer } from 'components/Timer';
import { Title } from 'reusable-components/Title'
import { Button, ButtonContainer } from 'reusable-components/Button'
import { Image } from 'reusable-components/Image'
import { CurrentQuestionContainer, ImgBox, OptionsImage } from './CurrentQuestionStyling'
import { ProgressBar } from '../ProgressBar';

export const CurrentQuestion = (props) => {
const question = useSelector((store) => store.quiz.questions[store.quiz.currentQuestionIndex])
const btnColor = useSelector((store) => store.quiz.btnColor)
const correctAnswerIndex = useSelector((store) => store.quiz.questions[store.quiz.currentQuestionIndex].correctAnswerIndex)
const { setScore, score } = props
const [selectedAnswerIndex, setSelectedAnswerIndex] = useState('')
const dispatch = useDispatch()
const countdownRef = useRef(null)

const onAnswerSubmit = (questionId, answerIndex) => {
if (correctAnswerIndex === answerIndex) {
setScore(score + 3)
} else {
setScore(score - 2)
}
setSelectedAnswerIndex(answerIndex)
setTimeout(() => dispatch(quiz.actions.submitAnswer({ questionId, answerIndex })), 1000)
setTimeout(() => dispatch(quiz.actions.goToNextQuestion()), 1500)
countdownRef.current.stop();
setTimeout(() => countdownRef.current.start(), 1500)
console.log(questionId)
}

console.log('score:', score)

const buttonStyle = (answerIndex) => {
if (selectedAnswerIndex === answerIndex) {
return { backgroundColor: btnColor }
}
};

if (!question) {
return <h1>Oh no! I could not find the current question!</h1>
}

return (
<CurrentQuestionContainer>
{/* <Timer countdownRef={countdownRef} setScore={setScore} score={score} /> */}
<ImgBox>
<Image src={question.img} alt="img" />
<ProgressBar />
</ImgBox>
<Title>Question: {question.questionText}</Title>
<ButtonContainer>
{question.options.map((answer, index) => {
return (
<Button
answerBtn
style={buttonStyle(index)}
type="button"
id={index}
onClick={() => onAnswerSubmit(question.id, index)}
key={answer}>
{answer.includes('.png') ? <OptionsImage src={answer} alt="option" /> : <p> {answer} </p>}
</Button>
)
})}
</ButtonContainer>
</CurrentQuestionContainer>

)
}
51 changes: 51 additions & 0 deletions src/components/CurrentQuestion/CurrentQuestionStyling.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import styled from 'styled-components';

export const CurrentQuestionContainer = styled.div`
background: linear-gradient(to right, #6E48AA, #9D50BB);
min-height: 100vh;
width: 100vw;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
gap:2rem;

@media (min-width: 1024px) {
display: flex;
width: 100vw;
height: auto;

}
`
export const ImgBox = styled.div`
max-width: 90vw;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 0 5%;
gap:1rem;
`
export const ProgressBarContainer = styled.div`
width: 100%;
display:flex;
align-items:center;
justify-content:center;
`
export const CountdownBox = styled.div`
border: 7px solid rgba(181, 118, 221, 0.65);
border-radius:50%;
padding:10px;
margin:10px;

@media (min-width: 1024px) {
display: flex;
border: 7px so1id rgba(181, 118, 221, 0.65);
border-radius: 50%;
width: 80px;
height: 80px;
}
`
export const OptionsImage = styled.img`
width:90%;
`
8 changes: 8 additions & 0 deletions src/components/GlobalStyle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { createGlobalStyle } from 'styled-components';

export const GlobalStyle = createGlobalStyle`
body {
font-family: 'Open Sans', sans-serif;
font-size: 16px;
}
`;
21 changes: 21 additions & 0 deletions src/components/Main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React, { useState } from 'react'
import { useSelector } from 'react-redux'
import { CurrentQuestion } from './CurrentQuestion/CurrentQuestion'
import { SummaryPage } from './SummaryPage/SummaryPage'
import { StartPage } from './StartPage/StartPage'
// import { Timer } from './Timer'

export const Main = () => {
const [score, setScore] = useState(0)
const showResults = useSelector((ReduxStore) => ReduxStore.quiz.quizOver)
return (
<div>
{showResults === null && (<StartPage />)}
{showResults !== null && !showResults && (
// <><Timer /><CurrentQuestion score={score} setScore={setScore} /></>
<CurrentQuestion score={score} setScore={setScore} />
)}
{showResults !== null && showResults && (<SummaryPage score={score} />)}
</div>
)
}
20 changes: 20 additions & 0 deletions src/components/ProgressBar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import { Line } from 'rc-progress';

import { useSelector } from 'react-redux'

export const ProgressBar = () => {
// eslint-disable-next-line max-len
const currentQuestionId = useSelector((store) => store.quiz.questions[store.quiz.currentQuestionIndex].id)
const totalQuestions = useSelector((store) => store.quiz.questions.length)

return (
<Line
percent={(currentQuestionId / totalQuestions) * 100}
width="80%"
trailWidth={4}
strokeWidth={4}
strokeColor="#FFBF00"
trailColor="#dfe3f5" />
)
}
22 changes: 22 additions & 0 deletions src/components/StartPage/StartPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import { useDispatch } from 'react-redux';
import { quiz } from 'reducers/quiz';
import { ButtonContainer, Button } from 'reusable-components/Button';
import { Title } from 'reusable-components/Title';
import { StartContainer, Logo } from './StartPageStyling';

export const StartPage = () => {
const dispatch = useDispatch()
const startOnClick = () => {
dispatch(quiz.actions.startQuiz())
}
return (
<StartContainer>
<Logo src="/images/logo.jpg" alt="quiz logo" />
<Title fontSize="4rem"> Quiz! </Title>
<ButtonContainer>
<Button type="button" onClick={startOnClick}>Start</Button>
</ButtonContainer>
</StartContainer>
)
}
25 changes: 25 additions & 0 deletions src/components/StartPage/StartPageStyling.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import styled from 'styled-components';

export const StartContainer = styled.div`
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
max-width: 100vw;
height:100vh;
color: #dfe3f5;
background: #9D50BB; /* fallback for old browsers */
background: -webkit-linear-gradient(to right, #6E48AA, #9D50BB); /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to right, #6E48AA, #9D50BB); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
`

export const Logo = styled.img`
display:flex;
width:40%;
border-radius: 50%;

@media (min-width: 1024px) {
width: 18%;

}
`
Loading