-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTopic.js
37 lines (33 loc) · 1.18 KB
/
Topic.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import React from "react";
import { useSelector } from "react-redux";
import { Link, useParams, Navigate } from "react-router-dom";
import ROUTES from "../../app/routes";
// import selectors
import { selectQuizzes } from "../quizzes/quizzesSlice";
import { selectTopics } from "./topicsSlice";
export default function Topic() {
const topics = useSelector(selectTopics); // call to your selector to select all the topics in state
const quizzes = useSelector(selectQuizzes); // call to your selector to select quizzes
const { topicId } = useParams();
const topic = topics[topicId];
if (!topic) {
return <Navigate to={ROUTES.topicsRoute()} replace />
}
const quizzesForTopic = topic.quizIds.map((quizId) => quizzes[quizId]);
return (
<section>
<img src={topic.icon} alt="" className="topic-icon" />
<h1>{topic.name}</h1>
<ul className="quizzes-list">
{quizzesForTopic.map((quiz) => (
<li className="quiz" key={quiz.id}>
<Link to={ROUTES.quizRoute(quiz.id)}>{quiz.name}</Link>
</li>
))}
</ul>
<Link to="/quizzes/new" className="button center">
Create a New Quiz
</Link>
</section>
);
}