summaryrefslogtreecommitdiffstats
path: root/ui/src/components/main.tsx
diff options
context:
space:
mode:
authorDessalines <tyhou13@gmx.com>2020-02-05 14:24:35 -0500
committerDessalines <tyhou13@gmx.com>2020-02-05 14:24:35 -0500
commit716ce0f77934f71c2104cf24d3cd5c17d6298cac (patch)
tree056dfd956ee07530adc6e0b973ad55f59986682f /ui/src/components/main.tsx
parent8405f0ee5366ff2b1b80e5387169f59d3adbde26 (diff)
Adding if found to catch errors.
Diffstat (limited to 'ui/src/components/main.tsx')
-rw-r--r--ui/src/components/main.tsx31
1 files changed, 16 insertions, 15 deletions
diff --git a/ui/src/components/main.tsx b/ui/src/components/main.tsx
index 0970381b..161f5df4 100644
--- a/ui/src/components/main.tsx
+++ b/ui/src/components/main.tsx
@@ -590,26 +590,27 @@ export class Main extends Component<any, MainState> {
} else if (res.op == UserOperation.EditPost) {
let data = res.data as PostResponse;
let found = this.state.posts.find(c => c.id == data.post.id);
+ if (found) {
+ found.url = data.post.url;
+ found.name = data.post.name;
+ found.nsfw = data.post.nsfw;
- found.url = data.post.url;
- found.name = data.post.name;
- found.nsfw = data.post.nsfw;
-
- this.setState(this.state);
+ this.setState(this.state);
+ }
} else if (res.op == UserOperation.CreatePostLike) {
let data = res.data as PostResponse;
let found = this.state.posts.find(c => c.id == data.post.id);
-
- found.score = data.post.score;
- found.upvotes = data.post.upvotes;
- found.downvotes = data.post.downvotes;
- if (data.post.my_vote !== null) {
- found.my_vote = data.post.my_vote;
- found.upvoteLoading = false;
- found.downvoteLoading = false;
+ if (found) {
+ found.score = data.post.score;
+ found.upvotes = data.post.upvotes;
+ found.downvotes = data.post.downvotes;
+ if (data.post.my_vote !== null) {
+ found.my_vote = data.post.my_vote;
+ found.upvoteLoading = false;
+ found.downvoteLoading = false;
+ }
+ this.setState(this.state);
}
-
- this.setState(this.state);
} else if (res.op == UserOperation.AddAdmin) {
let data = res.data as AddAdminResponse;
this.state.siteRes.admins = data.admins;