Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5779 | Rev 5782 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 5779 Rev 5781
Línea 30... Línea 30...
30
// Components
30
// Components
31
import FeedModal from './FeedModal'
31
import FeedModal from './FeedModal'
32
import FeedHeader from './FeedHeader'
32
import FeedHeader from './FeedHeader'
33
import FeedCommentSection from './feed-comment/FeedCommentSection'
33
import FeedCommentSection from './feed-comment/FeedCommentSection'
34
import { ReactionButton } from './withReaction'
34
import { ReactionButton } from './withReaction'
-
 
35
import useOutsideClick from '../../../hooks/useOutsideClick'
Línea 35... Línea 36...
35
 
36
 
36
const Feed = ({ feed, owner_shared, image }) => {
-
 
37
  // Destructuring feed data
37
const Feed = ({ feed, owner_shared, image }) => {
38
  const {
38
  const {
39
    feed_unique,
39
    feed_unique,
40
    owner_name,
40
    owner_name,
41
    owner_url,
41
    owner_url,
Línea 50... Línea 50...
50
    feed_delete_url,
50
    feed_delete_url,
51
    comments,
51
    comments,
52
    comment_add_url,
52
    comment_add_url,
53
    feed_share_external_url,
53
    feed_share_external_url,
54
  } = feed
54
  } = feed
55
 
-
 
56
  const dispatch = useDispatch()
-
 
57
 
-
 
58
  const [totalComments, setTotalComments] = useState(comments.length || 0)
55
  const [totalComments, setTotalComments] = useState(comments.length)
59
  //  const [feedIsLiked, setFeedIsLiked] = useState(feed_is_liked)
56
  const [totalReactions, setTotalReactions] = useState(0)
60
  const [sharedState, setSharedState] = useState(owner_shared)
57
  const [sharedState, setSharedState] = useState(owner_shared)
61
  // const [likesState, setLikesState] = useState(feed_likes)
-
 
62
  const [shareUrl, setShareUrl] = useState('')
58
  const [shareUrl, setShareUrl] = useState('')
63
  const [showComments, setShowComments] = useState(false)
-
 
Línea -... Línea 59...
-
 
59
 
64
 
60
  const [showComments, setShowComments] = useState(false)
65
  const [shareOptions, setShareOptions] = useState(false)
61
  const [shareOptions, setShareOptions] = useState(false)
Línea 66... Línea 62...
66
  const [show, setShow] = useState(false)
62
  const [show, setShow] = useState(false)
-
 
63
 
-
 
64
  const shareContainer = useRef(null)
Línea 67... Línea 65...
67
 
65
  const dispatch = useDispatch()
68
  const shareContainer = useRef(null)
66
  const outsideClick = useOutsideClick(shareContainer)
69
 
67
 
70
  useEffect(() => setSharedState(owner_shared), [owner_shared])
68
  const reactionsOptions = [
71
 
69
    {
-
 
70
      type: 'r',
72
  useEffect(() => {
71
      icon: <RecommendIcon style={{ color: '#7405f9' }} />,
73
    const handleClickOutside = (event) => {
72
    },
-
 
73
    {
74
      if (
74
      type: 's',
75
        shareContainer.current &&
75
      icon: <VolunteerActivismIcon style={{ color: '#6495ED' }} />,
-
 
76
    },
76
        !shareContainer.current.contains(event.target)
77
    {
77
      ) {
78
      type: 'l',
-
 
79
      icon: <FavoriteIcon style={{ color: '#DF704D' }} />,
-
 
80
    },
-
 
81
    {
78
        setShareOptions(false)
82
      type: 'i',
-
 
83
      icon: (
-
 
84
        <TungstenIcon
-
 
85
          style={{ color: '#F5BB5C', transform: 'rotate(180deg)' }}
79
      }
86
        />
80
    }
87
      ),
81
    document.addEventListener('mousedown', handleClickOutside)
88
    },
82
 
89
    {
83
    return () => {
90
      type: 'f',
Línea 84... Línea 91...
84
      document.removeEventListener('mousedown', handleClickOutside)
91
      icon: <EmojiEmotionsIcon style={{ color: '#FF7F50' }} />,
85
    }
92
    },
86
  }, [shareContainer])
93
  ]
87
 
94
 
Línea 100... Línea 107...
100
        })
107
        })
101
        .catch((err) => reject(err))
108
        .catch((err) => reject(err))
102
    }
109
    }
103
  })
110
  })
Línea 104... Línea 111...
104
 
111
 
-
 
