Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3561 | Rev 3564 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

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