diff --git a/README.md b/README.md index 450d2a2..fb9afa2 100644 --- a/README.md +++ b/README.md @@ -20,3 +20,4 @@ Table: | 16.07.2023 | Login and register page | 20 | | 16.07.2023 | Fix mock schema and move mock injections out of index.js | 1 | | 18.07.2023 | Home page and navigate to login/register page if not logged in | 20 | +| 19.07.2023 | Post widget | 10 | diff --git a/client/src/scenes/homePage/index.jsx b/client/src/scenes/homePage/index.jsx index 3b38331..3289eac 100644 --- a/client/src/scenes/homePage/index.jsx +++ b/client/src/scenes/homePage/index.jsx @@ -2,6 +2,7 @@ import { Box, useMediaQuery } from "@mui/material"; import { useSelector } from "react-redux"; import Navbar from "scenes/navbar"; import UserWidget from "scenes/widgets/UserWidget"; +import PostWidget from "scenes/widgets/PostWidget"; const HomePage = () => { const isNotMobile = useMediaQuery("(min-width: 1000px)"); @@ -23,7 +24,9 @@ const HomePage = () => { + > + + {isNotMobile && } diff --git a/client/src/scenes/widgets/PostWidget.jsx b/client/src/scenes/widgets/PostWidget.jsx new file mode 100644 index 0000000..daab1a9 --- /dev/null +++ b/client/src/scenes/widgets/PostWidget.jsx @@ -0,0 +1,179 @@ +import { + EditOutlined, + DeleteOutlined, + AttachFileOutlined, + GifBoxOutlined, + ImageOutlined, + MicOutlined, + MoreHorizOutlined, +} from "@mui/icons-material"; +import { + Box, + Divider, + Typography, + InputBase, + Button, + IconButton, + useTheme, + useMediaQuery, +} from "@mui/material"; +import Dropzone from "react-dropzone"; +import FlexBetween from "components/FlexBetween"; +import WidgetWrapper from "components/WidgetWrapper"; +import ProfilePhoto from "components/ProfilePhoto"; +import { useState } from "react"; +import { useDispatch, useSelector } from "react-redux"; +import { setPosts } from "state"; + +const PostWidget = ({ profilePicturePath }) => { + const dispatch = useDispatch(); + const [isImageDropzoneOpen, setIsImageDropzoneOpen] = useState(false); + const [image, setImage] = useState(null); + const [post, setPost] = useState(""); + const { palette } = useTheme(); + const { _id } = useSelector((state) => state.user); + const token = useSelector((state) => state.token); + const isNotMobile = useMediaQuery("(min-width: 1000px)"); + const mediumMain = palette.neutral.mediumMain; + const medium = palette.neutral.medium; + + const handlePost = async () => { + const formData = new FormData(); + formData.append("userId", _id); + formData.append("content", post); + if (image) { + formData.append("contentPicture", image); + formData.append("contentPicturePath", image.name); + } + + const response = await fetch(`http://localhost:3001/posts`, { + method: "POST", + headers: { + Authorization: `Bearer ${token}`, + }, + body: formData, + }); + const posts = await response.json(); + dispatch(setPosts({ posts })); + setImage(null); + setPost(""); + }; + + return ( + + + + setPost(e.target.value)} + value={post} + sx={{ + width: "100%", + backgroundColor: palette.neutral.light, + borderRadius: "2rem", + padding: "1rem 2rem", + }} + /> + + {isImageDropzoneOpen && ( + + { + setImage(acceptedFiles[0]); + }} + > + {({ getRootProps, getInputProps }) => ( + + + + {!image ? ( +

Add image to post

+ ) : ( + + {image.name} + + + )} +
+ {image && ( + setImage(null)} + sx={{ width: "15%" }} + > + + + )} +
+ )} +
+
+ )} + + + setIsImageDropzoneOpen(!isImageDropzoneOpen)} + > + + + Image + + + {isNotMobile ? ( + <> + + + Clip + + + + Attachment + + + + Audio + + + ) : ( + + + + )} + + +
+ ); +}; + +export default PostWidget;