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 0b75d46453
commit 909628bc34
5 changed files with 13 additions and 1 deletions

View file

@ -81,6 +81,7 @@ pub struct GetSiteResponse {
site: Option<SiteView>,
admins: Vec<UserView>,
banned: Vec<UserView>,
pub online: usize,
}
#[derive(Serialize, Deserialize)]
@ -296,6 +297,7 @@ impl Perform<GetSiteResponse> for Oper<GetSite> {
site: site_view,
admins: admins,
banned: banned,
online: 0
})
}
}
@ -486,6 +488,7 @@ impl Perform<GetSiteResponse> for Oper<TransferSite> {
site: Some(site_view),
admins: admins,
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)?)
}
UserOperation::GetSite => {
let online: usize = chat.sessions.len();
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)?)
}
UserOperation::Search => {

View file

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

View file

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

View file

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