diff options
author | Dessalines <tyhou13@gmx.com> | 2020-07-08 01:02:14 -0400 |
---|---|---|
committer | Dessalines <tyhou13@gmx.com> | 2020-07-08 01:02:14 -0400 |
commit | cd4e0ab3c2cfd615e4771fb9181a31ce237b5ceb (patch) | |
tree | 699dd63cd3ad7601e49a1173884506e3638ae37a /ui/src/components/sponsors.tsx | |
parent | 8fda7d00d5ec9e415b44aa10cff3c4d735563a20 (diff) |
HTML title bugs.
- Fixing HTML titles for some pages. Fixes #801
- Removing WebSocketService.Instance.site, fetching site on demand now.
Diffstat (limited to 'ui/src/components/sponsors.tsx')
-rw-r--r-- | ui/src/components/sponsors.tsx | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/ui/src/components/sponsors.tsx b/ui/src/components/sponsors.tsx index d0f163e5..6ff9b2ca 100644 --- a/ui/src/components/sponsors.tsx +++ b/ui/src/components/sponsors.tsx @@ -1,8 +1,15 @@ import { Component } from 'inferno'; +import { Subscription } from 'rxjs'; +import { retryWhen, delay, take } from 'rxjs/operators'; import { WebSocketService } from '../services'; +import { + GetSiteResponse, + WebSocketJsonResponse, + UserOperation, +} from '../interfaces'; import { i18n } from '../i18next'; import { T } from 'inferno-i18next'; -import { repoUrl } from '../utils'; +import { repoUrl, wsJsonToRes, toast } from '../utils'; interface SilverUser { name: string; @@ -33,17 +40,28 @@ let silver: Array<SilverUser> = [ // let latinum = []; export class Sponsors extends Component<any, any> { + private subscription: Subscription; constructor(props: any, context: any) { super(props, context); + this.subscription = WebSocketService.Instance.subject + .pipe(retryWhen(errors => errors.pipe(delay(3000), take(10)))) + .subscribe( + msg => this.parseMessage(msg), + err => console.error(err), + () => console.log('complete') + ); + + WebSocketService.Instance.getSite(); } componentDidMount() { - document.title = `${i18n.t('sponsors')} - ${ - WebSocketService.Instance.site.name - }`; window.scrollTo(0, 0); } + componentWillUnmount() { + this.subscription.unsubscribe(); + } + render() { return ( <div class="container text-center"> @@ -153,4 +171,16 @@ export class Sponsors extends Component<any, any> { </div> ); } + + parseMessage(msg: WebSocketJsonResponse) { + console.log(msg); + let res = wsJsonToRes(msg); + if (msg.error) { + toast(i18n.t(msg.error), 'danger'); + return; + } else if (res.op == UserOperation.GetSite) { + let data = res.data as GetSiteResponse; + document.title = `${i18n.t('sponsors')} - ${data.site.name}`; + } + } } |