summaryrefslogtreecommitdiffstats
path: root/ui/src/components/inbox.tsx
diff options
context:
space:
mode:
authorDessalines <tyhou13@gmx.com>2020-01-18 23:54:10 -0500
committerDessalines <tyhou13@gmx.com>2020-01-18 23:54:10 -0500
commita044718066623f19d51196d444bd199c1231cebe (patch)
treecbffb18d826df1330ce2b7f1a814205ba45148d1 /ui/src/components/inbox.tsx
parent05ee5a8b600fdd7a64ad66bb52978befed3a7614 (diff)
First pass at fixing UI to work with new websocketresponses.
Diffstat (limited to 'ui/src/components/inbox.tsx')
-rw-r--r--ui/src/components/inbox.tsx106
1 files changed, 53 insertions, 53 deletions
diff --git a/ui/src/components/inbox.tsx b/ui/src/components/inbox.tsx
index a302b834..a46017e2 100644
--- a/ui/src/components/inbox.tsx
+++ b/ui/src/components/inbox.tsx
@@ -14,7 +14,7 @@ import {
CommentResponse,
} from '../interfaces';
import { WebSocketService, UserService } from '../services';
-import { msgOp, fetchLimit } from '../utils';
+import { wsJsonToRes, fetchLimit } from '../utils';
import { CommentNodes } from './comment-nodes';
import { SortSelect } from './sort-select';
import { i18n } from '../i18next';
@@ -298,92 +298,92 @@ export class Inbox extends Component<any, InboxState> {
parseMessage(msg: any) {
console.log(msg);
- let op: UserOperation = msgOp(msg);
- if (msg.error) {
- alert(i18n.t(msg.error));
+ let res = wsJsonToRes(msg);
+ if (res.error) {
+ alert(i18n.t(res.error));
return;
- } else if (op == UserOperation.GetReplies) {
- let res: GetRepliesResponse = msg;
- this.state.replies = res.replies;
+ } else if (res.op == UserOperation.GetReplies) {
+ let data = res.data as GetRepliesResponse;
+ this.state.replies = data.replies;
this.sendUnreadCount();
window.scrollTo(0, 0);
this.setState(this.state);
- } else if (op == UserOperation.GetUserMentions) {
- let res: GetUserMentionsResponse = msg;
- this.state.mentions = res.mentions;
+ } else if (res.op == UserOperation.GetUserMentions) {
+ let data = res.data as GetUserMentionsResponse;
+ this.state.mentions = data.mentions;
this.sendUnreadCount();
window.scrollTo(0, 0);
this.setState(this.state);
- } else if (op == UserOperation.MarkAllAsRead) {
+ } else if (res.op == UserOperation.MarkAllAsRead) {
this.state.replies = [];
this.state.mentions = [];
window.scrollTo(0, 0);
this.setState(this.state);
- } else if (op == UserOperation.EditComment) {
- let res: CommentResponse = msg;
-
- let found = this.state.replies.find(c => c.id == res.comment.id);
- found.content = res.comment.content;
- found.updated = res.comment.updated;
- found.removed = res.comment.removed;
- found.deleted = res.comment.deleted;
- found.upvotes = res.comment.upvotes;
- found.downvotes = res.comment.downvotes;
- found.score = res.comment.score;
+ } else if (res.op == UserOperation.EditComment) {
+ let data = res.data as CommentResponse;
+
+ let found = this.state.replies.find(c => c.id == data.comment.id);
+ found.content = data.comment.content;
+ found.updated = data.comment.updated;
+ found.removed = data.comment.removed;
+ found.deleted = data.comment.deleted;
+ found.upvotes = data.comment.upvotes;
+ found.downvotes = data.comment.downvotes;
+ found.score = data.comment.score;
// If youre in the unread view, just remove it from the list
- if (this.state.unreadOrAll == UnreadOrAll.Unread && res.comment.read) {
+ if (this.state.unreadOrAll == UnreadOrAll.Unread && data.comment.read) {
this.state.replies = this.state.replies.filter(
- r => r.id !== res.comment.id
+ r => r.id !== data.comment.id
);
} else {
- let found = this.state.replies.find(c => c.id == res.comment.id);
- found.read = res.comment.read;
+ let found = this.state.replies.find(c => c.id == data.comment.id);
+ found.read = data.comment.read;
}
this.sendUnreadCount();
this.setState(this.state);
- } else if (op == UserOperation.EditUserMention) {
- let res: UserMentionResponse = msg;
-
- let found = this.state.mentions.find(c => c.id == res.mention.id);
- found.content = res.mention.content;
- found.updated = res.mention.updated;
- found.removed = res.mention.removed;
- found.deleted = res.mention.deleted;
- found.upvotes = res.mention.upvotes;
- found.downvotes = res.mention.downvotes;
- found.score = res.mention.score;
+ } else if (res.op == UserOperation.EditUserMention) {
+ let data = res.data as UserMentionResponse;
+
+ let found = this.state.mentions.find(c => c.id == data.mention.id);
+ found.content = data.mention.content;
+ found.updated = data.mention.updated;
+ found.removed = data.mention.removed;
+ found.deleted = data.mention.deleted;
+ found.upvotes = data.mention.upvotes;
+ found.downvotes = data.mention.downvotes;
+ found.score = data.mention.score;
// If youre in the unread view, just remove it from the list
- if (this.state.unreadOrAll == UnreadOrAll.Unread && res.mention.read) {
+ if (this.state.unreadOrAll == UnreadOrAll.Unread && data.mention.read) {
this.state.mentions = this.state.mentions.filter(
- r => r.id !== res.mention.id
+ r => r.id !== data.mention.id
);
} else {
- let found = this.state.mentions.find(c => c.id == res.mention.id);
- found.read = res.mention.read;
+ let found = this.state.mentions.find(c => c.id == data.mention.id);
+ found.read = data.mention.read;
}
this.sendUnreadCount();
this.setState(this.state);
- } else if (op == UserOperation.CreateComment) {
+ } else if (res.op == UserOperation.CreateComment) {
// let res: CommentResponse = msg;
alert(i18n.t('reply_sent'));
// this.state.replies.unshift(res.comment); // TODO do this right
// this.setState(this.state);
- } else if (op == UserOperation.SaveComment) {
- let res: CommentResponse = msg;
- let found = this.state.replies.find(c => c.id == res.comment.id);
- found.saved = res.comment.saved;
+ } else if (res.op == UserOperation.SaveComment) {
+ let data = res.data as CommentResponse;
+ let found = this.state.replies.find(c => c.id == data.comment.id);
+ found.saved = data.comment.saved;
this.setState(this.state);
- } else if (op == UserOperation.CreateCommentLike) {
- let res: CommentResponse = msg;
+ } else if (res.op == UserOperation.CreateCommentLike) {
+ let data = res.data as CommentResponse;
let found: Comment = this.state.replies.find(
- c => c.id === res.comment.id
+ c => c.id === data.comment.id
);
- found.score = res.comment.score;
- found.upvotes = res.comment.upvotes;
- found.downvotes = res.comment.downvotes;
- if (res.comment.my_vote !== null) found.my_vote = res.comment.my_vote;
+ found.score = data.comment.score;
+ found.upvotes = data.comment.upvotes;
+ found.downvotes = data.comment.downvotes;
+ if (data.comment.my_vote !== null) found.my_vote = data.comment.my_vote;
this.setState(this.state);
}
}