Skip to content

Commit 1664af3

Browse files
some more corrections
1 parent 9743d4e commit 1664af3

File tree

13 files changed

+273
-84
lines changed

13 files changed

+273
-84
lines changed

client/src/App.css

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/src/App.css.map

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/src/App.js

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,43 @@
1-
import React, { useEffect } from 'react';
2-
import './App.css';
1+
import React, { useEffect } from "react";
2+
import "./App.css";
33

44
// Router
5-
import { BrowserRouter as Router, Switch } from 'react-router-dom';
5+
import { BrowserRouter as Router, Switch } from "react-router-dom";
66

77
// Redux
8-
import { Provider } from 'react-redux';
9-
import store from './store';
8+
import { Provider } from "react-redux";
9+
import store from "./store";
1010

1111
// Import Routes
12-
import Routes from './Routes';
12+
import Routes from "./Routes";
1313

1414
// Import Utilities
15-
import setAuthToken from './utils/setAuthToken';
16-
import { loadUser } from './actions/authAction';
17-
import Navbar from './components/navbar/Navbar';
15+
import setAuthToken from "./utils/setAuthToken";
16+
import { loadUser } from "./actions/authAction";
17+
import Navbar from "./components/navbar/Navbar";
18+
import PopupModal from "./components/popup-modal/PopupModal";
1819

