Adding an online user count to main page.

- Fixes #274
This commit is contained in:
Dessalines 2019-09-13 09:09:01 -07:00
parent c8da0a92ec
commit e24f4a2d33
5 changed files with 13 additions and 1 deletions

View File

@ -81,6 +81,7 @@ pub struct GetSiteResponse {
site: Option<SiteView>, site: Option<SiteView>,
admins: Vec<UserView>, admins: Vec<UserView>,
banned: Vec<UserView>, banned: Vec<UserView>,
pub online: usize,
} }
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
@ -296,6 +297,7 @@ impl Perform<GetSiteResponse> for Oper<GetSite> {
site: site_view, site: site_view,
admins: admins, admins: admins,
banned: banned, banned: banned,
online: 0
}) })
} }
} }
@ -486,6 +488,7 @@ impl Perform<GetSiteResponse> for Oper<TransferSite> {
site: Some(site_view), site: Some(site_view),
admins: admins, admins: admins,
banned: banned, banned: banned,
online: 0
}) })
} }
} }

View File

@ -492,8 +492,10 @@ fn parse_json_message(chat: &mut ChatServer, msg: StandardMessage) -> Result<Str
Ok(serde_json::to_string(&res)?) Ok(serde_json::to_string(&res)?)
} }
UserOperation::GetSite => { UserOperation::GetSite => {
let online: usize = chat.sessions.len();
let get_site: GetSite = serde_json::from_str(data)?; let get_site: GetSite = serde_json::from_str(data)?;
let res = Oper::new(user_operation, get_site).perform()?; let mut res = Oper::new(user_operation, get_site).perform()?;
res.online = online;
Ok(serde_json::to_string(&res)?) Ok(serde_json::to_string(&res)?)
} }
UserOperation::Search => { UserOperation::Search => {

View File

@ -43,6 +43,7 @@ export class Main extends Component<any, MainState> {
}, },
admins: [], admins: [],
banned: [], banned: [],
online: null,
}, },
showEditSite: false, showEditSite: false,
loading: true, loading: true,
@ -215,6 +216,9 @@ export class Main extends Component<any, MainState> {
</ul> </ul>
} }
<ul class="my-2 list-inline"> <ul class="my-2 list-inline">
<li className="list-inline-item badge badge-secondary">
<T i18nKey="number_online" interpolation={{count: this.state.site.online}}>#</T>
</li>
<li className="list-inline-item badge badge-secondary"> <li className="list-inline-item badge badge-secondary">
<T i18nKey="number_of_users" interpolation={{count: this.state.site.site.number_of_users}}>#</T> <T i18nKey="number_of_users" interpolation={{count: this.state.site.site.number_of_users}}>#</T>
</li> </li>
@ -420,6 +424,7 @@ export class Main extends Component<any, MainState> {
this.state.site.admins = res.admins; this.state.site.admins = res.admins;
this.state.site.site = res.site; this.state.site.site = res.site;
this.state.site.banned = res.banned; this.state.site.banned = res.banned;
this.state.site.online = res.online;
this.setState(this.state); this.setState(this.state);
document.title = `${WebSocketService.Instance.site.name}`; document.title = `${WebSocketService.Instance.site.name}`;

View File

@ -546,6 +546,7 @@ export interface GetSiteResponse {
site: Site; site: Site;
admins: Array<UserView>; admins: Array<UserView>;
banned: Array<UserView>; banned: Array<UserView>;
online: number;
} }

View File

@ -70,6 +70,7 @@ export const en = {
number_of_users:'{{count}} Users', number_of_users:'{{count}} Users',
number_of_subscribers:'{{count}} Subscribers', number_of_subscribers:'{{count}} Subscribers',
number_of_points:'{{count}} Points', number_of_points:'{{count}} Points',
number_online:'{{count}} Users Online',
name: 'Name', name: 'Name',
title: 'Title', title: 'Title',
category: 'Category', category: 'Category',