Skip to content

Commit 9bc2ca6

Browse files
authored
Initial commit to Account page (#521)
* Initial commit to Account page * Addition of Post Content Popup * Requested changes * Requested changes
2 parents 72b4709 + c57ef6f commit 9bc2ca6

File tree

16 files changed

+1650
-87
lines changed

16 files changed

+1650
-87
lines changed

package-lock.json

Lines changed: 476 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"react-responsive": "^8.0.3",
4242
"react-router-dom": "^5.1.2",
4343
"react-scripts": "^3.4.0",
44+
"react-shapes": "^0.1.0",
4445
"react-spinners": "^0.8.3",
4546
"react-switch": "^5.0.1",
4647
"react-toastify": "^6.0.5",

src/actions/commentAction.js

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { GET_COMMENTS_OF_A_POST } from './types'
2-
import { errorHandler } from '../utils/errorHandler'
3-
import axios from 'axios'
4-
import { setRequestStatus } from '../utils/setRequestStatus'
1+
import { GET_COMMENTS_OF_A_POST, RESET_COMMENTS } from "./types";
2+
import { errorHandler } from "../utils/errorHandler";
3+
import axios from "axios";
4+
import { setRequestStatus } from "../utils/setRequestStatus";
55
import { BASE_URL } from './baseApi'
66

7-
// CREATE COMMENT ON A PARTICULAR POST
7+
// CREATE COMMENT ON A PARTICULAR POST
88
export const createComment = (postId, comment) => async (dispatch) => {
99
try {
1010
const res = await axios.post(`${BASE_URL}/comment/${postId}`, comment)
@@ -14,10 +14,10 @@ export const createComment = (postId, comment) => async (dispatch) => {
1414
console.log('created comment ', res.data.comment)
1515
dispatch(getAllCommentsOfPost(postId));
1616
}
17-
} catch(error) {
18-
dispatch(errorHandler(error))
17+
} catch (error) {
18+
dispatch(errorHandler(error));
1919
}
20-
}
20+
};
2121

2222
// GET ALL COMMENTS OF A POST
2323
export const getAllCommentsOfPost = (postId) => async (dispatch) => {
@@ -26,19 +26,21 @@ export const getAllCommentsOfPost = (postId) => async (dispatch) => {
2626
dispatch(setRequestStatus(false))
2727
if(res.status === 200) {
2828
dispatch(setRequestStatus(true));
29-
console.log('fetching comments of ', postId, res.data.comments);
29+
console.log("fetching comments of ", postId, res.data.comments);
3030
dispatch({
3131
type: GET_COMMENTS_OF_A_POST,
32-
payload: res.data.comments
33-
})
32+
payload: res.data.comments,
33+
});
3434
}
35-
} catch(error) {
36-
dispatch(errorHandler(error))
35+
} catch (error) {
36+
dispatch(errorHandler(error));
3737
}
38-
}
38+
};
3939

4040
// UPDATE COMMENT OF A POST
41-
export const updateComment = (commentId, updatedComment) => async (dispatch) => {
41+
export const updateComment = (commentId, updatedComment) => async (
42+
dispatch
43+
) => {
4244
try {
4345
const res = await axios.patch(`${BASE_URL}/comment/${commentId}`, updatedComment)
4446
dispatch(setRequestStatus(false))
@@ -47,10 +49,10 @@ export const updateComment = (commentId, updatedComment) => async (dispatch) =>
4749
console.log('comment updated ', res.data.comment)
4850
dispatch(getAllCommentsOfPost())
4951
}
50-
} catch(error) {
51-
errorHandler(error)
52+
} catch (error) {
53+
errorHandler(error);
5254
}
53-
}
55+
};
5456

5557
// DELETE COMMENT
5658
export const deleteComment = (commentId) => async (dispatch) => {
@@ -59,10 +61,14 @@ export const deleteComment = (commentId) => async (dispatch) => {
5961
dispatch(setRequestStatus(false))
6062
if(res.status === 200) {
6163
dispatch(setRequestStatus(true));
62-
console.log('comment deleted ', res.data)
63-
dispatch(getAllCommentsOfPost())
64+
console.log("comment deleted ", res.data);
65+
dispatch(getAllCommentsOfPost());
6466
}
65-
} catch(error) {
66-
dispatch(errorHandler(error))
67+
} catch (error) {
68+
dispatch(errorHandler(error));
6769
}
68-
}
70+
};
71+
72+
export const resetComments = () => async (dispatch) => {
73+
dispatch({ type: RESET_COMMENTS });
74+
};

