From 9fff6ed81ca45be6e69d103fe57821dc725d8bb7 Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Fri, 22 Nov 2019 18:23:49 -0500 Subject: [PATCH 1/2] changed status code for follow/unfollow --- functions/handlers/users.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions/handlers/users.js b/functions/handlers/users.js index 283b97b..5350d19 100644 --- a/functions/handlers/users.js +++ b/functions/handlers/users.js @@ -449,7 +449,7 @@ exports.addSubscription = (req, res) => { .catch(err => { return res.status(500).json({ err }); }); - return res.status(500).json({ error: "shouldn't execute" }); + return res.status(200).json({ message: "ok" }); }); }; @@ -489,6 +489,6 @@ exports.removeSub = (req, res) => { .catch(err => { return res.status(500).json({ err }); }); - return res.status(500).json({ error: "shouldn't execute" }); + return res.status(200).json({ message: "ok" }); }); }; From 445c8b39deeebfd91bc0e77ca3fb9947ac364c67 Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Mon, 2 Dec 2019 00:00:25 -0500 Subject: [PATCH 2/2] allow delete without refreshing page --- twistter-frontend/src/pages/user.js | 36 +++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/twistter-frontend/src/pages/user.js b/twistter-frontend/src/pages/user.js index 9896f7d..4d71e98 100644 --- a/twistter-frontend/src/pages/user.js +++ b/twistter-frontend/src/pages/user.js @@ -70,12 +70,15 @@ const styles = { }; class user extends Component { - state = { - profile: null, - imageUrl: null, - topics: null, - newTopic: null - }; + constructor() { + super(); + this.state = { + profile: null, + imageUrl: null, + topics: null, + newTopic: null + }; + } handleDelete = topic => { console.log(topic); @@ -83,8 +86,16 @@ class user extends Component { .post(`/deleteTopic`, { unfollow: topic }) - .then(function() { - location.reload(); + .then(() => { + let tempTopics = this.state.topics; + tempTopics.forEach((oldTopic, index) => { + if (oldTopic === topic) { + tempTopics.splice(index, 1); + } + }); + this.setState({ + topics: tempTopics + }); }) .catch(function(err) { console.log(err); @@ -96,8 +107,13 @@ class user extends Component { .post("/putTopic", { following: this.state.newTopic }) - .then(function() { - location.reload(); + .then(() => { + let tempTopics = this.state.topics; + tempTopics.push(this.state.newTopic); + this.setState({ + topics: tempTopics, + newTopic: "" + }); }) .catch(function(err) { console.log(err);