-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTopic.js
More file actions
35 lines (31 loc) · 1007 Bytes
/
Topic.js
File metadata and controls
35 lines (31 loc) · 1007 Bytes
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
import React from "react";
import { useSelector } from "react-redux";
import { Link, useParams, Navigate } from "react-router-dom";
import ROUTES from "../../app/routes";
// import selectors
export default function Topic() {
const topics = {}; // replace with selector
const quizzes = {}; // replace with selector
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>
);
}