src/actions/types.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ export const GET_ALL_PINNED_POSTS = "GET_ALL_PINNED_POSTS";
3838
export const GET_EVENT_BY_ID = "GET_EVENT_BY_ID";
3939
export const GET_ADMIN = "GET_ADMIN";
4040
export const GET_COMMENTS_OF_A_POST = "GET_COMMENTS_OF_A_POST";
41+
export const RESET_COMMENTS = "RESET_COMMENTS";
4142
export const GET_SINGLE_PROJECT = "GET_SINGLE_PROJECT";
42-
export const PASSWORD_CHANGE_REQUEST_SUCCESS = "PASSWORD_CHANGE_REQUEST_SUCCESS";
43+
export const PASSWORD_CHANGE_REQUEST_SUCCESS =
44+
"PASSWORD_CHANGE_REQUEST_SUCCESS";
4345
export const PASSWORD_SUCCESSFULLY_CHANGED = "PASSWORD_SUCCESSFULLY_CHANGED";
4446
export const GET_INVITE_LINK = "GET_INVITE_LINK";
4547
export const PROCESS_INVITE_LINK = "PROCESS_INVITE_LINK";

src/reducers/commentReducer.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1-
import { GET_COMMENTS_OF_A_POST } from '../actions/types'
1+
import { GET_COMMENTS_OF_A_POST, RESET_COMMENTS } from "../actions/types";
22

33
const initialState = {
4-
allComments: []
5-
}
4+
allComments: [],
5+
};
66

