From: Dessalines Date: Thu, 4 Apr 2019 20:00:19 +0000 (-0700) Subject: Adding forum / community page X-Git-Url: http://these/git/%22https:/join-lemmy.org/static/git-favicon.png?a=commitdiff_plain;h=d07a1b4563b829232040c9b1156a6598f493f469;p=lemmy.git Adding forum / community page - Adding the page. Fixes #17. - Adding number of comments for community. - Add sorting to that table. --- diff --git a/server/migrations/2019-04-03-155205_create_community_view/up.sql b/server/migrations/2019-04-03-155205_create_community_view/up.sql index 74972507..d26a313e 100644 --- a/server/migrations/2019-04-03-155205_create_community_view/up.sql +++ b/server/migrations/2019-04-03-155205_create_community_view/up.sql @@ -3,7 +3,8 @@ select *, (select name from user_ u where c.creator_id = u.id) as creator_name, (select name from category ct where c.category_id = ct.id) as category_name, (select count(*) from community_follower cf where cf.community_id = c.id) as number_of_subscribers, -(select count(*) from post p where p.community_id = c.id) as number_of_posts +(select count(*) from post p where p.community_id = c.id) as number_of_posts, +(select count(*) from comment co, post p where c.id = p.community_id and p.id = co.post_id) as number_of_comments from community c; create view community_moderator_view as diff --git a/server/src/actions/community_view.rs b/server/src/actions/community_view.rs index 9da6215d..03d822ab 100644 --- a/server/src/actions/community_view.rs +++ b/server/src/actions/community_view.rs @@ -17,6 +17,7 @@ table! { category_name -> Varchar, number_of_subscribers -> BigInt, number_of_posts -> BigInt, + number_of_comments -> BigInt, } } @@ -34,7 +35,8 @@ pub struct CommunityView { pub creator_name: String, pub category_name: String, pub number_of_subscribers: i64, - pub number_of_posts: i64 + pub number_of_posts: i64, + pub number_of_comments: i64 } impl CommunityView { diff --git a/ui/src/components/communities.tsx b/ui/src/components/communities.tsx new file mode 100644 index 00000000..411aebe1 --- /dev/null +++ b/ui/src/components/communities.tsx @@ -0,0 +1,80 @@ +import { Component, linkEvent } from 'inferno'; +import { Link } from 'inferno-router'; +import { Subscription } from "rxjs"; +import { retryWhen, delay, take } from 'rxjs/operators'; +import { UserOperation, Community, Post as PostI, GetPostResponse, PostResponse, Comment, CommentForm as CommentFormI, CommentResponse, CommentLikeForm, CommentSortType, CreatePostLikeResponse, ListCommunitiesResponse } from '../interfaces'; +import { WebSocketService, UserService } from '../services'; +import { msgOp, hotRank,mdToHtml } from '../utils'; + +interface CommunitiesState { + communities: Array; +} + +export class Communities extends Component { + private subscription: Subscription; + private emptyState: CommunitiesState = { + communities: [] + } + + constructor(props, context) { + super(props, context); + this.state = this.emptyState; + this.subscription = WebSocketService.Instance.subject + .pipe(retryWhen(errors => errors.pipe(delay(3000), take(10)))) + .subscribe( + (msg) => this.parseMessage(msg), + (err) => console.error(err), + () => console.log('complete') + ); + WebSocketService.Instance.listCommunities(); + } + + render() { + return ( +
+
+ + + + + + + + + + + + + {this.state.communities.map(community => + + + + + + + + + )} + +
NameTitleCategorySubscribersPostsComments
{community.name}{community.title}{community.category_name}{community.number_of_subscribers}{community.number_of_posts}{community.number_of_comments}
+
+
+ ); + } + + + + parseMessage(msg: any) { + console.log(msg); + let op: UserOperation = msgOp(msg); + if (msg.error) { + alert(msg.error); + return; + } else if (op == UserOperation.ListCommunities) { + let res: ListCommunitiesResponse = msg; + this.state.communities = res.communities; + this.state.communities.sort((a, b) => b.number_of_subscribers - a.number_of_subscribers); + this.setState(this.state); + } + } +} diff --git a/ui/src/components/create-community.tsx b/ui/src/components/create-community.tsx index c5149f0a..e21db8ac 100644 --- a/ui/src/components/create-community.tsx +++ b/ui/src/components/create-community.tsx @@ -64,7 +64,7 @@ export class CreateCommunity extends Component {
- +
diff --git a/ui/src/components/navbar.tsx b/ui/src/components/navbar.tsx index 1af592b4..44424994 100644 --- a/ui/src/components/navbar.tsx +++ b/ui/src/components/navbar.tsx @@ -37,7 +37,7 @@ export class Navbar extends Component { About