From 07ff311f6ffd831fba38051e7662b2a24480dcc9 Mon Sep 17 00:00:00 2001 From: Andrew Trieu Date: Sat, 22 Jul 2023 13:15:34 +0300 Subject: [PATCH] Ads and friend list --- README.md | 1 + client/src/scenes/homePage/index.jsx | 10 +++- client/src/scenes/widgets/AdsWidget.jsx | 37 +++++++++++++ client/src/scenes/widgets/ContentWidget.jsx | 2 +- client/src/scenes/widgets/FriendList.jsx | 57 +++++++++++++++++++++ client/src/scenes/widgets/PostWidget.jsx | 4 +- 6 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 client/src/scenes/widgets/AdsWidget.jsx create mode 100644 client/src/scenes/widgets/FriendList.jsx diff --git a/README.md b/README.md index d9de9ce..e61cf70 100644 --- a/README.md +++ b/README.md @@ -22,3 +22,4 @@ Table: | 18.07.2023 | Home page and navigate to login/register page if not logged in | 20 | | 19.07.2023 | Post widget | 10 | | 21.07.2023 | Each post on home page | 20 | +| 22.07.2023 | Ads and friend list | 10 | diff --git a/client/src/scenes/homePage/index.jsx b/client/src/scenes/homePage/index.jsx index cb83261..c7bf5a5 100644 --- a/client/src/scenes/homePage/index.jsx +++ b/client/src/scenes/homePage/index.jsx @@ -4,6 +4,8 @@ import Navbar from "scenes/navbar"; import UserWidget from "scenes/widgets/UserWidget"; import PostWidget from "scenes/widgets/PostWidget"; import FeedWidget from "scenes/widgets/FeedWidget"; +import AdsWidget from "scenes/widgets/AdsWidget"; +import FriendList from "scenes/widgets/FriendList"; const HomePage = () => { const isNotMobile = useMediaQuery("(min-width: 1000px)"); @@ -29,7 +31,13 @@ const HomePage = () => { - {isNotMobile && } + {isNotMobile && ( + + + + + + )} ); diff --git a/client/src/scenes/widgets/AdsWidget.jsx b/client/src/scenes/widgets/AdsWidget.jsx new file mode 100644 index 0000000..8dd2d8d --- /dev/null +++ b/client/src/scenes/widgets/AdsWidget.jsx @@ -0,0 +1,37 @@ +import { Typography, useTheme } from "@mui/material"; +import FlexBetween from "components/FlexBetween"; +import WidgetWrapper from "components/WidgetWrapper"; + +const AdsWidget = () => { + const { palette } = useTheme(); + const dark = palette.neutral.dark; + const main = palette.neutral.main; + const medium = palette.neutral.medium; + + return ( + + + + Sponsored + + Create Ad + + ads + + Helsinki, Finland + Daughter of the Baltic + + + Nobody in their right mind would come to Helsinki in November! + + + ); +}; + +export default AdsWidget; diff --git a/client/src/scenes/widgets/ContentWidget.jsx b/client/src/scenes/widgets/ContentWidget.jsx index 5bd95ad..6ecb516 100644 --- a/client/src/scenes/widgets/ContentWidget.jsx +++ b/client/src/scenes/widgets/ContentWidget.jsx @@ -6,7 +6,7 @@ import { } from "@mui/icons-material"; import { Box, Divider, Typography, IconButton, useTheme } from "@mui/material"; import FlexBetween from "components/FlexBetween"; -import Friend from "components/FriendList"; +import Friend from "components/Friend"; import WidgetWrapper from "components/WidgetWrapper"; import { useState } from "react"; import { useDispatch, useSelector } from "react-redux"; diff --git a/client/src/scenes/widgets/FriendList.jsx b/client/src/scenes/widgets/FriendList.jsx new file mode 100644 index 0000000..aeaf995 --- /dev/null +++ b/client/src/scenes/widgets/FriendList.jsx @@ -0,0 +1,57 @@ +import { Box, Typography, useTheme } from "@mui/material"; +import Friend from "components/Friend"; +import WidgetWrapper from "components/WidgetWrapper"; +import { useEffect } from "react"; +import { useDispatch, useSelector } from "react-redux"; +import { setFriends } from "state"; + +const FriendList = ({ userId }) => { + const dispatch = useDispatch(); + const { palette } = useTheme(); + const token = useSelector((state) => state.token); + const friends = useSelector((state) => state.user.friends); + + const getFriends = async () => { + const response = await fetch( + `http://localhost:3001/users/${userId}/friends`, + { + method: "GET", + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + const data = await response.json(); + dispatch(setFriends({ friends: data })); + }; + + useEffect(() => { + getFriends(); + }, []); // eslint-disable-line react-hooks/exhaustive-deps + + return ( + + + Great minds you know + + + {friends.map((friend) => ( + + ))} + + + ); +}; + +export default FriendList; diff --git a/client/src/scenes/widgets/PostWidget.jsx b/client/src/scenes/widgets/PostWidget.jsx index daab1a9..01acb00 100644 --- a/client/src/scenes/widgets/PostWidget.jsx +++ b/client/src/scenes/widgets/PostWidget.jsx @@ -53,8 +53,8 @@ const PostWidget = ({ profilePicturePath }) => { }, body: formData, }); - const posts = await response.json(); - dispatch(setPosts({ posts })); + const data = await response.json(); + dispatch(setPosts({ posts: data })); setImage(null); setPost(""); };