19-
if (localStorage.getItem('token')) {
20-
setAuthToken(localStorage.getItem('token'));
20+
if (localStorage.getItem("token")) {
21+
setAuthToken(localStorage.getItem("token"));
2122
}
2223

2324
function App() {
24-
useEffect(() => {
25-
store.dispatch(loadUser());
26-
}, []);
27-
return (
28-
<Provider store={store}>
29-
<Router>
30-
<Navbar />
31-
<div className='d-flex justify-content-center container-fluid'>
32-
<Switch>
33-
<Routes />
34-
</Switch>
35-
</div>
36-
</Router>
37-
</Provider>
38-
);
25+
useEffect(() => {
26+
store.dispatch(loadUser());
27+
}, []);
28+
return (
29+
<Provider store={store}>
30+
<Router>
31+
<Navbar />
32+
<PopupModal />
33+
<div className="d-flex justify-content-center container-fluid">
34+
<Switch>
35+
<Routes />
36+
</Switch>
37+
</div>
38+
</Router>
39+
</Provider>
40+
);
3941
}
4042

4143
export default App;

client/src/App.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
@import "./components/auth/auth";
22
@import "./components/navbar/navbar";
3-
// @import "./components/pages/Home";
43
@import "./components/layout components/Trending/trending";
54
@import "./components/layout components/Trending/TrendingItem/trendingitem";
65
@import "./components/layout components/Post/post";
@@ -11,6 +10,7 @@
1110
@import "./components/pages/profile/profile";
1211
@import "./components/pages/user-profile/that-user";
1312
@import "./components/comment/comment";
13+
@import "./components/popup-modal/popup-modal";
1414

1515
.container-fluid {
1616
display: flex;

client/src/actions/getPostAction.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export const uploadImage = (fData) => async (dispatch) => {
6767
try {
6868
dispatch({ type: RESET_IMAGE_UPLOAD });
6969
const res = await axios.post("/api/upload", fData);
70-
console.log("Working... ... ...");
7170
dispatch({ type: GET_POST_ID, payload: res.data._id });
7271
} catch (err) {
7372
console.log("Upload ERR: ->>", err);

client/src/actions/popupAction.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { DISPATCH_POPUP, REMOVE_POPUP } from "./types";
2+
3+
export const dispatchPopup = (heading, message) => (dispatch) => {
4+
dispatch({ type: DISPATCH_POPUP, payload: { heading, message } });
5+
};
6+
7+
export const removePopup = () => (dispatch) => {
8+
dispatch({ type: REMOVE_POPUP });
9+
};

client/src/actions/types.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,5 @@ export const GET_THAT_PROFILE = "GET_THAT_PROFILE";
4444
export const REALLY_GET_ALL_POSTS = "REALLY_GET_ALL_POSTS";
4545
export const POST_COMMENT = "POST_COMMENT";
4646
export const GET_COMMENTS = "GET_COMMENTS";
47+
export const DISPATCH_POPUP = "DISPATCH_POPUP";
48+
export const REMOVE_POPUP = "REMOVE_POPUP";
Lines changed: 53 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,67 @@
1-
import React, { useState, useEffect, Fragment } from 'react';
2-
import { connect } from 'react-redux';
3-
import { getTrendingPosts } from '../../../actions/trendingAction';
4-
import TrendingItem from './TrendingItem/TrendingItem';
1+
import React, { useState, useEffect, Fragment } from "react";
2+
import { connect } from "react-redux";
3+
import { getTrendingPosts } from "../../../actions/trendingAction";
4+
import TrendingItem from "./TrendingItem/TrendingItem";
55

66
const Trending = ({
7-
getTrendingPosts,
8-
trending: { loading, trendingPosts },
9-
routing,
7+
getTrendingPosts,
8+
trending: { loading, trendingPosts },
9+
routing,
10+
post,
1011
}) => {
11-
const [posts, setPosts] = useState([]);
12+
const [posts, setPosts] = useState([]);
1213

13-
useEffect(() => {
14-
if (trendingPosts.length === 0) {
15-
getTrendingPosts();
16-
}
17-
if (posts.length === 0) {
18-
setPosts(trendingPosts);
19-
}
14+
useEffect(() => {
15+
if (trendingPosts.length === 0) {
16+
getTrendingPosts();
17+
}
18+
if (posts.length === 0) {
19+
setPosts(trendingPosts);
20+
}
2021

21-
// eslint-disable-next-line
22-
}, []);
22+
// eslint-disable-next-line
23+
}, []);
2324

24-
useEffect(() => {
25-
if (trendingPosts.length === 0) {
26-
getTrendingPosts();
27-
}
28-
if (posts.length === 0) {
29-
setPosts(trendingPosts);
30-
}
25+
useEffect(() => {
26+
if (trendingPosts.length === 0) {
27+
getTrendingPosts();
28+
}
29+
if (posts.length === 0) {
30+
setPosts(trendingPosts);
31+
}
3132

32-
// eslint-disable-next-line
33-
}, [trendingPosts.length]);
33+
// eslint-disable-next-line
34+
}, [trendingPosts.length, post.uploadedStatus]);
3435

35-
return (
36-
<div className='container trending d-flex justify-content-around'>
37-
{posts.length > 0 ? (
38-
posts.map((post) => (
39-
<TrendingItem
40-
key={post._id}
41-
post={post}
42-
routing={routing}
43-
by={'home'}
44-
forComp='home-trend'
45-
/>
46-
))
47-
) : (
48-
<Fragment>
49-
<TrendingItem />
50-
<TrendingItem />
51-
<TrendingItem />
52-
<TrendingItem />
53-
</Fragment>
54-
)}
55-
</div>
56-
);
36+
return (
37+
<div className="container trending d-flex justify-content-around">
38+
{posts.length > 0 ? (
39+
posts.map((post) => (
40+
<TrendingItem
41+
key={post._id}
42+
post={post}
43+
routing={routing}
44+
by={"home"}
45+
forComp="home-trend"
46+
/>
47+
))
48+
) : (
49+
<Fragment>
50+
<TrendingItem />
51+
<TrendingItem />
52+
<TrendingItem />
53+
<TrendingItem />
54+
</Fragment>
55+
)}
56+
</div>
57+
);
5758
};
5859

5960
const mapStateToProps = (state) => {
60-
return {
61-
trending: state.trending,
62-
};
61+
return {
62+
trending: state.trending,
63+
post: state.post,
64+
};
6365
};
6466

6567
export default connect(mapStateToProps, { getTrendingPosts })(Trending);

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
clearPostID,
77
} from "../../../actions/getPostAction";
88
import { convertToRaw, Editor, EditorState, RichUtils } from "draft-js";
9+
import { dispatchPopup } from "../../../actions/popupAction";
910

1011
const PostEditor = ({
1112
uploadPost,
@@ -14,6 +15,7 @@ const PostEditor = ({
1415
history,
1516
uploadImage,
1617
clearPostID,
18+
dispatchPopup,
1719
}) => {
1820
const [heading, setHeading] = useState("");
1921
const [upload, setUpload] = useState("");
@@ -28,6 +30,12 @@ const PostEditor = ({
2830
}
2931
}, [post.imageUploaded]);
3032

33+
useEffect(() => {
34+
if (upload === "Uploaded!") {
35+
dispatchPopup("Post Image", "Post image has been uploaded successfully!");
36+
}
37+
}, [upload]);
38+
3139
const handleSave = async () => {
3240
if (isAuthenticated) {
3341
const postRawContent = convertToRaw(editorState.getCurrentContent())
@@ -43,7 +51,6 @@ const PostEditor = ({
4351
}
4452
clearPostID();
4553
history.push("/");
46-
console.log(JSON.stringify(postRawContent));
4754
}
4855
};
4956

@@ -61,12 +68,10 @@ const PostEditor = ({
6168

6269
const handleKeyCommand = (command, editorState) => {
6370
const newState = RichUtils.handleKeyCommand(editorState, command);
64-
6571
if (newState) {
6672
setEditorState(newState);
6773
return "handled";
6874
}
69-
7075
return "not-handled";
7176
};
7277

@@ -121,4 +126,5 @@ export default connect(mapStateToProps, {
121126
uploadPost,
122127
uploadImage,
123128
clearPostID,
129+
dispatchPopup,
124130
})(PostEditor);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React, { Fragment } from "react";
2+
import { connect } from "react-redux";
3+
import { removePopup } from "../../actions/popupAction";
4+
5+
const PopupModal = ({ popup, removePopup }) => {
6+
return (
7+
<Fragment>
8+
{popup.mounted ? (
9+
<div className="popup-modal-container">
10+
<h4>{popup.heading}</h4>
11+
<div className="popup-msg">{popup.message}</div>
12+
<div className="confirm-act">
13+
<button onClick={removePopup}>Ok</button>
14+
</div>
15+
</div>
16+
) : (
17+
<Fragment></Fragment>
18+
)}
19+
</Fragment>
20+
);
21+
};
22+
23+
const mapStateToProps = (state) => ({
24+
popup: state.popup,
25+
});
26+
27+
export default connect(mapStateToProps, { removePopup })(PopupModal);

0 commit comments

Comments
 (0)