| 3481 |
stevensc |
1 |
import React, { useMemo } from 'react'
|
|
|
2 |
import { useSelector } from 'react-redux'
|
|
|
3 |
import { Link } from 'react-router-dom'
|
|
|
4 |
import { Typography } from '@mui/material'
|
|
|
5 |
|
|
|
6 |
import { TopicContainer, TopicProgress, TopicsGrid } from './UI'
|
|
|
7 |
import EmptySection from 'components/UI/EmptySection'
|
|
|
8 |
|
|
|
9 |
const Capsules = ({ topicId = '' }) => {
|
|
|
10 |
const capsules = useSelector(({ microlearning }) =>
|
|
|
11 |
microlearning.capsulesAllIds.map((uuid) => microlearning.capsuleById[uuid])
|
|
|
12 |
)
|
|
|
13 |
const labels = useSelector(({ intl }) => intl.labels)
|
|
|
14 |
|
|
|
15 |
const filteredCapsules = useMemo(() => {
|
|
|
16 |
if (!topicId) {
|
|
|
17 |
return capsules
|
|
|
18 |
}
|
|
|
19 |
|
|
|
20 |
return capsules.filter((capsule) => capsule.topicId === topicId)
|
|
|
21 |
}, [topicId, capsules])
|
|
|
22 |
|
|
|
23 |
return (
|
|
|
24 |
<TopicsGrid>
|
|
|
25 |
{filteredCapsules.length ? (
|
|
|
26 |
filteredCapsules.map((capsule) => (
|
|
|
27 |
<Capsule key={capsule.uuid} capsule={capsule} />
|
|
|
28 |
))
|
|
|
29 |
) : (
|
|
|
30 |
<EmptySection message={labels.datatable_szerorecords} />
|
|
|
31 |
)}
|
|
|
32 |
</TopicsGrid>
|
|
|
33 |
)
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
const Capsule = ({ capsule }) => {
|
|
|
37 |
const { name, image, progress, uuid } = capsule
|
|
|
38 |
|
|
|
39 |
return (
|
|
|
40 |
<Link to={`/microlearning/capsules/${uuid}/slides`}>
|
|
|
41 |
<TopicContainer>
|
|
|
42 |
<div className='c-header'>
|
|
|
43 |
<Typography variant='h3'>{name}</Typography>
|
|
|
44 |
</div>
|
|
|
45 |
|
|
|
46 |
<img src={image} alt='' />
|
|
|
47 |
|
|
|
48 |
<div className='c-footer'>
|
|
|
49 |
<TopicProgress variant='determinate' value={progress} />
|
|
|
50 |
|
|
|
51 |
<span>{`${progress}%`}</span>
|
|
|
52 |
</div>
|
|
|
53 |
</TopicContainer>
|
|
|
54 |
</Link>
|
|
|
55 |
)
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
export default Capsules
|