Skip to content

Commit 76d9bd9

Browse files
styled compose post
1 parent e453620 commit 76d9bd9

File tree

7 files changed

+88
-45
lines changed

7 files changed

+88
-45
lines changed

client/src/actions/getPostAction.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
RESET_IMAGE_UPLOAD,
1616
CLEAN_POST_ACTION,
1717
REALLY_GET_ALL_POSTS,
18+
SAVE_POST_TOAST,
1819
} from "../actions/types";
1920
import axios from "axios";
2021
import { loadUser } from "./authAction";
@@ -100,6 +101,10 @@ export const savePost = (post_id) => async (dispatch) => {
100101
if (post_id !== undefined) {
101102
const res = await axios.post(`/api/save/${post_id}`);
102103
dispatch({ type: TOGGLE_SAVE_POST, payload: res.data });
104+
dispatch({ type: SAVE_POST_TOAST, payload: true });
105+
setTimeout(() => {
106+
dispatch({ type: SAVE_POST_TOAST, payload: false });
107+
}, 5000);
103108
}
104109
} catch (err) {
105110
console.log(err);

client/src/actions/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ export const GET_COMMENTS = "GET_COMMENTS";
4747
export const DISPATCH_POPUP = "DISPATCH_POPUP";
4848
export const REMOVE_POPUP = "REMOVE_POPUP";
4949
export const COMMENT_TOAST = "COMMENT_TOAST";
50+
export const SAVE_POST_TOAST = "SAVE_POST_TOAST";

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,6 @@ const Post = ({
5353
// eslint-disable-next-line
5454
}, [currentPost, openedPost]);
5555

56-
/*
57-
* The effect will get the like info from backend upon
58-
* any change in liked status when liked: -- Likes47658936478563,
59-
* else Unliked834658946873, and also when the postID is recieved,
60-
* the postID is required to make the req to the backend
61-
! Both dependencies are important and completly tested
62-
? The [likedPost.length] is required bcoz ->> this handels the
63-
? setLik when we actually get the filled array, else the array
64-
? is empty tough the request id already been made, the liked post
65-
? array the [lik] was still empty ;)
66-
*/
6756
useEffect(() => {
6857
if (auth !== undefined && auth.user !== null) {
6958
getLikedPosts(auth.user._id, post._id);
@@ -86,13 +75,6 @@ const Post = ({
8675
}
8776
}, [comment.commentToast]);
8877

89-
/*
90-
* This onClick Function, request the backend to
91-
* register the like by user and save it to DB
92-
? I have used the if check on post just to be sure
93-
? whether we have got the post and handel preload
94-
? events
95-
*/
9678
const likeThisPost = () => {
9779
if (post && auth.isAuthenticated) {
9880
likePost(post._id);

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Flex } from "@chakra-ui/react";
21
import React, { useState, useEffect, Fragment } from "react";
2+
import { Flex, useToast } from "@chakra-ui/react";
33
import { connect } from "react-redux";
44
import { getTrendingPosts } from "../../../actions/trendingAction";
55
import TrendingItem from "./TrendingItem/TrendingItem";
@@ -11,6 +11,7 @@ const Trending = ({
1111
post,
1212
}) => {
1313
const [posts, setPosts] = useState([]);
14+
const toast = useToast();
1415

1516
useEffect(() => {
1617
if (trendingPosts.length === 0) {
@@ -23,6 +24,8 @@ const Trending = ({
2324
// eslint-disable-next-line
2425
}, []);
2526

27+
console.log("cool");
28+
2629
useEffect(() => {
2730
if (trendingPosts.length === 0) {
2831
getTrendingPosts();
@@ -33,9 +36,24 @@ const Trending = ({
3336

3437
// eslint-disable-next-line
3538
}, [trendingPosts.length, post.uploadedStatus]);
39+
useEffect(() => {
40+
if (post.savedToast) {
41+
toast({
42+
position: "bottom-left",
43+
title: post.status[2] === "s" ? "Saved Post" : "Unsaved Post",
44+
description:
45+
post.status[2] == "s"
46+
? "Post has been saved"
47+
: "Post has been removed from saved collection",
48+
status: "success",
49+
duration: 5000,
50+
isClosable: true,
51+
});
52+
}
53+
}, [post.savedToast]);
3654

3755
return (
38-
<Flex justifyContent='center' mt='0rem'>
56+
<Flex justifyContent="center" mt="0rem">
3957
{posts.length > 0 ? (
4058
posts.map((post) => (
4159
<TrendingItem

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,23 @@ import {
88
import PostPlaceHolder from "../../PostPlaceHolder";
99
import { getAdminPrivilages } from "../../../../actions/adminPrivilagesAction";
1010
import OptionsMenu from "../../OptionsMenu";
11-
import { Avatar, AvatarBadge, Box, Flex, Image, Text } from "@chakra-ui/react";
11+
import {
12+
Avatar,
13+
AvatarBadge,
14+
Box,
15+
Flex,
16+
Image,
17+
Text,
18+
useToast,
19+
} from "@chakra-ui/react";
1220

1321
const TrendingItem = ({
1422
post,
1523
setCurrentPost,
1624
trending: { loading },
1725
routing,
1826
by,
19-
postRedu: { loadingUserPosts, savedPosts, status },
27+
postRedu: { loadingUserPosts, savedPosts, status, savedToast },
2028
getAdminPrivilages,
2129
adminPrivilages,
2230
savePost,
@@ -86,6 +94,7 @@ const TrendingItem = ({
8694
// eslint-disable-next-line
8795
}, [loadingUNI, loadingUserPosts, loading]);
8896

97+
8998
const openOptionsMenu = () => {
9099
setOpenOptions((prev) => !prev);
91100
};

client/src/components/layout components/editor/PostEditor.js

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
} from "../../../actions/getPostAction";
88
import { convertToRaw, Editor, EditorState, RichUtils } from "draft-js";
99
import { dispatchPopup } from "../../../actions/popupAction";
10+
import * as S from "@chakra-ui/react";
11+
import styled from "styled-components";
1012

1113
const PostEditor = ({
1214
uploadPost,
@@ -76,45 +78,64 @@ const PostEditor = ({
7678
};
7779

7880
return (
79-
<div className="d-flex flex-column editor-container-compose">
80-
<div className="img-upload">
81-
<input
81+
<S.Flex flexDir="column" px="300px" w="100%">
82+
<S.Flex>
83+
<S.Input
8284
type="file"
8385
name="file"
8486
id="file"
8587
className="custom-file-input"
8688
onChange={addFile}
89+
w="250px"
8790
/>
88-
<div className="custom-upload post-post-btn">Upload Image</div>
89-
{upload === "Uploading..." && (
90-
<div className="img-loader">
91-
<div className="the-moving-grad"></div>
92-
</div>
93-
)}
94-
</div>
95-
<div className="d-flex justify-content-center compose-heading">
96-
<input
91+
{upload === "Uploading..." && <div>uploading...</div>}
92+
</S.Flex>
93+
<S.Flex mt="20px" w="100%">
94+
<S.Input
9795
type="text"
9896
placeholder="Title"
9997
spellCheck="false"
10098
maxLength="100"
10199
value={heading}
102100
onChange={handleHeadingChange}
103101
/>
104-
</div>
105-
<Editor
106-
editorState={editorState}
107-
onChange={setEditorState}
108-
handleKeyCommand={handleKeyCommand}
109-
className="the-main-editor"
110-
/>
111-
<button className="post-post-btn" onClick={handleSave}>
112-
<span>{post.uploadedStatus ? "" : "Post"}</span>
113-
</button>
114-
</div>
102+
</S.Flex>
103+
<S.Box
104+
boxShadow="base"
105+
my="30px"
106+
mt="15px"
107+
rounded="md"
108+
border="2px solid #00000020"
109+
>
110+
<EditorWrapper>
111+
<Editor
112+
editorState={editorState}
113+
onChange={setEditorState}
114+
handleKeyCommand={handleKeyCommand}
115+
className="the-main-editor"
116+
/>
117+
</EditorWrapper>
118+
</S.Box>
119+
<S.Button w="250px" onClick={handleSave}>
120+
<S.Text>{post.uploadedStatus ? "" : "Post"}</S.Text>
121+
</S.Button>
122+
</S.Flex>
115123
);
116124
};
117125

126+
const EditorWrapper = styled.div`
127+
.DraftEditor-root {
128+
.DraftEditor-editorContainer {
129+
.public-DraftEditor-content div {
130+
margin: 20px;
131+
div {
132+
margin: 0;
133+
}
134+
}
135+
}
136+
}
137+
`;
138+
118139
const mapStateToProps = (state) => {
119140
return {
120141
auth: state.auth,

client/src/reducers/getPost.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
CLEAN_POST_ACTION,
1717
DELETE_POST,
1818
REALLY_GET_ALL_POSTS,
19+
SAVE_POST_TOAST,
1920
} from "../actions/types";
2021

2122
const initialState = {
@@ -34,6 +35,7 @@ const initialState = {
3435
imageUploaded: false,
3536
arePosts: true, //check weather are there some posts
3637
deletedStatus: "",
38+
savedToast: false,
3739
};
3840

3941
const postReducer = (state = initialState, action) => {
@@ -142,6 +144,11 @@ const postReducer = (state = initialState, action) => {
142144
imageUploaded: false,
143145
arePosts: true,
144146
};
147+
case SAVE_POST_TOAST:
148+
return {
149+
...state,
150+
savedToast: action.payload,
151+
};
145152
default:
146153
return state;
147154
}

0 commit comments

Comments
 (0)