3481 |
stevensc |
1 |
import React, { useMemo, useState } from 'react';
|
|
|
2 |
import { useSelector } from 'react-redux';
|
|
|
3 |
import { Typography } from '@mui/material';
|
|
|
4 |
import { CheckCircle } from '@mui/icons-material';
|
|
|
5 |
|
|
|
6 |
import { TopicContainer, TopicsGrid } from './UI';
|
|
|
7 |
import EmptySection from '../../../components/UI/EmptySection';
|
|
|
8 |
import SlidesCarousel from './slides/slides-carousel';
|
|
|
9 |
|
|
|
10 |
const Slides = ({ capsuleId = '' }) => {
|
|
|
11 |
const [showCarousel, setShowCarousel] = useState(false);
|
|
|
12 |
const [currentSlideIndex, setCurrentSlideIndex] = useState(0);
|
|
|
13 |
|
|
|
14 |
const slides = useSelector(({ microlearning }) =>
|
|
|
15 |
microlearning.slidesAllIds
|
|
|
16 |
.map((uuid) => microlearning.slideById[uuid])
|
|
|
17 |
.sort((a, b) => a.order - b.order)
|
|
|
18 |
);
|
|
|
19 |
const labels = useSelector(({ intl }) => intl.labels);
|
|
|
20 |
|
|
|
21 |
const filteredSlides = useMemo(() => {
|
|
|
22 |
if (!capsuleId) {
|
|
|
23 |
return slides;
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
return slides.filter((capsule) => capsule.capsuleId === capsuleId);
|
|
|
27 |
}, [capsuleId, slides]);
|
|
|
28 |
|
|
|
29 |
if (!filteredSlides.length) {
|
|
|
30 |
return <EmptySection message={labels.datatable_szerorecords} />;
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
const handleShowCarousel = (index = 0) => {
|
|
|
34 |
setCurrentSlideIndex(index);
|
|
|
35 |
setShowCarousel(true);
|
|
|
36 |
};
|
|
|
37 |
|
|
|
38 |
const handleHideCarousel = () => {
|
|
|
39 |
setCurrentSlideIndex(0);
|
|
|
40 |
setShowCarousel(false);
|
|
|
41 |
};
|
|
|
42 |
|
|
|
43 |
return (
|
|
|
44 |
<TopicsGrid>
|
|
|
45 |
{filteredSlides.map((slide, index) => (
|
|
|
46 |
<SlidesItem key={slide.uuid} slide={slide} onClick={() => handleShowCarousel(index)} />
|
|
|
47 |
))}
|
|
|
48 |
<SlidesCarousel
|
|
|
49 |
onClose={handleHideCarousel}
|
|
|
50 |
slides={filteredSlides}
|
|
|
51 |
show={showCarousel}
|
|
|
52 |
currentSlideIndex={currentSlideIndex}
|
|
|
53 |
/>
|
|
|
54 |
</TopicsGrid>
|
|
|
55 |
);
|
|
|
56 |
};
|
|
|
57 |
|
|
|
58 |
const SlidesItem = ({ slide, onClick }) => {
|
|
|
59 |
const { name, background, file, completed } = slide;
|
|
|
60 |
|
|
|
61 |
return (
|
|
|
62 |
<TopicContainer onClick={onClick} style={{ cursor: 'pointer' }}>
|
|
|
63 |
<div className='c-header'>
|
|
|
64 |
<Typography variant='h3' title={name}>
|
|
|
65 |
{name}
|
|
|
66 |
</Typography>
|
|
|
67 |
</div>
|
|
|
68 |
<div className='c-body'>
|
|
|
69 |
{completed ? <CheckCircle color='success' /> : null}
|
|
|
70 |
<img src={background || file} alt='' />
|
|
|
71 |
</div>
|
|
|
72 |
</TopicContainer>
|
|
|
73 |
);
|
|
|
74 |
};
|
|
|
75 |
|
|
|
76 |
export default Slides;
|