]> Untitled Git - lemmy.git/commitdiff
Showing community count on main sidebar
authorDessalines <tyhou13@gmx.com>
Thu, 29 Aug 2019 04:28:06 +0000 (21:28 -0700)
committerDessalines <tyhou13@gmx.com>
Thu, 29 Aug 2019 04:28:06 +0000 (21:28 -0700)
- Fixes #232

server/migrations/2019-08-29-040006_add_community_count/down.sql [new file with mode: 0644]
server/migrations/2019-08-29-040006_add_community_count/up.sql [new file with mode: 0644]
server/src/db/community_view.rs
ui/src/components/main.tsx
ui/src/interfaces.ts
ui/src/translations/en.ts

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 (file)
index 0000000..6302f26
--- /dev/null
@@ -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 (file)
index 0000000..0ec1c9c
--- /dev/null
@@ -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;
index 88ab10afe6ce0bc1493c7202d32b876dfa62ed91..a12d6bf96bc184cfe7d04e4d753adee099e31769 100644 (file)
@@ -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 {
index 0fab17f6fafe796466b7e23d4cb1e16ca5b9bec6..0a7a31e5928128cb141c2c713352966e79c637a4 100644 (file)
@@ -39,6 +39,7 @@ export class Main extends Component<any, MainState> {
         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<any, MainState> {
               <li className="list-inline-item badge badge-secondary">
                 <T i18nKey="number_of_users" interpolation={{count: this.state.site.site.number_of_users}}>#</T>
               </li>
+              <li className="list-inline-item badge badge-secondary">
+                <T i18nKey="number_of_communities" interpolation={{count: this.state.site.site.number_of_communities}}>#</T>
+              </li>
               <li className="list-inline-item badge badge-secondary">
                 <T i18nKey="number_of_posts" interpolation={{count: this.state.site.site.number_of_posts}}>#</T>
               </li>
index 251b64a0dbf52b907c9560273c4dadfba9c02a7b..c9a647d61c3e72a686bdf6a1633f9784398ef564 100644 (file)
@@ -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 {
index 85b5cab3caccb2569cc7a0dd402f98f82fa8ac9c..10c1540c67e8280d42d800fed23b02264ef93c76 100644 (file)
@@ -21,6 +21,7 @@ export const en = {
     subscribed_to_communities:'Subscribed to <1>communities</1>',
     trending_communities:'Trending <1>communities</1>',
     list_of_communities: 'List of communities',
+    number_of_communities:'{{count}} Communities',
     community_reqs: 'lowercase, underscores, and no spaces.',
     edit: 'edit',
     reply: 'reply',