| 3719 |
stevensc |
1 |
import React from 'react';
|
|
|
2 |
import { useNavigate, useParams } from 'react-router-dom';
|
|
|
3 |
import { Box, Button, Typography } from '@mui/material';
|
|
|
4 |
|
|
|
5 |
import { useModal } from '@shared/hooks';
|
|
|
6 |
import { useCapsule } from '@microlearning/hooks';
|
|
|
7 |
import { parse } from '@shared/utils';
|
|
|
8 |
|
|
|
9 |
import {
|
|
|
10 |
Card,
|
|
|
11 |
CardActions,
|
|
|
12 |
CardContent,
|
|
|
13 |
CardMedia,
|
|
|
14 |
CommentList,
|
|
|
15 |
Spinner
|
|
|
16 |
} from '@shared/components';
|
|
|
17 |
import { CapsuleCommentForm, SlideForm } from '@microlearning/components';
|
|
|
18 |
|
|
|
19 |
export function CapsuleDetailsPage() {
|
|
|
20 |
const { uuid } = useParams();
|
|
|
21 |
const navigate = useNavigate();
|
|
|
22 |
|
|
|
23 |
const { capsule, loading, addComment, removeComment } = useCapsule(uuid);
|
|
|
24 |
|
|
|
25 |
const { showModal } = useModal();
|
|
|
26 |
|
|
|
27 |
const showContent = () => {
|
|
|
28 |
if (!capsule?.slides?.length) return;
|
|
|
29 |
if (capsule?.slides?.length > 1 || capsule?.slides[0]?.type !== 'video') {
|
|
|
30 |
return navigate(`/microlearning/capsules/${uuid}`);
|
|
|
31 |
}
|
|
|
32 |
const firstSlide = capsule.slides[0];
|
|
|
33 |
showModal(firstSlide.name, <SlideForm uuid={firstSlide.uuid} autoPlay />);
|
|
|
34 |
};
|
|
|
35 |
|
|
|
36 |
if (loading || !capsule) return <Spinner />;
|
|
|
37 |
|
|
|
38 |
return (
|
|
|
39 |
<Card>
|
|
|
40 |
<CardMedia
|
|
|
41 |
src={capsule.image}
|
|
|
42 |
alt={`${capsule.name} capsule`}
|
|
|
43 |
sx={{
|
|
|
44 |
aspectRatio: 1 / 0.5,
|
|
|
45 |
objectFit: 'contain',
|
|
|
46 |
objectPosition: 'center'
|
|
|
47 |
}}
|
|
|
48 |
/>
|
|
|
49 |
<CardContent>
|
|
|
50 |
<Typography variant='h1'>{capsule.name}</Typography>
|
|
|
51 |
<Typography>{parse(capsule.description)}</Typography>
|
|
|
52 |
{capsule?.slides?.length > 0 && (
|
|
|
53 |
<Button
|
|
|
54 |
variant='contained'
|
|
|
55 |
color='primary'
|
|
|
56 |
onClick={showContent}
|
|
|
57 |
style={{ marginTop: 1, width: '100%' }}
|
|
|
58 |
>
|
|
|
59 |
Ver contenido
|
|
|
60 |
</Button>
|
|
|
61 |
)}
|
|
|
62 |
</CardContent>
|
|
|
63 |
|
|
|
64 |
<CardActions>
|
|
|
65 |
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 1, width: '100%' }}>
|
|
|
66 |
<CapsuleCommentForm onSubmit={addComment} />
|
|
|
67 |
<CommentList comments={capsule.comments} onDelete={removeComment} />
|
|
|
68 |
</Box>
|
|
|
69 |
</CardActions>
|
|
|
70 |
</Card>
|
|
|
71 |
);
|
|
|
72 |
}
|