import { Component, linkEvent } from "inferno"; import { ListRegistrationApplications, ListRegistrationApplicationsResponse, RegistrationApplicationResponse, RegistrationApplicationView, SiteView, UserOperation, } from "lemmy-js-client"; import { Subscription } from "rxjs"; import { i18n } from "../../i18next"; import { InitialFetchRequest } from "../../interfaces"; import { UserService, WebSocketService } from "../../services"; import { authField, fetchLimit, isBrowser, setIsoData, setupTippy, toast, updateRegistrationApplicationRes, wsClient, wsJsonToRes, wsSubscribe, wsUserOp, } from "../../utils"; import { HtmlTags } from "../common/html-tags"; import { Spinner } from "../common/icon"; import { Paginator } from "../common/paginator"; import { RegistrationApplication } from "../common/registration-application"; enum UnreadOrAll { Unread, All, } interface RegistrationApplicationsState { applications: RegistrationApplicationView[]; page: number; site_view: SiteView; unreadOrAll: UnreadOrAll; loading: boolean; } export class RegistrationApplications extends Component< any, RegistrationApplicationsState > { private isoData = setIsoData(this.context); private subscription: Subscription; private emptyState: RegistrationApplicationsState = { unreadOrAll: UnreadOrAll.Unread, applications: [], page: 1, site_view: this.isoData.site_res.site_view, loading: true, }; constructor(props: any, context: any) { super(props, context); this.state = this.emptyState; this.handlePageChange = this.handlePageChange.bind(this); if (!UserService.Instance.myUserInfo && isBrowser()) { toast(i18n.t("not_logged_in"), "danger"); this.context.router.history.push(`/login`); } this.parseMessage = this.parseMessage.bind(this); this.subscription = wsSubscribe(this.parseMessage); // Only fetch the data if coming from another route if (this.isoData.path == this.context.router.route.match.url) { this.state.applications = this.isoData.routeData[0].registration_applications || []; // TODO test this.state.loading = false; } else { this.refetch(); } } componentDidMount() { setupTippy(); } componentWillUnmount() { if (isBrowser()) { this.subscription.unsubscribe(); } } get documentTitle(): string { return `@${ UserService.Instance.myUserInfo.local_user_view.person.name } ${i18n.t("registration_applications")} - ${ this.state.site_view.site.name }`; } render() { return (