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

React quiz by Sara, Malwina and Giorgio #109

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
380cde8
first changhes, welcome page created
GiorgioCugusi Apr 12, 2023
0cd3163
summary page craeated
GiorgioCugusi Apr 12, 2023
c82d049
Update README.md
malvinamaria Apr 12, 2023
c120fe2
adding questions on React to the quiz.js file (#1)
malvinamaria Apr 12, 2023
2fee8bb
answerbutton
GiorgioCugusi Apr 12, 2023
c3b8c66
added nextbutton and restartbutton
Apr 12, 2023
2f57b24
next and reset button styling
Apr 12, 2023
95a35f6
Merge pull request #2 from GiorgioCugusi/nextButton
SaraBat Apr 12, 2023
7ca9664
add progress bar (#3)
malvinamaria Apr 13, 2023
f59f57e
current question pages changes
GiorgioCugusi Apr 13, 2023
492cc8a
afternoon work
GiorgioCugusi Apr 13, 2023
fe7aaf3
add text to summery page depending on score (#5)
malvinamaria Apr 13, 2023
e99f485
add emojis
malvinamaria Apr 13, 2023
4d4d76e
add css styling to the welcome page (#6)
malvinamaria Apr 13, 2023
5de62ab
we
Apr 13, 2023
a2bee21
styling
Apr 13, 2023
9aae1a3
position backgroung image (#7)
malvinamaria Apr 14, 2023
523345f
move play again button centrally
malvinamaria Apr 14, 2023
3fdcaff
position progress bar (#8)
malvinamaria Apr 14, 2023
8ab5745
added progress bar (#9)
malvinamaria Apr 14, 2023
3864bfa
fix img
malvinamaria Apr 14, 2023
af3efa1
fix spelling error
malvinamaria Apr 14, 2023
e5b5efa
Update CurrentQuestion.css
GiorgioCugusi Apr 14, 2023
e7057a8
nextButton styling fix
Apr 14, 2023
72c9078
answerButton alignment fix
Apr 14, 2023
fc65f82
still fixing alignment
Apr 14, 2023
c037f8e
added live link
Apr 14, 2023
df07bb4
bottom border cancelled
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
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"react-hooks"
],
"rules": {
"linebreak-style": "off",
"react/function-component-definition": [
2,
{
Expand Down
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,26 @@ 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.
https://rococo-pony-134b75.netlify.app/

# Running Locally

This is a short guide on how to run a Redux quiz project locally.

## Prerequisites

- [Node.js](https://nodejs.org/en/) installed on your machine
- A code editor like [VSCode](https://code.visualstudio.com/) or [Sublime Text](https://www.sublimetext.com/)

## Installation

1. Clone the repository or download the project files to your local machine.
2. Open a terminal and navigate to the project directory.
3. Run `npm install` to install all the project dependencies including `react-redux`, `@reduxjs/toolkit`, and `react-router-dom`.

## Running the Project

1. After the installation is complete, run `npm start` to start the development server.
2. Once the server is started, you can view the project in your web browser by navigating to [http://localhost:3000](http://localhost:3000).

That's it! You now have the Redux project up and running on your local machine with all the required dependencies installed.
141 changes: 101 additions & 40 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"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",
Expand All @@ -13,7 +13,8 @@
"eslint-plugin-react-hooks": "^4.6.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-redux": "^8.0.2",
"react-redux": "^8.0.5",
"react-router-dom": "^6.10.0",
"react-scripts": "^5.0.1"
},
"scripts": {
Expand Down
Binary file added public/assets/linkedinlogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react';
import { BrowserRouter, Routes, Route } from 'react-router-dom';
import { Provider } from 'react-redux';
import { combineReducers, configureStore } from '@reduxjs/toolkit';
import { quiz } from 'reducers/quiz';
import { WelcomePage } from 'pages/WelcomePage';

import { CurrentQuestion } from 'components/CurrentQuestion';
import { Question } from 'pages/Question';

const reducer = combineReducers({
quiz: quiz.reducer
Expand All @@ -14,7 +16,12 @@ const store = configureStore({ reducer });
export const App = () => {
return (
<Provider store={store}>
<CurrentQuestion />
<BrowserRouter>
<Routes>
<Route path="/" element={<WelcomePage />} />
<Route path="/quiz" element={<Question />} />
</Routes>
</BrowserRouter>
</Provider>
);
}
47 changes: 47 additions & 0 deletions src/components/AnswerButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* eslint-disable max-len */
/* eslint-disable no-nested-ternary */
/* eslint-disable no-shadow */
import React, { useState } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { quiz } from '../reducers/quiz';

export const AnswerButton = ({ index, option, setGoToNextButton }) => {
const dispatch = useDispatch();
const [activeBtn, setActiveBtn] = useState(false);

// Gets all question in the store
const question = useSelector((state) => state.quiz.questions[state.quiz.currentQuestionIndex]);

// Gets the answers the user has given
const usersAnswer = useSelector((state) => state.quiz.answers[state.quiz.currentQuestionIndex]);

const onAnswerSubmit = (questionId, answerIndex) => {
dispatch(quiz.actions.submitAnswer({
questionId, answerIndex
}));
if (question.correctAnswerIndex === answerIndex) {
window.alert('Yay YOU!')
dispatch(quiz.actions.goToNextQuestion())
} else {
window.alert('Wrong answer!')
}
setActiveBtn(true);
setGoToNextButton(true);
}

const correctAnswer = usersAnswer && index === question.correctAnswerIndex;

return (
/* If activeBtn is true, it checks whether the answer is correct or incorrect based on the correctAnswer variable.
If correctAnswer is true, it sets the class to 'correct', which applies the appropriate styles to indicate a correct answer.
If correctAnswer is false, it sets the class to 'wrong', which applies the appropriate styles to indicate an incorrect answer.
If activeBtn is false, it sets the class to 'default', which applies the default styles to the button. */
<button
className={activeBtn ? (correctAnswer ? 'correct' : 'wrong') : 'default'}
onClick={() => onAnswerSubmit(question.id, index)}
disabled={usersAnswer}
type="button">
{option}
</button>
);
};
Loading