Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 1033 Rev 1034
Línea 1... Línea 1...
1
import React, { useEffect, useState } from "react";
1
import React, { useEffect, useState } from "react";
2
import { connect } from "react-redux";
2
import { useDispatch } from "react-redux";
3
import { useForm } from "react-hook-form";
3
import { useForm } from "react-hook-form";
4
import FormErrorFeedback from "../../../shared/form-error-feedback/FormErrorFeedback";
4
import FormErrorFeedback from "../../../shared/form-error-feedback/FormErrorFeedback";
5
import FeedCommentTemplate from "./feed-comment/FeedCommentTemplate";
5
import FeedCommentTemplate from "./feed-comment/FeedCommentTemplate";
6
import { openShareModal as OpenShareModalAction } from "../../../redux/share-modal/shareModal.actions";
-
 
7
import { addNotification } from "../../../redux/notification/notification.actions";
-
 
8
import { deleteFeed } from "../../../redux/feed/feed.actions";
-
 
9
import { shareModalTypes } from "../../../redux/share-modal/shareModal.types";
6
import { shareModalTypes } from "../../../redux/share-modal/shareModal.types";
10
import parse from "html-react-parser";
7
import parse from "html-react-parser";
11
import { axios } from "../../../utils";
8
import { axios } from "../../../utils";
12
import ConfirmModal from "../../../shared/confirm-modal/ConfirmModal";
9
import ConfirmModal from "../../../shared/confirm-modal/ConfirmModal";
13
import { Modal } from "react-bootstrap";
10
import { Modal } from "react-bootstrap";
14
import styles from "./feedTemplate.module.scss";
11
import styles from "./feedTemplate.module.scss";
15
import { feedTypes } from "../../../redux/feed/feed.types";
12
import { feedTypes } from "../../../redux/feed/feed.types";
Línea 16... Línea 13...
16
 
13
 
-
 
14
// Redux actions
-
 
15
import { openShareModal } from "../../../redux/share-modal/shareModal.actions";
-
 
16
import { addNotification } from "../../../redux/notification/notification.actions";
-
 
17
import { deleteFeed } from "../../../redux/feed/feed.actions";
17
const FeedTemplate = (props) => {
18
 
Línea -... Línea 19...
-
 
19
const FeedTemplate = ({ feed }) => {
18
  // Destructuring feed data
20
 
19
 
21
  // Destructuring feed data
20
  const {
22
  const {
21
    feed_unique,
23
    feed_unique,
22
    feed_id_encrypted,
24
    feed_id_encrypted,
Línea 44... Línea 46...
44
    feed_is_liked,
46
    feed_is_liked,
45
    feed_share_url,
47
    feed_share_url,
46
    feed_delete_url,
48
    feed_delete_url,
47
    comments,
49
    comments,
48
    comment_add_url,
50
    comment_add_url,
49
  } = props.feed;
51
  } = feed;
50
 
-
 
51
  const [totalComments, setTotalComments] = useState(owner_comments || 0);
-
 
52
 
-
 
53
  // Destructuring redux
-
 
54
  /* const { feedType } = props; */
-
 
55
  const { deleteFeed, addNotification, openShareModal } = props;
-
 
56
 
-
 
57
  const [feedIsLiked, setFeedIsLiked] = useState(feed_is_liked);
-
 
Línea 58... Línea 52...
58
 
52
 
59
  // react hook form
53
  // react hook form
Línea 60... Línea -...
60
  const { register, handleSubmit, errors } = useForm();
-
 
61
 
54
  const { register, handleSubmit, errors } = useForm();
Línea -... Línea 55...
-
 
55
 
-
 
56
  const dispatch = useDispatch()
-
 
57
 
-
 
58
  const [totalComments, setTotalComments] = useState(owner_comments || 0);
62
  const [commentsState, setCommentsState] = useState(comments);
59
  const [feedIsLiked, setFeedIsLiked] = useState(feed_is_liked);
63
  const [ownerShared, setOwnerShared] = useState(owner_shared);
60
  const [commentsState, setCommentsState] = useState(comments);
64
 
61
  const [sharedState, setSharedState] = useState(owner_shared);
Línea 65... Línea -...
65
  const [isReadMoreActive, setIsReadMoreActive] = useState(false);
-
 
66
  const [showConfirmModal, setShowConfirmModal] = useState(false);
-
 
67
  const [show, setShow] = useState(false);
-
 
68
 
-
 
69
  useEffect(() => { 
-
 
70
    setOwnerShared(owner_shared) 
-
 
71
  }, [owner_shared]);
-
 
72
 
-
 
73
  useEffect(() => { 
62
  const [isReadMoreActive, setIsReadMoreActive] = useState(false);
74
    console.log(props)
63
  const [showConfirmModal, setShowConfirmModal] = useState(false);
-
 
64
  const [show, setShow] = useState(false);
-
 
65
 
-
 
66
  const handleClose = () => setShow(false);
-
 
67
  const handleShow = () => setShow(true);
-
 
68
 
75
  }, []);
69
  useEffect(() => {
76
 
70
    setSharedState(owner_shared)
77
  const handleClose = () => setShow(false);
71
  }, [owner_shared]);
78
  const handleShow = () => setShow(true);
72
 
79
  const deleteFeedHandler = () => {
73
  const deleteFeedHandler = () => {
80
    axios.post(feed_delete_url).then((res) => {
74
    axios.post(feed_delete_url).then((res) => {
81
      const data = res.data;
75
      const data = res.data;
82
      if (data.success) {
76
      if (data.success) {
83
        deleteFeed(feed_unique);
77
        dispatch(deleteFeed(feed_unique));
84
        addNotification({
78
        dispatch(addNotification({
85
          style: "success",
79
          style: "success",
86
          msg: data.data,
80
          msg: data.data,
87
        });
81
        }));
88
      } else {
82
      } else {
89
        addNotification({
83
        dispatch(addNotification({
90
          style: "danger",
84
          style: "danger",
91
          msg: data.data,
85
          msg: data.data,
Línea 92... Línea 86...
92
        });
86
        }));
Línea 108... Línea 102...
108
    axios.post(likeUrl).then((res) => {
102
    axios.post(likeUrl).then((res) => {
109
      const resData = res.data;
103
      const resData = res.data;
110
      const { success, data } = resData;
104
      const { success, data } = resData;
111
      if (!success) {
105
      if (!success) {
112
        setFeedIsLiked((previousState) => !previousState);
106
        setFeedIsLiked((previousState) => !previousState);
113
        addNotification({
107
        dispatch(addNotification({
114
          style: "danger",
108
          style: "danger",
115
          msg: data,
109
          msg: data,
116
        });
110
        }));
117
      }
111
      }
118
    });
112
    });
119
  };
113
  };
Línea 120... Línea 114...
120
 
114
 
Línea 130... Línea 124...
130
        const newComment = data;
124
        const newComment = data;
131
        setTotalComments(total_comments);
125
        setTotalComments(total_comments);
132
        setCommentsState([...commentsState, newComment]);
126
        setCommentsState([...commentsState, newComment]);
133
        e.target.reset();
127
        e.target.reset();
134
      } else {
128
      } else {
135
        addNotification({
129
        dispatch(addNotification({
136
          style: "danger",
130
          style: "danger",
137
          msg: data,
131
          msg: data,
138
        });
132
        }));
139
      }
133
      }
140
    });
134
    });
141
  };
135
  };
