Adding version to GetSite. Fixes #1001 (#1002)

* Adding version to GetSite. Fixes #1001

* Removing version.ts file
pull/1013/head
Dessalines 2020-07-21 09:20:23 -04:00 committed by GitHub
parent f93f2fe03c
commit 55ce7b1339
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 55 additions and 9 deletions

View File

@ -12,8 +12,6 @@ third_semver=$(echo $new_tag | cut -d "." -f 3)
# Setting the version on the front end # Setting the version on the front end
cd ../../ cd ../../
echo "export const version: string = '$new_tag';" > "ui/src/version.ts"
git add "ui/src/version.ts"
# Setting the version on the backend # Setting the version on the backend
echo "pub const VERSION: &str = \"$new_tag\";" > "server/src/version.rs" echo "pub const VERSION: &str = \"$new_tag\";" > "server/src/version.rs"
git add "server/src/version.rs" git add "server/src/version.rs"

View File

@ -754,6 +754,8 @@ Search types are `All, Comments, Posts, Communities, Users, Url`
site: Option<SiteView>, site: Option<SiteView>,
admins: Vec<UserView>, admins: Vec<UserView>,
banned: Vec<UserView>, banned: Vec<UserView>,
online: usize, // This is currently broken
version: String,
} }
} }
``` ```

View File

@ -3,6 +3,7 @@ use crate::{
api::{claims::Claims, APIError, Oper, Perform}, api::{claims::Claims, APIError, Oper, Perform},
apub::fetcher::search_by_apub_id, apub::fetcher::search_by_apub_id,
blocking, blocking,
version,
websocket::{server::SendAllMessage, UserOperation, WebsocketInfo}, websocket::{server::SendAllMessage, UserOperation, WebsocketInfo},
DbPool, DbPool,
LemmyError, LemmyError,
@ -110,6 +111,7 @@ pub struct GetSiteResponse {
admins: Vec<UserView>, admins: Vec<UserView>,
banned: Vec<UserView>, banned: Vec<UserView>,
pub online: usize, pub online: usize,
version: String,
} }
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
@ -424,6 +426,7 @@ impl Perform for Oper<GetSite> {
admins, admins,
banned, banned,
online, online,
version: version::VERSION.to_string(),
}) })
} }
} }
@ -666,6 +669,7 @@ impl Perform for Oper<TransferSite> {
admins, admins,
banned, banned,
online: 0, online: 0,
version: version::VERSION.to_string(),
}) })
} }
} }

View File

@ -46,6 +46,7 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
admins: [], admins: [],
banned: [], banned: [],
online: null, online: null,
version: null,
}, },
siteConfigForm: { siteConfigForm: {
config_hjson: null, config_hjson: null,

View File

@ -1,12 +1,41 @@
import { Component } from 'inferno'; import { Component } from 'inferno';
import { Link } from 'inferno-router'; import { Link } from 'inferno-router';
import { repoUrl } from '../utils';
import { version } from '../version';
import { i18n } from '../i18next'; 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) { constructor(props: any, context: any) {
super(props, context); 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() { render() {
@ -15,7 +44,7 @@ export class Footer extends Component<any, any> {
<div className="navbar-collapse"> <div className="navbar-collapse">
<ul class="navbar-nav ml-auto"> <ul class="navbar-nav ml-auto">
<li class="nav-item"> <li class="nav-item">
<span class="navbar-text">{version}</span> <span class="navbar-text">{this.state.version}</span>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<Link class="nav-link" to="/modlog"> <Link class="nav-link" to="/modlog">
@ -42,4 +71,12 @@ export class Footer extends Component<any, any> {
</nav> </nav>
); );
} }
parseMessage(msg: WebSocketJsonResponse) {
let res = wsJsonToRes(msg);
if (res.op == UserOperation.GetSite) {
let data = res.data as GetSiteResponse;
this.setState({ version: data.version });
}
}
} }

View File

@ -107,6 +107,7 @@ export class Main extends Component<any, MainState> {
admins: [], admins: [],
banned: [], banned: [],
online: null, online: null,
version: null,
}, },
showEditSite: false, showEditSite: false,
loading: true, loading: true,

View File

@ -30,7 +30,6 @@ import {
messageToastify, messageToastify,
md, md,
} from '../utils'; } from '../utils';
import { version } from '../version';
import { i18n } from '../i18next'; import { i18n } from '../i18next';
interface NavbarState { interface NavbarState {
@ -41,6 +40,7 @@ interface NavbarState {
messages: Array<PrivateMessage>; messages: Array<PrivateMessage>;
unreadCount: number; unreadCount: number;
siteName: string; siteName: string;
version: string;
admins: Array<UserView>; admins: Array<UserView>;
searchParam: string; searchParam: string;
toggleSearch: boolean; toggleSearch: boolean;
@ -58,6 +58,7 @@ export class Navbar extends Component<any, NavbarState> {
messages: [], messages: [],
expanded: false, expanded: false,
siteName: undefined, siteName: undefined,
version: undefined,
admins: [], admins: [],
searchParam: '', searchParam: '',
toggleSearch: false, toggleSearch: false,
@ -150,7 +151,7 @@ export class Navbar extends Component<any, NavbarState> {
navbar() { navbar() {
return ( return (
<nav class="container-fluid navbar navbar-expand-md navbar-light shadow p-0 px-3"> <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} {this.state.siteName}
</Link> </Link>
{this.state.isLoggedIn && ( {this.state.isLoggedIn && (
@ -395,6 +396,7 @@ export class Navbar extends Component<any, NavbarState> {
if (data.site && !this.state.siteName) { if (data.site && !this.state.siteName) {
this.state.siteName = data.site.name; this.state.siteName = data.site.name;
this.state.version = data.version;
this.state.admins = data.admins; this.state.admins = data.admins;
this.setState(this.state); this.setState(this.state);
} }

View File

@ -92,6 +92,7 @@ export class Post extends Component<any, PostState> {
enable_nsfw: undefined, enable_nsfw: undefined,
}, },
online: null, online: null,
version: null,
}, },
}; };

View File

@ -758,6 +758,7 @@ export interface GetSiteResponse {
admins: Array<UserView>; admins: Array<UserView>;
banned: Array<UserView>; banned: Array<UserView>;
online: number; online: number;
version: string;
} }
export interface SiteResponse { export interface SiteResponse {

1
ui/src/version.ts vendored
View File

@ -1 +0,0 @@
export const version: string = 'v0.7.25';