Skip to content

Commit 992f9a0

Browse files
committed
fixing breakdown functions and inconsistencies
1 parent 9e4df8f commit 992f9a0

File tree

6 files changed

+52
-43
lines changed

6 files changed

+52
-43
lines changed

src/actions/postAction.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,16 @@ export const removeReaction = (postId, type) => async (dispatch) => {
111111
dispatch(errorHandler(error));
112112
}
113113
};
114+
115+
// PIN POST BY ID
116+
export const pinPost = (postId) => async (dispatch) => {
117+
try {
118+
const res = await axios.patch(`${BASE_URL}/post/pin/${postId}`)
119+
if (res.status === 200) {
120+
console.log('post pinned ', res.data.post)
121+
dispatch(getAllPinnedPosts(10, 1));
122+
}
123+
} catch(error) {
124+
dispatch(errorHandler(error))
125+
}
126+
}

src/actions/usersAction.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { errorHandler } from '../utils/errorHandler'
33
import axios from 'axios'
44
import { setRequestStatus } from '../utils/setRequestStatus'
55
import { BASE_URL } from './baseApi'
6+
const userId = localStorage.getItem('userId')
67

78
// GET USER PROFILE
89
export const getProfile = (id) => async (dispatch)=> {
@@ -106,11 +107,11 @@ export const updateProfile = (userId, updatedInfo) => async (dispatch) => {
106107
}
107108

108109
// GET EVENTS CREATED BY USER
109-
export const getEventsCreatedByUser = (userId, pagination = 10, page = 1) => async (dispatch) => {
110+
export const getEventsCreatedByUser = (id = userId, pagination = 10, page = 1) => async (dispatch) => {
110111
try {
111-
console.log('getEvents userId ', userId)
112+
console.log('getEvents userId ', id)
112113
const res = await axios
113-
.get(`${BASE_URL}/event/${userId}/all?pagination=${pagination}&page=${page}`);
114+
.get(`${BASE_URL}/event/${id}/all?pagination=${pagination}&page=${page}`);
114115
dispatch(setRequestStatus(false))
115116
if(res.status === 200) {
116117
dispatch(setRequestStatus(true))
@@ -126,11 +127,11 @@ export const getEventsCreatedByUser = (userId, pagination = 10, page = 1) => asy
126127
}
127128

128129
// GET ALL PROJECT CREATED BY A USER
129-
export const getProjectCreatedByUser = (userId, pagination = 10, page = 1) => async (dispatch) => {
130+
export const getProjectCreatedByUser = (id = userId, pagination = 10, page = 1) => async (dispatch) => {
130131
try {
131-
console.log('getProjects userId ', userId)
132+
console.log('getProjects userId ', id)
132133
const res = await axios
133-
.get(`${BASE_URL}/project/${userId}/all?pagination=${pagination}&page=${page}`);
134+
.get(`${BASE_URL}/project/${id}/all?pagination=${pagination}&page=${page}`);
134135
dispatch(setRequestStatus(false))
135136
if(res.status === 200) {
136137
dispatch(setRequestStatus(true))
@@ -146,11 +147,11 @@ export const getProjectCreatedByUser = (userId, pagination = 10, page = 1) => as
146147
}
147148

148149
// GET POSTS CREATED BY USER
149-
export const getPostsCreatedByUser = (userId, pagination = 10, page = 1) => async (dispatch) => {
150+
export const getPostsCreatedByUser = (id = userId, pagination = 10, page = 1) => async (dispatch) => {
150151
try {
151-
console.log('getPosts userId ', userId)
152+
console.log('getPosts userId ', id)
152153
const res = await axios
153-
.get(`${BASE_URL}/post/${userId}/all?pagination=${pagination}&page=${page}`);
154+
.get(`${BASE_URL}/post/${id}/all?pagination=${pagination}&page=${page}`);
154155
dispatch(setRequestStatus(false))
155156
if(res.status === 200) {
156157
dispatch(setRequestStatus(true))

src/user/dashboard/news-feed/news-feed.js

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import {
1010
Avatar,
1111
ListItemText,
1212
// ListItemSecondaryAction,
13-
IconButton,
13+
// IconButton,
1414
CardMedia,
1515
} from "@material-ui/core";
1616
import { makeStyles } from "@material-ui/core/styles";
17-
import { Button, Dropdown, FormControl } from "react-bootstrap";
17+
import { Button, Dropdown } from "react-bootstrap";
1818
import AddEventModal from "./popups/AddEventModal";
1919
import AddProjectModal from "./popups/AddProjectModal";
2020
import PostReactionModal from "./popups/PostReactionsModal";
21-
import ArrowDropUpIcon from "@material-ui/icons/ArrowDropUp";
21+
// import ArrowDropUpIcon from "@material-ui/icons/ArrowDropUp";
2222
import ChatBubbleIcon from "@material-ui/icons/ChatBubble";
2323
import "../../pinned-posts/posts/posts.scss";
2424
import "./news-feed.scss";
@@ -35,15 +35,16 @@ import { withRouter } from "react-router-dom";
3535
import { rsvpYes } from "../../../actions/eventAction";
3636
import { FaEllipsisH, FaThumbtack } from "react-icons/fa";
3737
import ReactionsElement from "./ReactionsElement";
38+
import { pinPost } from '../../../actions/postAction'
3839
import Moment from "react-moment";
3940

40-
const reactionVariant = {
41-
hover: {
42-
scale: 1.3,
43-
opacity: 0.9,
44-
rotate: [0, 10, 0, -10, 0],
45-
},
46-
};
41+
// const reactionVariant = {
42+
// hover: {
43+
// scale: 1.3,
44+
// opacity: 0.9,
45+
// rotate: [0, 10, 0, -10, 0],
46+
// },
47+
// };
4748

4849
const navStyles = { position: 'fixed', width: '83%', top: '0', zIndex:1, background: '#fff', marginTop: '0px', marginBottom:'0px'}
4950

@@ -193,10 +194,10 @@ function NewsFeed(props) {
193194
toggle(!showComment);
194195
};
195196

196-
let onUpvote = (postId) => {
197-
console.log("upvote clicked!", postId);
198-
props.upVotePost(postId);
199-
};
197+
// let onUpvote = (postId) => {
198+
// console.log("upvote clicked!", postId);
199+
// props.upVotePost(postId);
200+
// };
200201

201202
let onRsvpYes = (eventId) => {
202203
console.log("On rsvp yes ", eventId);
@@ -221,6 +222,11 @@ function NewsFeed(props) {
221222
setShowReactions(false);
222223
};
223224

225+
let onPinPost = (postId) => {
226+
console.log('Pinning post ', postId)
227+
props.pinPost(postId)
228+
}
229+
224230
useEffect(() => {
225231
if (Object.keys(votes).length !== 0) {
226232
setShowReactions(true);
@@ -279,7 +285,10 @@ function NewsFeed(props) {
279285
</h2>
280286
<Moment format="DD MMM YYYY">{post?.createdAt}</Moment>
281287
</ListItemText>
282-
<FaThumbtack style={{ margin: "10px", width: "10px" }} />
288+
<FaThumbtack
289+
style={{ margin: "10px", width: "10px", cursor: "pointer" }}
290+
onClick={() => onPinPost(post._id)}
291+
/>
283292
<Dropdown>
284293
<Dropdown.Toggle
285294
as={CustomToggle}
@@ -631,5 +640,6 @@ const mapStateToProps = (state) => ({
631640
export default connect(mapStateToProps, {
632641
getAllCommentsOfPost,
633642
upVotePost,
643+
pinPost,
634644
rsvpYes,
635645
})(withRouter(NewsFeed));

src/user/dashboard/news-feed/popups/comment.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component } from "react";
22
import { Modal, Button, Row, Col, Form } from "react-bootstrap";
33
import { connect } from 'react-redux';
4-
import { createComment, getAllCommentsOfPost, deleteComment } from '../../../../actions/commentAction'
4+
import { createComment, deleteComment } from '../../../../actions/commentAction'
55
import "./comment.scss";
66
// import comments from "../../../../jsonData/comments";
77
import profile_img from '../../../../assets/svgs/profile-icon.svg'
@@ -134,4 +134,4 @@ const mapStateToProps = (state) => ({
134134
post: state.post
135135
})
136136

137-
export default connect(mapStateToProps, { getAllCommentsOfPost, createComment, deleteComment })(Comment);
137+
export default connect(mapStateToProps, {createComment, deleteComment })(Comment);

src/user/profile/profile-feed.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,6 @@ class ProfileFeed extends Component {
3030
displayingPost: 0,
3131
};
3232
}
33-
componentDidMount() {
34-
console.log(this.props);
35-
setTimeout(() => {
36-
this.props.getProfile();
37-
});
38-
setTimeout(() => {
39-
this.props.getPostsCreatedByUser();
40-
});
41-
setTimeout(() => {
42-
this.props.getEventsCreatedByUser();
43-
});
44-
setTimeout(() => {
45-
this.props.getProjectCreatedByUser();
46-
});
47-
}
4833

4934
componentWillReceiveProps(nextProps) {
5035
const { userEvents, userProjects, userPosts, userProfile } = nextProps.user;

src/user/profile/profile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ class Profile extends Component {
3232
componentDidMount() {
3333
console.log("match", this.props.match?.path);
3434
const { path, params } = this.props.match;
35-
const userId = params.id
35+
const userId = params.id ? params.id : localStorage.getItem('userId')
3636
console.log("checking profile", userId);
37-
this.props.getProfile(userId)
3837
setTimeout(() => {
38+
this.props.getProfile(userId);
3939
this.props.getOrgProfile();
4040
})
4141
setTimeout(() => {

0 commit comments

Comments
 (0)