Merge pull request #95 from ClaytonWWilson/fix_follow

Fix follow
This commit is contained in:
Leon Liang 2019-12-02 00:08:07 -05:00 committed by GitHub
commit e218708e0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 12 deletions

View File

@ -449,7 +449,7 @@ exports.addSubscription = (req, res) => {
.catch(err => { .catch(err => {
return res.status(500).json({ 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 => { .catch(err => {
return res.status(500).json({ err }); return res.status(500).json({ err });
}); });
return res.status(500).json({ error: "shouldn't execute" }); return res.status(200).json({ message: "ok" });
}); });
}; };

View File

@ -70,12 +70,15 @@ const styles = {
}; };
class user extends Component { class user extends Component {
state = { constructor() {
profile: null, super();
imageUrl: null, this.state = {
topics: null, profile: null,
newTopic: null imageUrl: null,
}; topics: null,
newTopic: null
};
}
handleDelete = topic => { handleDelete = topic => {
console.log(topic); console.log(topic);
@ -83,8 +86,16 @@ class user extends Component {
.post(`/deleteTopic`, { .post(`/deleteTopic`, {
unfollow: topic unfollow: topic
}) })
.then(function() { .then(() => {
location.reload(); let tempTopics = this.state.topics;
tempTopics.forEach((oldTopic, index) => {
if (oldTopic === topic) {
tempTopics.splice(index, 1);
}
});
this.setState({
topics: tempTopics
});
}) })
.catch(function(err) { .catch(function(err) {
console.log(err); console.log(err);
@ -96,8 +107,13 @@ class user extends Component {
.post("/putTopic", { .post("/putTopic", {
following: this.state.newTopic following: this.state.newTopic
}) })
.then(function() { .then(() => {
location.reload(); let tempTopics = this.state.topics;
tempTopics.push(this.state.newTopic);
this.setState({
topics: tempTopics,
newTopic: ""
});
}) })
.catch(function(err) { .catch(function(err) {
console.log(err); console.log(err);