From 1c59f06fc8f394c8a7a0e44f0c377ce7b6570aec Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 28 Aug 2019 21:28:06 -0700 Subject: [PATCH] Showing community count on main sidebar - Fixes #232 --- .../2019-08-29-040006_add_community_count/down.sql | 9 +++++++++ .../2019-08-29-040006_add_community_count/up.sql | 10 ++++++++++ server/src/db/community_view.rs | 2 ++ ui/src/components/main.tsx | 4 ++++ ui/src/interfaces.ts | 1 + ui/src/translations/en.ts | 1 + 6 files changed, 27 insertions(+) create mode 100644 server/migrations/2019-08-29-040006_add_community_count/down.sql create mode 100644 server/migrations/2019-08-29-040006_add_community_count/up.sql diff --git a/server/migrations/2019-08-29-040006_add_community_count/down.sql b/server/migrations/2019-08-29-040006_add_community_count/down.sql new file mode 100644 index 000000000..6302f2675 --- /dev/null +++ b/server/migrations/2019-08-29-040006_add_community_count/down.sql @@ -0,0 +1,9 @@ +drop view site_view; + +create view site_view as +select *, +(select name from user_ u where s.creator_id = u.id) as creator_name, +(select count(*) from user_) as number_of_users, +(select count(*) from post) as number_of_posts, +(select count(*) from comment) as number_of_comments +from site s; diff --git a/server/migrations/2019-08-29-040006_add_community_count/up.sql b/server/migrations/2019-08-29-040006_add_community_count/up.sql new file mode 100644 index 000000000..0ec1c9c33 --- /dev/null +++ b/server/migrations/2019-08-29-040006_add_community_count/up.sql @@ -0,0 +1,10 @@ +drop view site_view; + +create view site_view as +select *, +(select name from user_ u where s.creator_id = u.id) as creator_name, +(select count(*) from user_) as number_of_users, +(select count(*) from post) as number_of_posts, +(select count(*) from comment) as number_of_comments, +(select count(*) from community) as number_of_communities +from site s; diff --git a/server/src/db/community_view.rs b/server/src/db/community_view.rs index 88ab10afe..a12d6bf96 100644 --- a/server/src/db/community_view.rs +++ b/server/src/db/community_view.rs @@ -69,6 +69,7 @@ table! { number_of_users -> BigInt, number_of_posts -> BigInt, number_of_comments -> BigInt, + number_of_communities -> BigInt, } } @@ -253,6 +254,7 @@ pub struct SiteView { pub number_of_users: i64, pub number_of_posts: i64, pub number_of_comments: i64, + pub number_of_communities: i64, } impl SiteView { diff --git a/ui/src/components/main.tsx b/ui/src/components/main.tsx index 0fab17f6f..0a7a31e59 100644 --- a/ui/src/components/main.tsx +++ b/ui/src/components/main.tsx @@ -39,6 +39,7 @@ export class Main extends Component { number_of_users: null, number_of_posts: null, number_of_comments: null, + number_of_communities: null, }, admins: [], banned: [], @@ -217,6 +218,9 @@ export class Main extends Component {
  • #
  • +
  • + # +
  • #
  • diff --git a/ui/src/interfaces.ts b/ui/src/interfaces.ts index 251b64a0d..c9a647d61 100644 --- a/ui/src/interfaces.ts +++ b/ui/src/interfaces.ts @@ -135,6 +135,7 @@ export interface Site { number_of_users: number; number_of_posts: number; number_of_comments: number; + number_of_communities: number; } export interface FollowCommunityForm { diff --git a/ui/src/translations/en.ts b/ui/src/translations/en.ts index 85b5cab3c..10c1540c6 100644 --- a/ui/src/translations/en.ts +++ b/ui/src/translations/en.ts @@ -21,6 +21,7 @@ export const en = { subscribed_to_communities:'Subscribed to <1>communities', trending_communities:'Trending <1>communities', list_of_communities: 'List of communities', + number_of_communities:'{{count}} Communities', community_reqs: 'lowercase, underscores, and no spaces.', edit: 'edit', reply: 'reply',