diff options
author | Dessalines <tyhou13@gmx.com> | 2020-01-23 19:17:42 -0500 |
---|---|---|
committer | Dessalines <tyhou13@gmx.com> | 2020-01-23 19:17:42 -0500 |
commit | ac1d5f2b86b0816cc9b5794dc6c38a38365ed839 (patch) | |
tree | bedaab04ca797113990e5702cad36f5e34e9e6e8 /ui/src/components/main.tsx | |
parent | 39d1fb4450cb418d9c11b31ea99484c2a177fab6 (diff) | |
parent | b45c83682c187737b092080e83ba741c39cfa695 (diff) |
Done merging http-api and private_message
Diffstat (limited to 'ui/src/components/main.tsx')
-rw-r--r-- | ui/src/components/main.tsx | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/ui/src/components/main.tsx b/ui/src/components/main.tsx index b244ce66..9f16edb5 100644 --- a/ui/src/components/main.tsx +++ b/ui/src/components/main.tsx @@ -17,6 +17,7 @@ import { CreatePostLikeResponse, Post, GetPostsForm, + WebSocketJsonResponse, } from '../interfaces'; import { WebSocketService, UserService } from '../services'; import { PostListings } from './post-listings'; @@ -24,7 +25,7 @@ import { SortSelect } from './sort-select'; import { ListingTypeSelect } from './listing-type-select'; import { SiteForm } from './site-form'; import { - msgOp, + wsJsonToRes, repoUrl, mdToHtml, fetchLimit, @@ -57,7 +58,6 @@ export class Main extends Component<any, MainState> { subscribedCommunities: [], trendingCommunities: [], site: { - op: null, site: { id: null, name: null, @@ -563,50 +563,50 @@ export class Main extends Component<any, MainState> { WebSocketService.Instance.getPosts(getPostsForm); } - parseMessage(msg: any) { + parseMessage(msg: WebSocketJsonResponse) { console.log(msg); - let op: UserOperation = msgOp(msg); - if (msg.error) { + let res = wsJsonToRes(msg); + if (res.error) { toast(i18n.t(msg.error), 'danger'); return; - } else if (op == UserOperation.GetFollowedCommunities) { - let res: GetFollowedCommunitiesResponse = msg; - this.state.subscribedCommunities = res.communities; + } else if (res.op == UserOperation.GetFollowedCommunities) { + let data = res.data as GetFollowedCommunitiesResponse; + this.state.subscribedCommunities = data.communities; this.setState(this.state); - } else if (op == UserOperation.ListCommunities) { - let res: ListCommunitiesResponse = msg; - this.state.trendingCommunities = res.communities; + } else if (res.op == UserOperation.ListCommunities) { + let data = res.data as ListCommunitiesResponse; + this.state.trendingCommunities = data.communities; this.setState(this.state); - } else if (op == UserOperation.GetSite) { - let res: GetSiteResponse = msg; + } else if (res.op == UserOperation.GetSite) { + let data = res.data as GetSiteResponse; // This means it hasn't been set up yet - if (!res.site) { + if (!data.site) { this.context.router.history.push('/setup'); } - this.state.site.admins = res.admins; - this.state.site.site = res.site; - this.state.site.banned = res.banned; - this.state.site.online = res.online; + this.state.site.admins = data.admins; + this.state.site.site = data.site; + this.state.site.banned = data.banned; + this.state.site.online = data.online; this.setState(this.state); document.title = `${WebSocketService.Instance.site.name}`; - } else if (op == UserOperation.EditSite) { - let res: SiteResponse = msg; - this.state.site.site = res.site; + } else if (res.op == UserOperation.EditSite) { + let data = res.data as SiteResponse; + this.state.site.site = data.site; this.state.showEditSite = false; this.setState(this.state); - } else if (op == UserOperation.GetPosts) { - let res: GetPostsResponse = msg; - this.state.posts = res.posts; + } else if (res.op == UserOperation.GetPosts) { + let data = res.data as GetPostsResponse; + this.state.posts = data.posts; this.state.loading = false; this.setState(this.state); - } else if (op == UserOperation.CreatePostLike) { - let res: CreatePostLikeResponse = msg; - let found = this.state.posts.find(c => c.id == res.post.id); - found.my_vote = res.post.my_vote; - found.score = res.post.score; - found.upvotes = res.post.upvotes; - found.downvotes = res.post.downvotes; + } else if (res.op == UserOperation.CreatePostLike) { + let data = res.data as CreatePostLikeResponse; + let found = this.state.posts.find(c => c.id == data.post.id); + found.my_vote = data.post.my_vote; + found.score = data.post.score; + found.upvotes = data.post.upvotes; + found.downvotes = data.post.downvotes; this.setState(this.state); } } |