</Switch>
<Symbols />
</div>
- <Footer />
+ <Footer site={this.props.site} />
</div>
</Provider>
</>
import { Component } from 'inferno';
import { Link } from 'inferno-router';
import { Subscription } from 'rxjs';
-import { retryWhen, delay, take } from 'rxjs/operators';
import {
CommentNode as CommentNodeI,
CommentForm as CommentFormI,
UserOperation,
CommentResponse,
} from 'lemmy-js-client';
-import { capitalizeFirstLetter, wsJsonToRes } from '../utils';
+import { capitalizeFirstLetter, wsJsonToRes, wsSubscribe } from '../utils';
import { WebSocketService, UserService } from '../services';
import { i18n } from '../i18next';
import { T } from 'inferno-i18next';
}
}
- 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')
- );
+ this.parseMessage = this.parseMessage.bind(this);
+ this.subscription = wsSubscribe(this.parseMessage);
}
componentWillUnmount() {
import { Component, linkEvent } from 'inferno';
import { Prompt } from 'inferno-router';
import { Subscription } from 'rxjs';
-import { retryWhen, delay, take } from 'rxjs/operators';
import {
CommunityForm as CommunityFormI,
UserOperation,
Community,
} from 'lemmy-js-client';
import { WebSocketService } from '../services';
-import { wsJsonToRes, capitalizeFirstLetter, toast, randomStr } from '../utils';
+import {
+ wsJsonToRes,
+ capitalizeFirstLetter,
+ toast,
+ randomStr,
+ wsSubscribe,
+} from '../utils';
import { i18n } from '../i18next';
import { MarkdownTextArea } from './markdown-textarea';
};
}
- 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')
- );
+ this.parseMessage = this.parseMessage.bind(this);
+ this.subscription = wsSubscribe(this.parseMessage);
}
componentDidUpdate() {
import { Component } from 'inferno';
import { Link } from 'inferno-router';
import { i18n } from '../i18next';
-import { Subscription } from 'rxjs';
-import { retryWhen, delay, take } from 'rxjs/operators';
-import { WebSocketService } from '../services';
-import { repoUrl, wsJsonToRes, isBrowser } from '../utils';
-import {
- UserOperation,
- WebSocketJsonResponse,
- GetSiteResponse,
-} from 'lemmy-js-client';
+import { repoUrl } from '../utils';
+import { GetSiteResponse } from 'lemmy-js-client';
-interface FooterState {
- version: string;
+interface FooterProps {
+ site: GetSiteResponse;
}
-export class Footer extends Component<any, FooterState> {
- private wsSub: Subscription;
- emptyState: FooterState = {
- version: null,
- };
+interface FooterState {}
+
+export class Footer extends Component<FooterProps, FooterState> {
constructor(props: any, context: any) {
super(props, context);
-
- this.state = this.emptyState;
-
- if (isBrowser()) {
- 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() {
<div className="navbar-collapse">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
- <span class="navbar-text">{this.state.version}</span>
+ <span class="navbar-text">{this.props.site.version}</span>
</li>
<li className="nav-item">
<Link className="nav-link" to="/modlog">
</nav>
);
}
- parseMessage(msg: WebSocketJsonResponse) {
- let res = wsJsonToRes(msg);
-
- if (res.op == UserOperation.GetSite) {
- let data = res.data as GetSiteResponse;
- this.setState({ version: data.version });
- }
- }
}
import { Component, linkEvent } from 'inferno';
import { Helmet } from 'inferno-helmet';
import { Subscription } from 'rxjs';
-import { retryWhen, delay, take } from 'rxjs/operators';
import {
LoginForm,
RegisterForm,
Site,
} from 'lemmy-js-client';
import { WebSocketService, UserService } from '../services';
-import { wsJsonToRes, validEmail, toast } from '../utils';
+import {
+ wsJsonToRes,
+ validEmail,
+ toast,
+ wsSubscribe,
+ isBrowser,
+ setIsoData,
+} from '../utils';
import { i18n } from '../i18next';
interface State {
}
export class Login extends Component<any, State> {
+ private isoData = setIsoData(this.context);
private subscription: Subscription;
emptyState: State = {
registerLoading: false,
captcha: undefined,
captchaPlaying: false,
- site: {
- id: undefined,
- name: undefined,
- creator_id: undefined,
- published: undefined,
- creator_name: undefined,
- number_of_users: undefined,
- number_of_posts: undefined,
- number_of_comments: undefined,
- number_of_communities: undefined,
- enable_downvotes: undefined,
- open_registration: undefined,
- enable_nsfw: undefined,
- },
+ site: this.isoData.site.site,
};
constructor(props: any, context: any) {
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')
- );
+ this.parseMessage = this.parseMessage.bind(this);
+ this.subscription = wsSubscribe(this.parseMessage);
- WebSocketService.Instance.getSite();
- WebSocketService.Instance.getCaptcha();
+ if (isBrowser()) {
+ WebSocketService.Instance.getCaptcha();
+ }
}
componentWillUnmount() {
- this.subscription.unsubscribe();
+ if (isBrowser()) {
+ this.subscription.unsubscribe();
+ }
}
get documentTitle(): string {
import { Component, linkEvent } from 'inferno';
import { Helmet } from 'inferno-helmet';
import { Subscription } from 'rxjs';
-import { retryWhen, delay, take } from 'rxjs/operators';
import {
UserOperation,
LoginResponse,
PasswordChangeForm,
WebSocketJsonResponse,
- GetSiteResponse,
Site,
} from 'lemmy-js-client';
import { WebSocketService, UserService } from '../services';
-import { wsJsonToRes, capitalizeFirstLetter, toast } from '../utils';
+import {
+ wsJsonToRes,
+ capitalizeFirstLetter,
+ toast,
+ setIsoData,
+ isBrowser,
+ wsSubscribe,
+} from '../utils';
import { i18n } from '../i18next';
interface State {
}
export class PasswordChange extends Component<any, State> {
+ private isoData = setIsoData(this.context);
private subscription: Subscription;
emptyState: State = {
password_verify: undefined,
},
loading: false,
- site: undefined,
+ site: this.isoData.site.site,
};
constructor(props: any, context: any) {
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();
+ this.parseMessage = this.parseMessage.bind(this);
+ this.subscription = wsSubscribe(this.parseMessage);
}
componentWillUnmount() {
- this.subscription.unsubscribe();
+ if (isBrowser()) {
+ this.subscription.unsubscribe();
+ }
}
get documentTitle(): string {
- if (this.state.site) {
- return `${i18n.t('password_change')} - ${this.state.site.name}`;
- } else {
- return 'Lemmy';
- }
+ return `${i18n.t('password_change')} - ${this.state.site.name}`;
}
render() {
this.setState(this.state);
UserService.Instance.login(data);
this.props.history.push('/');
- } else if (res.op == UserOperation.GetSite) {
- let data = res.data as GetSiteResponse;
- this.state.site = data.site;
- this.setState(this.state);
}
}
}
interface PostListingProps {
post: Post;
- communities: Community[];
+ communities: Community[]; // TODO this should be an optional
showCommunity?: boolean;
showBody?: boolean;
moderators?: CommunityUser[];
this.outer().map(post => (
<>
<PostListing
+ communities={[]}
post={post}
showCommunity={this.props.showCommunity}
enableDownvotes={this.props.enableDownvotes}
import { Component, linkEvent } from 'inferno';
-import { Link } from 'inferno-router';
import {
PrivateMessage as PrivateMessageI,
DeletePrivateMessageForm,
MarkPrivateMessageAsReadForm,
+ UserView,
} from 'lemmy-js-client';
import { WebSocketService, UserService } from '../services';
-import { mdToHtml, pictrsAvatarThumbnail, showAvatars, toast } from '../utils';
+import { mdToHtml, toast } from '../utils';
import { MomentTime } from './moment-time';
import { PrivateMessageForm } from './private-message-form';
import { UserListing, UserOther } from './user-listing';
showEdit: boolean;
collapsed: boolean;
viewSource: boolean;
+ recipient: UserView;
}
interface PrivateMessageProps {
showEdit: false,
collapsed: false,
viewSource: false,
+ recipient: {
+ id: this.props.privateMessage.recipient_id,
+ actor_id: this.props.privateMessage.recipient_actor_id,
+ name: this.props.privateMessage.recipient_name,
+ local: this.props.privateMessage.recipient_local,
+ avatar: this.props.privateMessage.recipient_avatar,
+ preferred_username: this.props.privateMessage
+ .recipient_preferred_username,
+ published: undefined,
+ number_of_posts: 0,
+ post_score: 0,
+ number_of_comments: 0,
+ comment_score: 0,
+ banned: false,
+ },
};
constructor(props: any, context: any) {
</ul>
{this.state.showEdit && (
<PrivateMessageForm
+ recipient={this.state.recipient}
privateMessage={message}
onEdit={this.handlePrivateMessageEdit}
onCreate={this.handlePrivateMessageCreate}
</div>
{this.state.showReply && (
<PrivateMessageForm
- params={{
- recipient_id: this.props.privateMessage.creator_id,
- }}
+ recipient={this.state.recipient}
onCreate={this.handlePrivateMessageCreate}
/>
)}
component: Main,
fetchInitialData: (auth, path) => Main.fetchInitialData(auth, path),
},
- { path: `/login`, component: Login },
+ {
+ path: `/login`,
+ component: Login,
+ },
{
path: `/create_post`,
component: CreatePost,