Skip to content

Commit 87afd9e

Browse files
work on displaying user posts in profile
1 parent d222d47 commit 87afd9e

File tree

12 files changed

+113
-136
lines changed

12 files changed

+113
-136
lines changed

client/src/Routes.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ const Routes = () => {
1919
<Route exact path="/post" component={Post} />
2020
<Route exact path="/that-user" component={UserProfile} />
2121
<PrivateRoute exact path="/compose-post" component={PostEditor} />
22-
<PrivateRoute exact path="/dashboard/home" component={Dashboard} />
22+
<PrivateRoute
23+
exact
24+
path="/dashboard/home/:name/:id"
25+
component={Dashboard}
26+
/>
2327
<PrivateRoute exact path="/dashboard/saved" component={SavedPost} />
2428
</Fragment>
2529
);

client/src/actions/getPostAction.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export const uploadPost = (post, post_id) => async (dispatch) => {
4747
"Content-Type": "application/json",
4848
},
4949
};
50-
console.log(post);
5150
try {
5251
if (post_id !== undefined) {
5352
const res = await axios.post(
@@ -123,7 +122,6 @@ export const getSavedPosts = () => async (dispatch) => {
123122
export const likePost = (post_id) => async (dispatch) => {
124123
try {
125124
if (post_id !== undefined) {
126-
console.log("the recieved post ID", post_id);
127125
const res = await axios.put(`/api/post/like/${post_id}`);
128126
dispatch({ type: LIKE_POST, payload: res.data });
129127
}
@@ -145,9 +143,7 @@ export const getLikedPosts = (user, post_id) => async (dispatch) => {
145143

146144
export const reallyGetAllPosts = (userId) => async (dispatch) => {
147145
try {
148-
// console.log(userId, "this");
149146
const res = await axios.get(`/api/post/real-all/${userId}`);
150-
console.log("data", res.data);
151147
dispatch({ type: REALLY_GET_ALL_POSTS, payload: res.data });
152148
} catch (error) {
153149
console.log(error.message);

client/src/components/layout components/Post/Post-Placeholder/PostHolder.js

Lines changed: 0 additions & 70 deletions
This file was deleted.

client/src/components/layout components/Post/Post.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ const Post = ({
9797
};
9898

9999
const getThatP = () => {
100-
getThatProfileE(openedPost.user);
101-
reallyGetAllPosts(openedPost.user);
102-
history.push("/that-user");
100+
// getThatProfileE(openedPost.user);
101+
// reallyGetAllPosts(openedPost.user);
102+
history.push(`/dashboard/home/${openedPost.name}/${openedPost.user}`);
103103
};
104104

105105
return (

client/src/components/layout components/Trending/Trending.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ const Trending = ({
2424
// eslint-disable-next-line
2525
}, []);
2626

27-
console.log("cool");
28-
2927
useEffect(() => {
3028
if (trendingPosts.length === 0) {
3129
getTrendingPosts();
@@ -36,6 +34,7 @@ const Trending = ({
3634

3735
// eslint-disable-next-line
3836
}, [trendingPosts.length, post.uploadedStatus]);
37+
3938
useEffect(() => {
4039
if (post.savedToast) {
4140
toast({

client/src/components/navbar/Navbar.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ const Navbar = ({
8787
</MenuItem>
8888
)}
8989
<MenuItem>
90-
<Link to="/dashboard/home">Dashboard</Link>
90+
<Link to={`/dashboard/home/user/${profile.profile._id}`}>
91+
Dashboard
92+
</Link>
9193
</MenuItem>
9294
<MenuItem>
9395
<Link to="/compose-post">Compose Post</Link>

client/src/components/pages/Dashboard.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import React, { useEffect } from "react";
22
import { connect } from "react-redux";
33
import { removeNav } from "../../actions/navAction";
44
import { clearPost } from "../../actions/getPostAction";
5-
import DashboardSideBar from "./DashboardSideBar";
65
import DashboardHome from "./DashboardHome";
76
import { Flex } from "@chakra-ui/react";
7+
import { useRouteMatch } from "react-router-dom";
88

99
const Dashboard = ({ removeNav, clearPost, history }) => {
1010
useEffect(() => {
@@ -14,9 +14,12 @@ const Dashboard = ({ removeNav, clearPost, history }) => {
1414
// eslint-disable-next-line
1515
}, []);
1616

17+
const match = useRouteMatch();
18+
console.log({ match });
19+
1720
return (
1821
<Flex>
19-
<DashboardHome routing={history} />
22+
<DashboardHome routing={history} user={match} />
2023
</Flex>
2124
);
2225
};

client/src/components/pages/DashboardHome.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,24 @@ import Profile from "./profile/Profile";
44
import { Flex, Box, Text } from "@chakra-ui/react";
55
import DashboardSideBar from "./DashboardSideBar";
66

7-
const DashboardHome = ({ routing }) => {
7+
const DashboardHome = ({ routing, user }) => {
88
return (
99
<Flex flexDir="column" pt="2rem" px="6rem" w="100vw">
10-
<Flex justifyContent='flex-start' alignItems='center'>
11-
<Box>
12-
<DashboardSideBar />
13-
</Box>
10+
<Flex justifyContent="flex-start" alignItems="center">
11+
{user.params.name === "user" && (
12+
<Box>
13+
<DashboardSideBar />
14+
</Box>
15+
)}
1416
<Box>
1517
<Text fontSize="25px" fontWeight="600">
16-
Dashboard
18+
{user.params.name === "user"
19+
? "Dashboard"
20+
: `${user.params.name}'s Profile`}
1721
</Text>
1822
</Box>
1923
</Flex>
20-
<Profile />
24+
<Profile user={user.params} />
2125
<UserPost routing={routing} />
2226
</Flex>
2327
);

client/src/components/pages/profile/Profile.js

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,19 @@ import {
1717
useSetProfileInSettings,
1818
useShowToastOnSuccessfulUpdating,
1919
} from "./profile-functions";
20+
import { reallyGetAllPosts } from "../../../actions/getPostAction";
21+
import { getThatProfileE } from "../../../actions/profileAction";
2022

2123
const Profile = ({
2224
profile,
2325
uploadProfilePhoto,
2426
loadProfile,
2527
editProfile,
2628
cleanProfile,
29+
user,
30+
post,
31+
getThatProfileE,
32+
reallyGetAllPosts,
2733
}) => {
2834
const { isOpen, onOpen, onClose } = S.useDisclosure();
2935
const toast = S.useToast();
@@ -35,16 +41,34 @@ const Profile = ({
3541
const initialRef = React.useRef();
3642
const finalRef = React.useRef();
3743

38-
useLoadProfile(loadProfile);
44+
useLoadProfile(loadProfile, { getThatProfileE, reallyGetAllPosts }, user);
3945
useSetProfileInSettings(profile, setProfileValues);
4046
useShowToastOnSuccessfulUpdating(profile, onClose, cleanProfile, toast);
4147

48+
let imgURL = "";
49+
let name = "";
50+
let bio = "";
51+
let country = "";
52+
if (user.name === "user" && profile.profile.user) {
53+
imgURL = profile.profile.image;
54+
name = profile.profile.user.name;
55+
if (!isEmpty(profile.profile)) {
56+
bio = profile.profile.bio;
57+
country = profile.profile.country;
58+
}
59+
} else if (user.name !== "user" && profile.thatProfile) {
60+
imgURL = profile.thatProfile.image;
61+
name = user.name;
62+
bio = profile.thatProfile.bio;
63+
country = profile.thatProfile.country;
64+
}
65+
4266
return (
4367
<React.Fragment>
4468
<S.Flex py="2rem">
4569
<S.Flex>
4670
<S.Image
47-
src={profile.profile && `${profile.profile.image}`}
71+
src={imgURL}
4872
fallbackSrc="https://i.ibb.co/RBT25fY/default-fallback-image.png"
4973
style={{ width: "150px", height: "150px", borderRadius: "100%" }}
5074
alt="user"
@@ -53,9 +77,9 @@ const Profile = ({
5377
<S.Flex mx="3rem" flexDir="column" py="2rem">
5478
<S.Flex>
5579
<S.Text>
56-
{profile.profile.user ? (
80+
{profile.profile.user || profile.thatProfile ? (
5781
<strong>
58-
<S.Text>{profile.profile.user.name}</S.Text>
82+
<S.Text>{name}</S.Text>
5983
</strong>
6084
) : (
6185
<S.Skeleton height="20px" w="220px" my="5px"></S.Skeleton>
@@ -64,30 +88,32 @@ const Profile = ({
6488
</S.Flex>
6589
<S.Flex flexDir="column">
6690
<S.Text>
67-
{!isEmpty(profile.profile) ? (
68-
profile.profile.bio
91+
{!isEmpty(profile.profile) || profile.thatProfile ? (
92+
<S.Text>{bio}</S.Text>
6993
) : (
7094
<S.Skeleton height="20px" w="180px" mb="5px"></S.Skeleton>
7195
)}
7296
</S.Text>
7397
<S.Text>
74-
{!isEmpty(profile.profile) ? (
75-
profile.profile.country
98+
{!isEmpty(profile.profile) || profile.thatProfile ? (
99+
<S.Text>{country}</S.Text>
76100
) : (
77101
<S.Skeleton height="20px" w="180px"></S.Skeleton>
78102
)}
79103
</S.Text>
80104
</S.Flex>
81105
<S.Flex>
82-
<S.Button
83-
h="30px"
84-
onClick={onOpen}
85-
my="5px"
86-
fontWeight="normal"
87-
colorScheme="blackAlpha"
88-
>
89-
Edit Profile
90-
</S.Button>
106+
{user.name === "user" && (
107+
<S.Button
108+
h="30px"
109+
onClick={onOpen}
110+
my="5px"
111+
fontWeight="normal"
112+
colorScheme="blackAlpha"
113+
>
114+
Edit Profile
115+
</S.Button>
116+
)}
91117
</S.Flex>
92118
</S.Flex>
93119
<S.Modal
@@ -164,6 +190,7 @@ const mapStateToProps = (state) => {
164190
return {
165191
auth: state.auth,
166192
profile: state.profile,
193+
post: state.post,
167194
};
168195
};
169196

@@ -173,4 +200,6 @@ export default connect(mapStateToProps, {
173200
toggleBackdrop,
174201
editProfile,
175202
cleanProfile,
203+
getThatProfileE,
204+
reallyGetAllPosts,
176205
})(Profile);

client/src/components/pages/profile/profile-functions.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ export const addProfile = (e, fn) => {
1717
fn(fd);
1818
};
1919

20-
export const useLoadProfile = (fn) => {
20+
export const useLoadProfile = (fn, a, b) => {
2121
useEffect(() => {
22-
fn();
22+
if (b.name === "user") fn();
23+
else {
24+
a.getThatProfileE(b.id);
25+
a.reallyGetAllPosts(b.id);
26+
}
2327
// eslint-disable-next-line
2428
}, []);
2529
};

0 commit comments

Comments
 (0)