3719 |
stevensc |
1 |
import React, { useMemo, useState } from 'react';
|
|
|
2 |
import { useSelector } from 'react-redux';
|
|
|
3 |
import { styled } from '@mui/material';
|
|
|
4 |
|
|
|
5 |
import Widget from '@components/UI/Widget';
|
|
|
6 |
import SurveyForm from '@components/survey-form/SurveyForm';
|
|
|
7 |
import FeedDescription from './feed-description';
|
|
|
8 |
|
|
|
9 |
const FeedContainer = styled(Widget.Body)(({ theme }) => ({
|
|
|
10 |
padding: 0,
|
|
|
11 |
'& > *:not(img, video, .MuiCard-root)': {
|
|
|
12 |
padding: theme.spacing(0, 1)
|
|
|
13 |
},
|
|
|
14 |
'& > p, & > span': {
|
|
|
15 |
fontSize: '1rem',
|
|
|
16 |
wordWrap: 'break-word',
|
|
|
17 |
fontWeight: 'normal'
|
|
|
18 |
},
|
|
|
19 |
'& > img, & > video ': {
|
|
|
20 |
width: '100%',
|
|
|
21 |
maxHeight: '600px',
|
|
|
22 |
objectFit: 'contain',
|
|
|
23 |
position: 'relative'
|
|
|
24 |
}
|
|
|
25 |
}));
|
|
|
26 |
|
|
|
27 |
export default function FeedContent({ id }) {
|
|
|
28 |
const [showModal, setShowModal] = useState(false);
|
|
|
29 |
|
|
|
30 |
const {
|
|
|
31 |
owner_description: description,
|
|
|
32 |
owner_file_image: image,
|
|
|
33 |
owner_file_document: document,
|
|
|
34 |
owner_file_video: video,
|
|
|
35 |
owner_file_image_preview: imagePreview,
|
|
|
36 |
feed_vote_url: voteUrl,
|
|
|
37 |
feed_content_type: contentType,
|
|
|
38 |
shared_name: sharedName,
|
|
|
39 |
shared_image: sharedImage,
|
|
|
40 |
shared_time_elapse: sharedTimeElapse,
|
|
|
41 |
shared_description: sharedFeedDescription,
|
|
|
42 |
shared_file_video: sharedFileVideo,
|
|
|
43 |
shared_file_image_preview: sharedFileImagePreview,
|
|
|
44 |
shared_file_image: sharedFileImage,
|
|
|
45 |
shared_file_document: sharedFileDocument,
|
|
|
46 |
shared_content_type: sharedContentType
|
|
|
47 |
} = useSelector(({ feed }) => feed.feeds.byId[id]);
|
|
|
48 |
|
|
|
49 |
const answers = useMemo(() => {
|
|
|
50 |
if (contentType !== 'fast-survey') return [];
|
|
|
51 |
return Array.from(
|
|
|
52 |
{ length: description.number_of_answers },
|
|
|
53 |
(_, i) => description[`answer${i + 1}`]
|
|
|
54 |
);
|
|
|
55 |
}, [description, contentType]);
|
|
|
56 |
|
|
|
57 |
const votes = useMemo(() => {
|
|
|
58 |
if (contentType !== 'fast-survey') return [];
|
|
|
59 |
return Array.from(
|
|
|
60 |
{ length: description.number_of_votes ?? 0 },
|
|
|
61 |
(_, i) => description[`votes${i + 1}`]
|
|
|
62 |
);
|
|
|
63 |
}, [description, contentType]);
|
|
|
64 |
|
|
|
65 |
const toggleModal = () => setShowModal(!showModal);
|
|
|
66 |
|
|
|
67 |
return (
|
|
|
68 |
<FeedContainer>
|
|
|
69 |
{description && contentType !== 'fast-survey' && (
|
|
|
70 |
<FeedDescription description={description} />
|
|
|
71 |
)}
|
|
|
72 |
{contentType === 'video' && (
|
|
|
73 |
<video
|
|
|
74 |
poster={imagePreview}
|
|
|
75 |
src={video}
|
|
|
76 |
onClick={toggleModal}
|
|
|
77 |
preload='none'
|
|
|
78 |
controls
|
|
|
79 |
controlsList='nodownload'
|
|
|
80 |
/>
|
|
|
81 |
)}
|
|
|
82 |
{contentType === 'image' && (
|
|
|
83 |
<img src={image} onClick={toggleModal} loading='lazy' width='100%' height='100%' />
|
|
|
84 |
)}
|
|
|
85 |
{contentType === 'document' && (
|
|
|
86 |
<a href={document} target='_blank' rel='noreferrer'>
|
|
|
87 |
<img className='pdf' src='/images/extension/pdf.png' alt='pdf' />
|
|
|
88 |
</a>
|
|
|
89 |
)}
|
|
|
90 |
{contentType === 'fast-survey' && (
|
|
|
91 |
<SurveyForm
|
|
|
92 |
voteUrl={voteUrl}
|
|
|
93 |
active={Boolean(description.active)}
|
|
|
94 |
question={description.question}
|
|
|
95 |
time={description.time_remaining}
|
|
|
96 |
resultType={description.result_type}
|
|
|
97 |
result={description.result}
|
|
|
98 |
answers={answers}
|
|
|
99 |
votes={votes}
|
|
|
100 |
/>
|
|
|
101 |
)}
|
|
|
102 |
{contentType === 'shared' && (
|
|
|
103 |
<Widget styles={{ width: 'inherit' }}>
|
|
|
104 |
<Widget.Header avatar={sharedImage} title={sharedName} subheader={sharedTimeElapse} />
|
|
|
105 |
<FeedContainer>
|
|
|
106 |
<FeedDescription description={sharedFeedDescription} />
|
|
|
107 |
{sharedContentType === 'video' && (
|
|
|
108 |
<video
|
|
|
109 |
poster={sharedFileImagePreview}
|
|
|
110 |
src={sharedFileVideo}
|
|
|
111 |
onClick={toggleModal}
|
|
|
112 |
controls
|
|
|
113 |
preload='none'
|
|
|
114 |
controlsList='nodownload'
|
|
|
115 |
/>
|
|
|
116 |
)}
|
|
|
117 |
{sharedContentType === 'image' && (
|
|
|
118 |
<img src={sharedFileImage} onClick={toggleModal} loading='lazy' width='100%' />
|
|
|
119 |
)}
|
|
|
120 |
{sharedContentType === 'document' && (
|
|
|
121 |
<a href={sharedFileDocument} target='_blank' rel='noreferrer'>
|
|
|
122 |
<img className='pdf' src='/images/extension/pdf.png' alt='pdf' />
|
|
|
123 |
</a>
|
|
|
124 |
)}
|
|
|
125 |
</FeedContainer>
|
|
|
126 |
</Widget>
|
|
|
127 |
)}
|
|
|
128 |
</FeedContainer>
|
|
|
129 |
);
|
|
|
130 |
}
|