Línea 142... Línea 136...
142
 
136
 
Línea 150... Línea 144...
150
            (comment) => comment.unique !== commentUnique
144
            (comment) => comment.unique !== commentUnique
151
          );
145
          );
152
          setCommentsState(newCommentsState);
146
          setCommentsState(newCommentsState);
153
          setTotalComments(total_comments);
147
          setTotalComments(total_comments);
154
        } else {
148
        } else {
155
          addNotification({
149
          dispatch(addNotification({
156
            style: "danger",
150
            style: "danger",
157
            msg: data,
151
            msg: data,
158
          });
152
          }));
159
        }
153
        }
160
      })
154
      })
161
      .catch((error) => {
155
      .catch((error) => {
162
        addNotification({
156
        dispatch(addNotification({
163
          style: "danger",
157
          style: "danger",
164
          msg: error.message,
158
          msg: error.message,
165
        });
159
        }));
166
      });
160
      });
167
  };
161
  };
Línea 168... Línea 162...
168
 
162
 
169
  const btnShareHandler = (event) => {
163
  const btnShareHandler = (event) => {
170
    event.preventDefault();
164
    event.preventDefault();
171
    openShareModal(feed_share_url, shareModalTypes.SHARE, feedTypes.DASHBOARD, feed_unique);
165
    dispatch(openShareModal(feed_share_url, shareModalTypes.SHARE, feedTypes.DASHBOARD, feed_unique))
Línea 172... Línea 166...
172
  };
166
  };
173
 
167
 
174
  let commentsRender = null;
168
  let commentsRender = null;
Línea 422... Línea 416...
422
              <a
416
              <a
423
                href="#"
417
                href="#"
424
                id={`btn-share-${feed_unique}`}
418
                id={`btn-share-${feed_unique}`}
425
                className="btn-indicator"
419
                className="btn-indicator"
426
              >
420
              >
427
                <i className="fas fa-share"></i> {ownerShared}
421
                <i className="fas fa-share"></i> {sharedState}
428
              </a>
422
              </a>
429
            </li>
423
            </li>
430
          </ul>
424
          </ul>
431
          <a
425
          <a
432
            href={feed_share_url}
426
            href={feed_share_url}
Línea 482... Línea 476...
482
      />
476
      />
483
    </React.Fragment>
477
    </React.Fragment>
484
  );
478
  );
485
};
479
};
Línea 486... Línea -...
486
 
-
 
487
const mapStateToProps = (state) => ({
-
 
488
  currentFeed: state.feed.currentFeed,
-
 
489
  isShareModalOpen: state.feed.isShareModalOpen,
-
 
490
  feedType: state.shareModal.feedType,
-
 
491
});
-
 
492
 
-
 
493
const mapDispatchToProps = {
-
 
494
  deleteFeed: (feedId) => deleteFeed(feedId),
-
 
495
  openShareModal: (postUrl, modalType, feedType, feed_unique) => OpenShareModalAction(postUrl, modalType, feedType, feed_unique),
-
 
496
  addNotification: (notification) => addNotification(notification),
-
 
497
};
-
 
498
 
480