77
export default (state = initialState, action) => {
8-
switch(action.type) {
8+
switch (action.type) {
99
case GET_COMMENTS_OF_A_POST: {
1010
return {
1111
...state,
12-
allComments: action.payload
13-
}
12+
allComments: action.payload,
13+
};
14+
}
15+
case RESET_COMMENTS: {
16+
return {
17+
allComments: [],
18+
};
1419
}
1520
default: {
16-
return state
21+
return state;
1722
}
1823
}
19-
}
24+
};

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

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
CardMedia,
1515
} from "@material-ui/core";
1616
import { makeStyles } from "@material-ui/core/styles";
17+
import { Button } from "react-bootstrap";
1718
import AddEventModal from "./popups/AddEventModal";
1819
import AddProjectModal from "./popups/AddProjectModal";
1920
import ArrowDropUpIcon from "@material-ui/icons/ArrowDropUp";
@@ -42,11 +43,11 @@ const styles = makeStyles((theme) => ({
4243
background: "#ffffff",
4344
border: "1px solid #cccccc",
4445
boxShadow: "1px 2px 5px rgba(0, 0, 0, 0.1)",
45-
borderRadius: "5px"
46+
borderRadius: "5px",
4647
},
4748
listStyle2: {
4849
paddingTop: 0,
49-
marginTop: "-4px"
50+
marginTop: "-4px",
5051
},
5152
info: {
5253
position: "absolute",
@@ -84,7 +85,7 @@ const styles = makeStyles((theme) => ({
8485
reply: {
8586
color: "rgba(0, 0, 0, 0.4)",
8687
fontSize: "36px",
87-
paddingLeft: "17px"
88+
paddingLeft: "17px",
8889
},
8990
paper: {
9091
marginBottom: "15px",
@@ -99,7 +100,7 @@ function NewsFeed(props) {
99100
const [showEvent, setShowEvent] = useState(false);
100101
const [writePost, showPostModal] = useState(false);
101102
const [showComment, toggle] = useState(false);
102-
const [commentId, setCommentId] = useState('');
103+
const [commentId, setCommentId] = useState("");
103104
const [events, setEvents] = useState([]);
104105
const [projects, setAllProjects] = useState([]);
105106
const [posts, setAllPosts] = useState([]);
@@ -112,7 +113,7 @@ function NewsFeed(props) {
112113
}, [props.allEvents, props.allPosts, props.allProjects, props]);
113114

114115
let handleClick = (atrb) => () => {
115-
console.log('attr ', atrb);
116+
console.log("attr ", atrb);
116117
changeType(atrb);
117118
// second("s");
118119
};
@@ -124,7 +125,7 @@ function NewsFeed(props) {
124125
setShowEvent(true);
125126
}
126127
};
127-
128+
128129
let handleClose = (modalName) => {
129130
if (modalName === "project") {
130131
setShowProject(false);
@@ -134,35 +135,35 @@ function NewsFeed(props) {
134135
};
135136

136137
let openPostModal = () => {
137-
showPostModal(true)
138-
}
138+
showPostModal(true);
139+
};
139140

140141
let closePostModal = () => {
141-
showPostModal(false)
142-
}
142+
showPostModal(false);
143+
};
143144

144145
let commentToggle = (postId) => {
145146
console.log("Comment toggle clicked!", postId);
146-
props.getAllCommentsOfPost(postId)
147+
props.getAllCommentsOfPost(postId);
147148
setCommentId(postId);
148149
toggle(!showComment);
149-
}
150+
};
150151

151152
let onUpvote = (postId) => {
152-
console.log('upvote clicked!', postId);
153-
props.upVotePost(postId)
154-
}
153+
console.log("upvote clicked!", postId);
154+
props.upVotePost(postId);
155+
};
155156

156157
let onRsvpYes = (eventId) => {
157-
console.log('On rsvp yes ', eventId);
158+
console.log("On rsvp yes ", eventId);
158159
const info = {
159-
yes: localStorage.getItem('userId')
160-
}
160+
yes: localStorage.getItem("userId"),
161+
};
161162
props.rsvpYes(eventId, info);
162-
}
163+
};
163164

164165
let onViewProject = (projectId) => {
165-
console.log('Redirecting to project ', projectId);
166+
console.log("Redirecting to project ", projectId);
166167
props.history.push(`/${projectId}/proj-info`);
167168
}
168169

@@ -173,7 +174,7 @@ function NewsFeed(props) {
173174

174175
let postContent = posts?.map((post) => {
175176
return (
176-
<div className="grid" key={post._id}>
177+
<div className="grid" key={post._id}>
177178
<Paper elevation={1} className={classes.paper}>
178179
<Card className={classes.root}>
179180
<List className={classes.listStyle}>
@@ -196,13 +197,15 @@ function NewsFeed(props) {
196197
</ListItem>
197198
<div className="post-details2">{parse(post?.content)}</div>
198199
<ListItem>
199-
<IconButton
200+
<IconButton
200201
className={classes.vote}
201202
onClick={() => onUpvote(post._id)}
202-
>
203+
>
203204
<ArrowDropUpIcon className="up-vote" />
204205
</IconButton>
205-
<span className="up-vote">{post?.votes?.upVotes?.user.length}</span>
206+
<span className="up-vote">
207+
{post?.votes?.upVotes?.user.length}
208+
</span>
206209
<span className="space"></span>
207210
<span className="com-btn">
208211
<ChatBubbleIcon className={classes.chat} />
@@ -218,8 +221,8 @@ function NewsFeed(props) {
218221
</Card>
219222
</Paper>
220223
</div>
221-
)
222-
})
224+
);
225+
});
223226

224227
let projectsContent = projects?.map((project) => {
225228
return (
@@ -345,16 +348,16 @@ function NewsFeed(props) {
345348
)
346349
})
347350

348-
let content;
349-
if (type === "Project") {
350-
content = projectsContent
351-
}
352-
if (type === "Post") {
353-
content = postContent
354-
}
355-
if (type === "Event") {
356-
content = eventsContent
357-
}
351+
let content;
352+
if (type === "Project") {
353+
content = projectsContent;
354+
}
355+
if (type === "Post") {
356+
content = postContent;
357+
}
358+
if (type === "Event") {
359+
content = eventsContent;
360+
}
358361

359362
return (
360363
<>
@@ -540,18 +543,18 @@ function NewsFeed(props) {
540543
);
541544
}
542545

543-
// map state to props
546+
// map state to props
544547
const mapStateToProps = (state) => ({
545548
auth: state.auth,
546549
error: state.error,
547550
event: state.event,
548551
post: state.post,
549552
status: state.status,
550-
comment: state.comment
551-
})
553+
comment: state.comment,
554+
});
552555

553556
export default connect(mapStateToProps, {
554557
getAllCommentsOfPost,
555558
upVotePost,
556-
rsvpYes
557-
})(withRouter(NewsFeed))
559+
rsvpYes,
560+
})(withRouter(NewsFeed));

0 commit comments

Comments
 (0)