From 55ce7b1339a73b8c309dce2fa7c57a6c2d81b301 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 21 Jul 2020 09:20:23 -0400 Subject: [PATCH] Adding version to GetSite. Fixes #1001 (#1002) * Adding version to GetSite. Fixes #1001 * Removing version.ts file --- docker/prod/deploy.sh | 2 - docs/src/contributing_websocket_http_api.md | 2 + server/src/api/site.rs | 4 ++ ui/src/components/admin-settings.tsx | 1 + ui/src/components/footer.tsx | 45 +++++++++++++++++++-- ui/src/components/main.tsx | 1 + ui/src/components/navbar.tsx | 6 ++- ui/src/components/post.tsx | 1 + ui/src/interfaces.ts | 1 + ui/src/version.ts | 1 - 10 files changed, 55 insertions(+), 9 deletions(-) delete mode 100644 ui/src/version.ts diff --git a/docker/prod/deploy.sh b/docker/prod/deploy.sh index 3b7ee1740..2e8728180 100755 --- a/docker/prod/deploy.sh +++ b/docker/prod/deploy.sh @@ -12,8 +12,6 @@ third_semver=$(echo $new_tag | cut -d "." -f 3) # Setting the version on the front end cd ../../ -echo "export const version: string = '$new_tag';" > "ui/src/version.ts" -git add "ui/src/version.ts" # Setting the version on the backend echo "pub const VERSION: &str = \"$new_tag\";" > "server/src/version.rs" git add "server/src/version.rs" diff --git a/docs/src/contributing_websocket_http_api.md b/docs/src/contributing_websocket_http_api.md index 5af89431a..7aab35782 100644 --- a/docs/src/contributing_websocket_http_api.md +++ b/docs/src/contributing_websocket_http_api.md @@ -754,6 +754,8 @@ Search types are `All, Comments, Posts, Communities, Users, Url` site: Option, admins: Vec, banned: Vec, + online: usize, // This is currently broken + version: String, } } ``` diff --git a/server/src/api/site.rs b/server/src/api/site.rs index 241a80e31..a945d9ec0 100644 --- a/server/src/api/site.rs +++ b/server/src/api/site.rs @@ -3,6 +3,7 @@ use crate::{ api::{claims::Claims, APIError, Oper, Perform}, apub::fetcher::search_by_apub_id, blocking, + version, websocket::{server::SendAllMessage, UserOperation, WebsocketInfo}, DbPool, LemmyError, @@ -110,6 +111,7 @@ pub struct GetSiteResponse { admins: Vec, banned: Vec, pub online: usize, + version: String, } #[derive(Serialize, Deserialize)] @@ -424,6 +426,7 @@ impl Perform for Oper { admins, banned, online, + version: version::VERSION.to_string(), }) } } @@ -666,6 +669,7 @@ impl Perform for Oper { admins, banned, online: 0, + version: version::VERSION.to_string(), }) } } diff --git a/ui/src/components/admin-settings.tsx b/ui/src/components/admin-settings.tsx index 0034c229e..6fe4e9347 100644 --- a/ui/src/components/admin-settings.tsx +++ b/ui/src/components/admin-settings.tsx @@ -46,6 +46,7 @@ export class AdminSettings extends Component { admins: [], banned: [], online: null, + version: null, }, siteConfigForm: { config_hjson: null, diff --git a/ui/src/components/footer.tsx b/ui/src/components/footer.tsx index cadb6aa39..e911370fa 100644 --- a/ui/src/components/footer.tsx +++ b/ui/src/components/footer.tsx @@ -1,12 +1,41 @@ 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 { +interface FooterState { + version: string; +} + +export class Footer extends Component { + 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() { @@ -15,7 +44,7 @@ export class Footer extends Component {