From a1f9a4bef34098451467160af6a91b1c1d79d8d0 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Thu, 5 Dec 2019 21:39:38 -0500 Subject: [PATCH] Fixing errors on the otherUsers page --- twistter-frontend/src/pages/otherUser.js | 49 ++++++++++++++---------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/twistter-frontend/src/pages/otherUser.js b/twistter-frontend/src/pages/otherUser.js index 14b3b40..5c4c177 100644 --- a/twistter-frontend/src/pages/otherUser.js +++ b/twistter-frontend/src/pages/otherUser.js @@ -179,24 +179,33 @@ class user extends Component { }) .catch(err => console.log(err)); - axios - .get("/getAlert") - .then(res => { - let temp = this.state.posts; - // console.log(res.data); - res.data.forEach(element => { - element ? temp.push(element) : console.err; - }); - // temp.push(res.data[0]); - this.setState({ - posts: temp + // Only add Admin posts if this is not the Admin account + let alertPromise; + if (this.state.profile !== "Admin") { + alertPromise = axios + .get("/getAlert") + .then(res => { + let temp = this.state.posts; + // console.log(res.data); + res.data.forEach(element => { + element ? temp.push(element) : console.err; + }); + // temp.push(res.data[0]); + this.setState({ + posts: temp + }); + }) + .catch(function(err) { + console.log(err); }); + } else { + alertPromise = new Promise((resolve, reject) => { + resolve(); }) - .catch(function(err) { - console.log(err); - }); + } + - Promise.all([otherUserPromise, userPromise, posts]) + Promise.all([otherUserPromise, userPromise, posts, alertPromise]) .then(() => { this.setState({ loading: false }); }) @@ -245,14 +254,14 @@ class user extends Component { this.state.myTopics.includes(topic) ? ( } /> ) : ( this.handleAdd(topic)} @@ -275,7 +284,7 @@ class user extends Component { //(this.state.posts); let postMarkup = this.state.posts ? ( this.state.posts.map(post => ( - + {this.state.imageUrl ? ( @@ -284,7 +293,7 @@ class user extends Component { )} - + {post.userHandle} @@ -320,7 +329,7 @@ class user extends Component { style={{ marginTop: "300px" }} > ) : ( - + {imageMarkup} {profileMarkup}