112
  const saveReaction = (type) => {
-
 
113
    const reactionTypesUrl = {
-
 
114
      r: feed.feed_save_reaction_recommended_url,
-
 
115
      s: feed.feed_save_reaction_support_url,
-
 
116
      l: feed.feed_save_reaction_love_url,
-
 
117
      i: feed.feed_save_reaction_interest_url,
-
 
118
      f: feed.feed_save_reaction_fun_url,
-
 
119
    }
105
  /* const likeHandler = (likeUrl) => {
120
 
106
    axios.post(likeUrl).then((res) => {
121
    axios.post(reactionTypesUrl[type]).then((res) => {
-
 
122
      const { success, data } = res.data
107
      const { success, data } = res.data
123
 
108
      if (!success) {
124
      if (!success) {
109
        setFeedIsLiked((previousState) => !previousState)
-
 
110
        dispatch(
-
 
111
          addNotification({
-
 
112
            style: 'danger',
-
 
113
            msg: data,
-
 
114
          })
-
 
115
        )
-
 
116
      } else {
-
 
117
        setLikesState(data.likes)
-
 
118
        setFeedIsLiked(!feedIsLiked)
125
        dispatch(addNotification({ style: 'danger', msg: data }))
-
 
126
      }
-
 
127
 
-
 
128
      return data
-
 
129
    })
-
 
130
  }
-
 
131
 
-
 
132
  const deleteReaction = () => {
-
 
133
    axios.post(feed.fefeed_delete_reaction_url).then((res) => {
-
 
134
      const { success, data } = res.data
-
 
135
 
-
 
136
      if (!success) {
-
 
137
        dispatch(addNotification({ style: 'danger', msg: data }))
-
 
138
        return
-
 
139
      }
-
 
140
 
119
      }
141
      return data
120
    })
142
    })
Línea 121... Línea 143...
121
  } */
143
  }
Línea 122... Línea 144...
122
 
144
 
123
  const displayComments = () => setShowComments(!showComments)
145
  const displayComments = () => setShowComments(!showComments)
124
 
146
 
125
  const btnShareHandler = () =>
147
  const btnShareHandler = () => {
126
    dispatch(
148
    dispatch(
127
      openShareModal(
149
      openShareModal(
128
        feed_share_url,
150
        feed_share_url,
129
        shareModalTypes.SHARE,
151
        shareModalTypes.SHARE,
130
        feedTypes.DASHBOARD,
152
        feedTypes.DASHBOARD,
-
 
153
        feed_unique
-
 
154
      )
-
 
155
    )
-
 
156
  }
-
 
157
 
-
 
158
  useEffect(() => setSharedState(owner_shared), [owner_shared])
-
 
159
 
-
 
160
  useEffect(() => outsideClick && setShareOptions(false), [outsideClick])
-
 
161
 
-
 
162
  useEffect(() => {
-
 
163
    const feedReactions = feed.feed_reactions.reduce(
-
 
164
      (acc, reaction) => acc + Number(reaction.total),
-
 
165
      0
Línea 131... Línea 166...
131
        feed_unique
166
    )
132
      )
167
    setTotalReactions(feedReactions)
133
    )
168
  }, [feed.feed_reactions])
134
 
169
 
Línea 168... Línea 203...
168
              file_image: feed.shared_file_image,
203
              file_image: feed.shared_file_image,
169
              file_document: feed.shared_file_document,
204
              file_document: feed.shared_file_document,
170
            }}
205
            }}
171
          />
206
          />
172
        </div>
207
        </div>
-
 
208
        <div className="d-inline-flex align-items-center">
-
 
209
          {reactionsOptions
-
 
210
            .filter((option) =>
-
 
211
              feed.feed_reactions.find(
-
 
212
                (reaction) => reaction.reaction === option.type
-
 
213
              )
173
 
214
            )
-
 
215
            .map((reaction) => reaction.icon)}
-
 
216
        </div>
174
        <ul className="reactions-list">
217
        <ul className="reactions-list">
175
          <li>
218
          <li>
176
            <ReactionButton
219
            <ReactionButton
177
              saveReactionRecommendedUrl={
220
              onSelect={saveReaction}
178
                feed.feed_save_reaction_recommended_url
-
 
179
              }
-
 
180
              saveReactionSupportUrl={feed.feed_save_reaction_support_url}
-
 
181
              saveReactionLoveUrl={feed.feed_save_reaction_love_url}
-
 
182
              saveReactionInterestUrl={feed.feed_save_reaction_interest_url}
-
 
183
              saveReactionFunUrl={feed.feed_save_reaction_fun_url}
-
 
184
              deleteReactionUrl={feed.feed_delete_reaction_url}
221
              onDelete={deleteReaction}
185
              myReaction={feed.feed_my_reaction}
222
              myReaction={feed.feed_my_reaction}
186
              reactions={feed.feed_reactions}
-
 
187
            />
223
            />
188
          </li>
224
          </li>
189
          <li>
225
          <li>
190
            <button
226
            <button
191
              type="button"
227
              type="button"