Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev Autor Línea Nro. Línea
2838 stevensc 1
import React, { useMemo, useState } from 'react'
2
import { useSelector } from 'react-redux'
3
 
4
import Widget from '@components/UI/Widget'
5
import SurveyForm from '@components/survey-form/SurveyForm'
6
import FeedDescription from './feed-description'
7
 
8
export default function FeedContent({ id }) {
9
  const [showModal, setShowModal] = useState(false)
10
 
11
  const {
12
    owner_description: description,
13
    owner_file_image: image,
14
    owner_file_document: document,
15
    owner_file_video: video,
16
    owner_file_image_preview: imagePreview,
17
    feed_vote_url: voteUrl,
18
    feed_content_type: contentType,
19
    shared_name: sharedName,
20
    shared_image: sharedImage,
21
    shared_time_elapse: sharedTimeElapse,
22
    shared_description: sharedFeedDescription,
23
    shared_file_video: sharedFileVideo,
24
    shared_file_image_preview: sharedFileImagePreview,
25
    shared_file_image: sharedFileImage,
26
    shared_file_document: sharedFileDocument,
27
    shared_content_type: sharedContentType
28
  } = useSelector(({ feed }) => feed.feeds.byId[id])
29
 
30
  const answers = useMemo(() => {
31
    if (contentType !== 'fast-survey') return []
32
    return Array.from({ length: 5 }, (_, i) => description[`answer${i + 1}`])
33
  }, [description, contentType])
34
 
35
  const votes = useMemo(() => {
36
    if (contentType !== 'fast-survey') return []
37
    return Array.from({ length: 5 }, (_, i) => description[`votes${i + 1}`])
38
  }, [description, contentType])
39
 
40
  const toggleModal = () => setShowModal(!showModal)
41
 
42
  const renderContent = ({
43
    description,
44
    image,
45
    document,
46
    video,
47
    imagePreview,
48
    voteUrl,
49
    sharedName,
50
    sharedImage,
51
    sharedTimeElapse,
52
    type
53
  }) => {
54
    switch (type) {
55
      case 'video': {
56
        return (
57
          <>
58
            <FeedDescription description={description} />
59
            <Widget.Media
60
              type='video'
2842 stevensc 61
              poster={imagePreview}
2838 stevensc 62
              src={video}
63
              onClick={toggleModal}
2842 stevensc 64
              controls
2838 stevensc 65
            />
66
          </>
67
        )
68
      }
69
      case 'image': {
70
        return (
71
          <>
72
            <FeedDescription description={description} />
73
            <Widget.Media src={image} onClick={toggleModal} />
74
          </>
75
        )
76
      }
77
      case 'document': {
78
        return (
79
          <>
80
            <FeedDescription description={description} />
81
            <a href={document} target='_blank' rel='noreferrer'>
82
              <img className='pdf' src='/images/extension/pdf.png' alt='pdf' />
83
            </a>
84
          </>
85
        )
86
      }
87
      case 'fast-survey': {
88
        return (
3015 stevensc 89
          <SurveyForm
90
            active={description.active}
91
            question={description.question}
92
            answers={answers}
93
            votes={votes}
94
            time={description.time_remaining}
95
            voteUrl={voteUrl}
96
            voted={description.voted}
97
          />
2838 stevensc 98
        )
99
      }
100
      case 'shared': {
101
        return (
102
          <>
103
            <FeedDescription description={description} />
104
            <Widget>
105
              <Widget.Header
106
                avatar={sharedImage}
107
                title={sharedName}
108
                subheader={sharedTimeElapse}
109
              />
110
              <Widget.Body>
111
                {renderContent({
112
                  type: sharedContentType,
113
                  description: sharedFeedDescription,
114
                  document: sharedFileDocument,
115
                  image: sharedFileImage,
116
                  video: sharedFileVideo,
117
                  imagePreview: sharedFileImagePreview
118
                })}
119
              </Widget.Body>
120
            </Widget>
121
          </>
122
        )
123
      }
124
      default:
2841 stevensc 125
        return <FeedDescription description={description} />
2838 stevensc 126
    }
127
  }
128
 
129
  return (
130
    <Widget.Body
131
      styles={{
132
        padding: 0,
2842 stevensc 133
        '& > *:not(img, video, .MuiCard-root)': {
2838 stevensc 134
          padding: '0 1rem'
135
        },
2842 stevensc 136
        '.MuiCard-root': {
137
          margin: '0 1rem'
138
        },
2838 stevensc 139
        '& > p, & > span': {
140
          fontSize: '1rem',
141
          wordWrap: 'break-word',
142
          fontWeight: 'normal'
143
        },
144
        '& > img, & > video ': {
145
          width: '100%',
146
          maxHeight: '600px',
2842 stevensc 147
          objectFit: 'contain',
148
          position: 'relative',
2848 stevensc 149
          backgroundColor: '#000e'
2838 stevensc 150
        }
151
      }}
152
    >
153
      {renderContent({
154
        description,
155
        image,
156
        document,
157
        video,
158
        imagePreview,
159
        voteUrl,
2841 stevensc 160
        type: sharedName ? 'shared' : contentType,
2838 stevensc 161
        sharedName,
162
        sharedImage,
163
        sharedTimeElapse
164
      })}
165
    </Widget.Body>
166
  )
167
}