Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2969 | Rev 3015 | 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 (
3014 stevensc 89
          <div>
90
            {JSON.stringify(answers)}
91
            {JSON.stringify(votes)}
92
          </div>
2838 stevensc 93
        )
94
      }
95
      case 'shared': {
96
        return (
97
          <>
98
            <FeedDescription description={description} />
99
            <Widget>
100
              <Widget.Header
101
                avatar={sharedImage}
102
                title={sharedName}
103
                subheader={sharedTimeElapse}
104
              />
105
              <Widget.Body>
106
                {renderContent({
107
                  type: sharedContentType,
108
                  description: sharedFeedDescription,
109
                  document: sharedFileDocument,
110
                  image: sharedFileImage,
111
                  video: sharedFileVideo,
112
                  imagePreview: sharedFileImagePreview
113
                })}
114
              </Widget.Body>
115
            </Widget>
116
          </>
117
        )
118
      }
119
      default:
2841 stevensc 120
        return <FeedDescription description={description} />
2838 stevensc 121
    }
122
  }
123
 
124
  return (
125
    <Widget.Body
126
      styles={{
127
        padding: 0,
2842 stevensc 128
        '& > *:not(img, video, .MuiCard-root)': {
2838 stevensc 129
          padding: '0 1rem'
130
        },
2842 stevensc 131
        '.MuiCard-root': {
132
          margin: '0 1rem'
133
        },
2838 stevensc 134
        '& > p, & > span': {
135
          fontSize: '1rem',
136
          wordWrap: 'break-word',
137
          fontWeight: 'normal'
138
        },
139
        '& > img, & > video ': {
140
          width: '100%',
141
          maxHeight: '600px',
2842 stevensc 142
          objectFit: 'contain',
143
          position: 'relative',
2848 stevensc 144
          backgroundColor: '#000e'
2838 stevensc 145
        }
146
      }}
147
    >
148
      {renderContent({
149
        description,
150
        image,
151
        document,
152
        video,
153
        imagePreview,
154
        voteUrl,
2841 stevensc 155
        type: sharedName ? 'shared' : contentType,
2838 stevensc 156
        sharedName,
157
        sharedImage,
158
        sharedTimeElapse
159
      })}
160
    </Widget.Body>
161
  )
162
}