diff --git a/client/public/styles.css b/client/public/styles.css index 7841adc..44cdad8 100644 --- a/client/public/styles.css +++ b/client/public/styles.css @@ -11,6 +11,11 @@ body{cursor: pointer;} .home{ min-height: 100vh; + width: 100%; +} + +.recommendation{ + display: none; } .activity-info{ @@ -123,3 +128,15 @@ body{cursor: pointer;} width: 30%; } } + +@media only screen and (min-width: 1200px){ + .recommendation{ + width: 30%; + float: left; + display: block; + } + .home{ + width: 70%; + float: left; + } +} \ No newline at end of file diff --git a/client/src/Components/home.component.js b/client/src/Components/home.component.js index b9e75a2..caf7290 100644 --- a/client/src/Components/home.component.js +++ b/client/src/Components/home.component.js @@ -28,6 +28,8 @@ const Home = () => { const [skip, setSkip] = useState(0); const [likeInfo, setLikeInfo] = useState({}); const [totalLikes, setTotalLikes] = useState({}); + const [newestUser, setNewestUser] = useState([]); + const [taggedList, setTaggedList] = useState([]); useEffect(() => { check_token().then(result => { @@ -119,6 +121,35 @@ const Home = () => { }) } } + + useEffect(() => { + Axios.get('http://localhost:5000/users/get_newest') + .then(res => { + (res.data).forEach((user) => { + setNewestUser(existing => [...existing, user]) + }) + }) + .catch(err => console.log(err)); + }, []) + + useEffect(() => { + if(userInfo){ + Axios.get(`http://localhost:5000/posts/get/tagged/${userInfo.username}`) + .then(res => { + (res.data).forEach((tag) => { + Axios.get("http://localhost:5000/users") + .then(users => { + (users.data).forEach((user) => { + if(user._id === tag.user){ + tag.username = user.username; + setTaggedList(ex => [...ex, tag]); + } + }) + }) + }) + }) + } + }, [userInfo]) const GeneratePost = ({post}) => { return
@@ -154,13 +185,34 @@ const Home = () => { } return( -
- {posts.length !== 0?( - [posts.map((post)=> { - return - })] - ) - :

Loading...

} +
+
+ {posts.length !== 0?( + [posts.map((post)=> { + return + })] + ) + :

Loading...

} +
+
+
+

You might like these users:

+
    + {newestUser.map((user) => { + if (user.username !== userInfo.username){ + return
  • {user.username} (joined {moment(user.createdAt).fromNow()})
  • + }else{return null;} + })} +
+
+
+

Tags:

+ {taggedList.map((tag) => { + return

{tag.username} tagged you on a +  post

+ })} +
+
) } diff --git a/server/Routers/postRouter.js b/server/Routers/postRouter.js index c85460d..c893b05 100644 --- a/server/Routers/postRouter.js +++ b/server/Routers/postRouter.js @@ -39,6 +39,22 @@ router.post("/create", jsonParser,(req, res)=> { }) }) +router.get('/get/tagged/:user', (req, res) => { + let tagged_list = [] + const user = req.params.user + Post.find() + .sort({_id: -1}) + .then(posts => { + posts.forEach((post) => { + if(post.tags.includes(user)){ + tagged_list.push(post) + } + }) + res.json(tagged_list); + }) + .catch(err => res.status(400).json("Error: "+err)); +}) + router.get("/get/:user", (req, res)=> { const skip = req.query.skip && /^\d+$/.test(req.query.skip) ? Number(req.query.skip) : 0 Post.find({user: req.params.user}, undefined, {skip, limit: 1}).sort({_id: -1}) diff --git a/server/Routers/userRouter.js b/server/Routers/userRouter.js index 20f7a2b..f699d43 100644 --- a/server/Routers/userRouter.js +++ b/server/Routers/userRouter.js @@ -95,4 +95,12 @@ router.post('/profile', jsonParser, (req, res)=> { }).catch(err => res.status(400).json("Error: "+err)); }) +router.get('/get_newest', (req, res) => { + User.find() + .sort({_id: -1}) + .limit(3) + .then(users => res.json(users)) + .catch(err => res.status(400).json("Error: "+err)); +}) + module.exports = router; \ No newline at end of file