import { Component, linkEvent } from 'inferno'; import { Subscription } from 'rxjs'; import { retryWhen, delay, take } from 'rxjs/operators'; import { UserOperation, SiteResponse, GetSiteResponse, SiteConfigForm, GetSiteConfigResponse, WebSocketJsonResponse, } from '../interfaces'; import { WebSocketService } from '../services'; import { wsJsonToRes, capitalizeFirstLetter, toast, randomStr } from '../utils'; import autosize from 'autosize'; import { SiteForm } from './site-form'; import { UserListing } from './user-listing'; import { i18n } from '../i18next'; interface AdminSettingsState { siteRes: GetSiteResponse; siteConfigRes: GetSiteConfigResponse; siteConfigForm: SiteConfigForm; loading: boolean; siteConfigLoading: boolean; } export class AdminSettings extends Component { private siteConfigTextAreaId = `site-config-${randomStr()}`; private subscription: Subscription; private emptyState: AdminSettingsState = { siteRes: { site: { id: null, name: null, creator_id: null, creator_name: null, published: null, number_of_users: null, number_of_posts: null, number_of_comments: null, number_of_communities: null, enable_downvotes: null, open_registration: null, enable_nsfw: null, }, admins: [], banned: [], online: null, version: null, }, siteConfigForm: { config_hjson: null, auth: null, }, siteConfigRes: { config_hjson: null, }, loading: true, siteConfigLoading: null, }; 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(); WebSocketService.Instance.getSiteConfig(); } componentWillUnmount() { this.subscription.unsubscribe(); } render() { return (
{this.state.loading ? (
) : (
{this.admins()} {this.bannedUsers()}
{this.adminSettings()}
)}
); } admins() { return ( <>
{capitalizeFirstLetter(i18n.t('admins'))}
); } bannedUsers() { return ( <>
{i18n.t('banned_users')}
); } adminSettings() { return (
{i18n.t('admin_settings')}