api::{claims::Claims, APIError, Oper, Perform},
apub::fetcher::search_by_apub_id,
blocking,
+ version,
websocket::{server::SendAllMessage, UserOperation, WebsocketInfo},
DbPool,
LemmyError,
admins: Vec<UserView>,
banned: Vec<UserView>,
pub online: usize,
+ version: String,
}
#[derive(Serialize, Deserialize)]
admins,
banned,
online,
+ version: version::VERSION.to_string(),
})
}
}
admins,
banned,
online: 0,
+ version: version::VERSION.to_string(),
})
}
}
import { Component } from 'inferno';
import { Link } from 'inferno-router';
-import { repoUrl } from '../utils';
-import { version } from '../version';
import { i18n } from '../i18next';
+import { Subscription } from 'rxjs';
+import { retryWhen, delay, take } from 'rxjs/operators';
+import { WebSocketService } from '../services';
+import { repoUrl, wsJsonToRes } from '../utils';
+import {
+ UserOperation,
+ WebSocketJsonResponse,
+ GetSiteResponse,
+} from '../interfaces';
-export class Footer extends Component<any, any> {
+interface FooterState {
+ version: string;
+}
+
+export class Footer extends Component<any, FooterState> {
+ private wsSub: Subscription;
+ emptyState: FooterState = {
+ version: null,
+ };
constructor(props: any, context: any) {
super(props, context);
+
+ this.state = this.emptyState;
+
+ this.wsSub = WebSocketService.Instance.subject
+ .pipe(retryWhen(errors => errors.pipe(delay(3000), take(10))))
+ .subscribe(
+ msg => this.parseMessage(msg),
+ err => console.error(err),
+ () => console.log('complete')
+ );
+ }
+
+ componentWillUnmount() {
+ this.wsSub.unsubscribe();
}
render() {
<div className="navbar-collapse">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
- <span class="navbar-text">{version}</span>
+ <span class="navbar-text">{this.state.version}</span>
</li>
<li class="nav-item">
<Link class="nav-link" to="/modlog">
</nav>
);
}
+ parseMessage(msg: WebSocketJsonResponse) {
+ let res = wsJsonToRes(msg);
+
+ if (res.op == UserOperation.GetSite) {
+ let data = res.data as GetSiteResponse;
+ this.setState({ version: data.version });
+ }
+ }
}
messageToastify,
md,
} from '../utils';
-import { version } from '../version';
import { i18n } from '../i18next';
interface NavbarState {
messages: Array<PrivateMessage>;
unreadCount: number;
siteName: string;
+ version: string;
admins: Array<UserView>;
searchParam: string;
toggleSearch: boolean;
messages: [],
expanded: false,
siteName: undefined,
+ version: undefined,
admins: [],
searchParam: '',
toggleSearch: false,
navbar() {
return (
<nav class="container-fluid navbar navbar-expand-md navbar-light shadow p-0 px-3">
- <Link title={version} class="navbar-brand" to="/">
+ <Link title={this.state.version} class="navbar-brand" to="/">
{this.state.siteName}
</Link>
{this.state.isLoggedIn && (
if (data.site && !this.state.siteName) {
this.state.siteName = data.site.name;
+ this.state.version = data.version;
this.state.admins = data.admins;
this.setState(this.state);
}