Skip to content

Commit 2c2073e

Browse files
committed
Mejoras de diseño y usabilidad a la hora de mostrar los resultados
1 parent 1ae85bd commit 2c2073e

File tree

11 files changed

+74
-16
lines changed

11 files changed

+74
-16
lines changed

src/App.css

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
margin: 0;
1515
}
1616

17+
html {
18+
scroll-behavior: smooth;
19+
}
20+
1721
body {
1822
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
1923
Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
@@ -26,6 +30,12 @@ body {
2630
);
2731
}
2832

33+
#root {
34+
min-height: 100dvh;
35+
display: grid;
36+
grid-template-rows: max-content 1fr max-content;
37+
}
38+
2939
.container {
3040
width: min(700px, 100%);
3141
margin-inline: auto;
@@ -34,8 +44,7 @@ body {
3444

3545
h1 {
3646
text-align: center;
37-
margin-top: 2rem;
38-
margin-bottom: 1rem;
47+
margin-block: 2rem;
3948
font-size: clamp(2.5rem, calc(2rem + 1.333vw), 3rem);
4049
text-shadow: 2px 2px 3px var(--info-color);
4150
display: flex;

src/components/finalView/FinalView.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ export const FinalView = () => {
1313
<>
1414
<article className="quiz final-view">
1515
<Score />
16-
<Dots />
1716
</article>
18-
{showResults && <Results />}
17+
{showResults && (
18+
<>
19+
<Results />
20+
<Dots />
21+
</>
22+
)}
1923
</>
2024
);
2125
};

src/components/finalView/dots/Dots.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ export const Dots = () => {
99
return (
1010
<div className="dots">
1111
{shuffleQuestions.map(({ id, correctAnswer }, i) => (
12-
<span
12+
<a
1313
key={id}
14+
href={`#question-${i + 1}`}
1415
className={`dot ${
1516
correctAnswer === userAnswers[i] ? 'correct' : 'incorrect'
1617
}`}
1718
>
1819
{i + 1}
19-
</span>
20+
</a>
2021
))}
2122
</div>
2223
);

src/components/finalView/dots/dots.css

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
.dots {
2+
background-color: #16074ebb;
3+
backdrop-filter: blur(10px);
4+
box-shadow: 0 0 6px var(--text-color);
5+
border: 2px solid var(--text-color);
6+
border-radius: 1rem;
7+
padding: 0.75rem;
28
display: flex;
39
flex-wrap: wrap;
410
justify-content: center;
511
gap: 0.6rem;
12+
position: fixed;
13+
bottom: 65px;
14+
left: 0;
15+
right: 0;
16+
z-index: 1;
17+
width: min(100%, 500px);
18+
margin-inline: auto;
619

720
.dot {
821
display: grid;
922
place-items: center;
10-
width: 1.5rem;
23+
width: 1.7rem;
1124
aspect-ratio: 1;
1225
border-radius: 50%;
13-
font-size: 0.8rem;
26+
text-decoration: none;
27+
color: white;
1428

1529
&.correct {
1630
background-color: var(--correct-color);

src/components/finalView/results/Results.jsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1-
import { useContext } from 'react';
1+
import { useContext, useEffect, useRef } from 'react';
22
import { marked } from 'marked';
33
import { QuizContext } from '../../../context/QuizContext';
44

55
import './results.css';
66

77
export const Results = () => {
88
const { shuffleQuestions, userAnswers } = useContext(QuizContext);
9+
const firstQuestionRef = useRef(null);
10+
11+
useEffect(() => {
12+
if (firstQuestionRef.current) {
13+
firstQuestionRef.current.scrollIntoView();
14+
}
15+
}, []);
16+
917
return (
1018
<section className="results">
1119
{shuffleQuestions.map((question, i) => (
12-
<article className="quiz" key={question.id}>
20+
<article
21+
className="quiz"
22+
key={question.id}
23+
id={`question-${i + 1}`}
24+
ref={i === 0 ? firstQuestionRef : null}
25+
>
1326
<h3>Pregunta {i + 1}</h3>
1427
<p>{question.question}</p>
1528
<div className="answers">

src/components/finalView/results/results.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
display: flex;
33
flex-direction: column;
44
row-gap: 1rem;
5+
margin-block-end: 7rem;
56
}

src/components/finalView/score/Score.jsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ import { QuizContext } from '../../../context/QuizContext';
44
import './score.css';
55

66
export const Score = () => {
7-
const { score, shuffleQuestions, handleRestart, setShowResults } =
8-
useContext(QuizContext);
7+
const {
8+
score,
9+
shuffleQuestions,
10+
handleRestart,
11+
setShowResults,
12+
showResults,
13+
} = useContext(QuizContext);
914

1015
const percentage = (score / shuffleQuestions.length) * 100;
1116
const message =
@@ -22,7 +27,12 @@ export const Score = () => {
2227
{shuffleQuestions.length}, consiguiendo un porcentaje de acierto de (
2328
{percentage.toFixed()}%).
2429
</p>
25-
<button onClick={() => setShowResults(true)}>Ver resultados</button>
30+
<button
31+
onClick={() => setShowResults(true)}
32+
hidden={showResults === true}
33+
>
34+
Ver resultados
35+
</button>
2636
<button onClick={handleRestart}>Jugar de nuevo</button>
2737
</section>
2838
);

src/components/quiz/answer/Answer.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ export const Answer = ({ option }) => {
1919
className={`
2020
answer
2121
${correctAnswer ? 'correct' : ''}
22-
${incorrectAnswer ? 'incorrect' : ''}`}
22+
${incorrectAnswer ? 'incorrect' : ''}
23+
${selectedOption === null ? 'cursor' : ''}
24+
`}
2325
>
2426
<input
2527
type="radio"

src/components/quiz/answer/answer.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
animation: vibrate 0.3s ease-in-out;
1717
}
1818

19+
&.cursor {
20+
cursor: pointer;
21+
}
22+
1923
input {
2024
accent-color: var(--secondary-color);
2125
}

src/components/quiz/quiz.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.quiz {
22
background-color: var(--primary-color);
33
border-radius: 16px;
4-
padding: 3rem 1.5rem;
4+
padding: 2rem 1.5rem;
55
box-shadow: 2px 2px 3px var(--secondary-color);
66
display: flex;
77
flex-direction: column;

0 commit comments

Comments
 (0)