diff --git a/functions/handlers/post.js b/functions/handlers/post.js
index 2f5ce4f..788c64e 100644
--- a/functions/handlers/post.js
+++ b/functions/handlers/post.js
@@ -56,7 +56,7 @@ exports.getallPostsforUser = (req, res) => {
.catch(function(err) {
return res
.status(500)
- .json("Failed to retrieve user's posts from database.", err);
+ .json({message: "Failed to retrieve user's posts from database.", error: err});
});
};
diff --git a/twistter-frontend/src/pages/user.js b/twistter-frontend/src/pages/user.js
index 6a189b6..59c096e 100644
--- a/twistter-frontend/src/pages/user.js
+++ b/twistter-frontend/src/pages/user.js
@@ -13,6 +13,7 @@ import CardMedia from "@material-ui/core/CardMedia";
import CardContent from "@material-ui/core/CardContent";
import Button from "@material-ui/core/Button";
import Grid from "@material-ui/core/Grid";
+import CircularProgress from "@material-ui/core/CircularProgress";
import Chip from "@material-ui/core/Chip";
import Typography from "@material-ui/core/Typography";
@@ -76,7 +77,8 @@ class user extends Component {
profile: null,
imageUrl: null,
topics: null,
- newTopic: ""
+ newTopic: "",
+ loading: false
};
}
@@ -127,7 +129,8 @@ class user extends Component {
}
componentDidMount() {
- axios
+ this.setState({loading: true})
+ let userPromise = axios
.get("/user")
.then(res => {
this.setState({
@@ -141,7 +144,7 @@ class user extends Component {
})
.catch(err => console.log(err));
- axios
+ let postsPromise = axios
.get("/getallPostsforUser")
.then(res => {
// console.log(res.data);
@@ -150,6 +153,14 @@ class user extends Component {
});
})
.catch(err => console.log(err));
+
+ Promise.all([userPromise, postsPromise])
+ .then(() => {
+ this.setState({loading: false});
+ })
+ .catch((error) => {
+ console.log(error)
+ })
}
formatDate(dateString) {
@@ -259,6 +270,7 @@ class user extends Component {
) : null;
return (
+ this.state.loading ?