import { Component } from 'inferno';
+import { Helmet } from 'inferno-helmet';
+import { Subscription } from 'rxjs';
+import { retryWhen, delay, take } from 'rxjs/operators';
import { WebSocketService } from '../services';
+import {
+ GetSiteResponse,
+ Site,
+ WebSocketJsonResponse,
+ UserOperation,
+} from 'lemmy-js-client';
import { i18n } from '../i18next';
import { T } from 'inferno-i18next';
-import { repoUrl } from '../utils';
+import { repoUrl, wsJsonToRes, toast } from '../utils';
interface SilverUser {
name: string;
}
let general = [
+ 'Brendan',
+ 'mexicanhalloween',
+ 'William Moore',
+ 'Rachel Schmitz',
+ 'comradeda',
+ 'ybaumy',
+ 'dude in phx',
'twilight loki',
'Andrew Plaza',
'Jonathan Cremin',
'Andre Vallestero',
'NotTooHighToHack',
];
-let highlighted = ['DiscountFuneral', 'Oskenso Kashi', 'Alex Benishek'];
+let highlighted = ['DQW', 'DiscountFuneral', 'Oskenso Kashi', 'Alex Benishek'];
let silver: Array<SilverUser> = [
{
name: 'Redjoker',
// let gold = [];
// let latinum = [];
-export class Sponsors extends Component<any, any> {
+interface SponsorsState {
+ site: Site;
+}
+
+export class Sponsors extends Component<any, SponsorsState> {
+ private subscription: Subscription;
+ private emptyState: SponsorsState = {
+ site: undefined,
+ };
constructor(props: any, context: any) {
super(props, context);
+ this.state = this.emptyState;
+ 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();
+ }
+
+ get documentTitle(): string {
+ if (this.state.site) {
+ return `${i18n.t('sponsors')} - ${this.state.site.name}`;
+ } else {
+ return 'Lemmy';
+ }
+ }
+
render() {
return (
<div class="container text-center">
+ <Helmet title={this.documentTitle} />
{this.topMessage()}
<hr />
{this.sponsors()}
<div class="container">
<h5>{i18n.t('sponsors')}</h5>
<p>{i18n.t('silver_sponsors')}</p>
- <div class="row card-columns">
+ <div class="row justify-content-md-center card-columns">
{silver.map(s => (
<div class="card col-12 col-md-2">
<div>
))}
</div>
<p>{i18n.t('general_sponsors')}</p>
- <div class="row card-columns">
+ <div class="row justify-content-md-center card-columns">
{highlighted.map(s => (
<div class="card bg-primary col-12 col-md-2 font-weight-bold">
<div>{s}</div>
</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;
+ this.state.site = data.site;
+ this.setState(this.state);
+ }
+ }
}