From e0626925abab649c8bbb91451b743f60a270770a Mon Sep 17 00:00:00 2001 From: shilangyu Date: Sun, 31 Jan 2021 14:07:36 +0000 Subject: [PATCH] Display online counts --- CHANGELOG.md | 4 ++++ lib/pages/community.dart | 26 ++++++++++++++++++-------- lib/pages/instance.dart | 2 +- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1127699..b8ac2e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Unreleased +### Added + +- Online users count is now correctly displayed + ### Fixed - Fixed a bug where replying to a comment would instead reply to the parent of that comment diff --git a/lib/pages/community.dart b/lib/pages/community.dart index 8bbd105..b615e6e 100644 --- a/lib/pages/community.dart +++ b/lib/pages/community.dart @@ -167,8 +167,11 @@ class CommunityPage extends HookWidget { IconButton(icon: Icon(moreIcon), onPressed: _openMoreMenu), ], flexibleSpace: FlexibleSpaceBar( - background: - _CommunityOverview(community, instanceHost: instanceHost), + background: _CommunityOverview( + community: community, + instanceHost: instanceHost, + onlineUsers: fullCommunitySnap.data?.online, + ), ), ), SliverPersistentHeader( @@ -213,6 +216,7 @@ class CommunityPage extends HookWidget { _AboutTab( community: community, moderators: fullCommunitySnap.data?.moderators, + onlineUsers: fullCommunitySnap.data?.online, ), ], ), @@ -225,10 +229,12 @@ class CommunityPage extends HookWidget { class _CommunityOverview extends StatelessWidget { final CommunityView community; final String instanceHost; + final int onlineUsers; - const _CommunityOverview( - this.community, { + const _CommunityOverview({ + @required this.community, @required this.instanceHost, + @required this.onlineUsers, }) : assert(instanceHost != null), assert(goToInstance != null); @@ -354,7 +360,9 @@ class _CommunityOverview extends StatelessWidget { padding: EdgeInsets.only(right: 3), child: Icon(Icons.record_voice_over, size: 20), ), - const Text('xx'), // TODO: display online users + Text(onlineUsers == null + ? 'xx' + : compactNumber(onlineUsers)), const Spacer(), ], ), @@ -394,11 +402,13 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate { class _AboutTab extends StatelessWidget { final CommunityView community; final List moderators; + final int onlineUsers; const _AboutTab({ Key key, @required this.community, @required this.moderators, + @required this.onlineUsers, }) : super(key: key); void goToModlog() { @@ -430,9 +440,9 @@ class _AboutTab extends StatelessWidget { scrollDirection: Axis.horizontal, children: [ // TODO: consider using Chips - const Padding( - padding: EdgeInsets.only(left: 7), - child: _Badge('X users online'), + Padding( + padding: const EdgeInsets.only(left: 7), + child: _Badge('${onlineUsers ?? 'X'} users online'), ), _Badge( '''${community.counts.subscribers} subscriber${pluralS(community.counts.subscribers)}'''), diff --git a/lib/pages/instance.dart b/lib/pages/instance.dart index c486db2..86a25a7 100644 --- a/lib/pages/instance.dart +++ b/lib/pages/instance.dart @@ -301,7 +301,7 @@ class _AboutTab extends HookWidget { scrollDirection: Axis.horizontal, children: [ const SizedBox(width: 7), - const _Badge('X users online'), + _Badge('${site.online} users online'), _Badge('${site.siteView.counts.users} users'), _Badge('${site.siteView.counts.communities} communities'), _Badge('${site.siteView.counts.posts} posts'),