showCommunity?: boolean;
sort?: CommentSortType;
sortType?: SortType;
+ enableDownvotes: boolean;
}
export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
<span class="ml-1">{this.state.upvotes}</span>
)}
</button>
- {WebSocketService.Instance.site.enable_downvotes && (
+ {this.props.enableDownvotes && (
<button
className={`btn btn-link btn-animate ${
this.state.my_vote == -1
postCreatorId={this.props.postCreatorId}
sort={this.props.sort}
sortType={this.props.sortType}
+ enableDownvotes={this.props.enableDownvotes}
/>
)}
{/* A collapsed clearfix */}
showCommunity?: boolean;
sort?: CommentSortType;
sortType?: SortType;
+ enableDownvotes: boolean;
}
export class CommentNodes extends Component<
showCommunity={this.props.showCommunity}
sort={this.props.sort}
sortType={this.props.sortType}
+ enableDownvotes={this.props.enableDownvotes}
/>
))}
</div>
import { Component, linkEvent } from 'inferno';
-import { Link } from 'inferno-router';
import { Subscription } from 'rxjs';
import { retryWhen, delay, take } from 'rxjs/operators';
import {
ListCommunitiesForm,
SortType,
WebSocketJsonResponse,
+ GetSiteResponse,
} from '../interfaces';
import { WebSocketService } from '../services';
import { wsJsonToRes, toast } from '../utils';
);
this.refetch();
+ WebSocketService.Instance.getSite();
}
getPageFromProps(props: any): number {
this.subscription.unsubscribe();
}
- componentDidMount() {
- document.title = `${i18n.t('communities')} - ${
- WebSocketService.Instance.site.name
- }`;
- }
-
// Necessary for back button for some reason
componentWillReceiveProps(nextProps: any) {
if (nextProps.history.action == 'POP') {
found.subscribed = data.community.subscribed;
found.number_of_subscribers = data.community.number_of_subscribers;
this.setState(this.state);
+ } else if (res.op == UserOperation.GetSite) {
+ let data = res.data as GetSiteResponse;
+ document.title = `${i18n.t('communities')} - ${data.site.name}`;
}
}
}
Category,
ListCategoriesResponse,
CommunityResponse,
- GetSiteResponse,
WebSocketJsonResponse,
} from '../interfaces';
import { WebSocketService } from '../services';
onCancel?(): any;
onCreate?(community: Community): any;
onEdit?(community: Community): any;
+ enableNsfw: boolean;
}
interface CommunityFormState {
communityForm: CommunityFormI;
categories: Array<Category>;
loading: boolean;
- enable_nsfw: boolean;
}
export class CommunityForm extends Component<
},
categories: [],
loading: false,
- enable_nsfw: null,
};
constructor(props: any, context: any) {
);
WebSocketService.Instance.listCategories();
- WebSocketService.Instance.getSite();
}
componentDidMount() {
</div>
</div>
- {this.state.enable_nsfw && (
+ {this.props.enableNsfw && (
<div class="form-group row">
<div class="col-12">
<div class="form-check">
let data = res.data as CommunityResponse;
this.state.loading = false;
this.props.onEdit(data.community);
- } else if (res.op == UserOperation.GetSite) {
- let data = res.data as GetSiteResponse;
- this.state.enable_nsfw = data.site.enable_nsfw;
- this.setState(this.state);
}
}
}
GetCommentsResponse,
CommentResponse,
WebSocketJsonResponse,
+ GetSiteResponse,
+ Site,
} from '../interfaces';
import { WebSocketService } from '../services';
import { PostListings } from './post-listings';
dataType: DataType;
sort: SortType;
page: number;
+ site: Site;
}
export class Community extends Component<any, State> {
dataType: getDataTypeFromProps(this.props),
sort: getSortTypeFromProps(this.props),
page: getPageFromProps(this.props),
+ 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,
+ },
};
constructor(props: any, context: any) {
name: this.state.communityName ? this.state.communityName : null,
};
WebSocketService.Instance.getCommunity(form);
+ WebSocketService.Instance.getSite();
}
componentWillUnmount() {
moderators={this.state.moderators}
admins={this.state.admins}
online={this.state.online}
+ enableNsfw={this.state.site.enable_nsfw}
/>
</div>
</div>
posts={this.state.posts}
removeDuplicates
sort={this.state.sort}
+ enableDownvotes={this.state.site.enable_downvotes}
+ enableNsfw={this.state.site.enable_nsfw}
/>
) : (
<CommentNodes
noIndent
sortType={this.state.sort}
showContext
+ enableDownvotes={this.state.site.enable_downvotes}
/>
);
}
this.state.moderators = data.moderators;
this.state.admins = data.admins;
this.state.online = data.online;
- document.title = `/c/${this.state.community.name} - ${WebSocketService.Instance.site.name}`;
+ document.title = `/c/${this.state.community.name} - ${this.state.site.name}`;
this.setState(this.state);
this.fetchData();
} else if (res.op == UserOperation.EditCommunity) {
let data = res.data as CommentResponse;
createCommentLikeRes(data, this.state.comments);
this.setState(this.state);
+ } else if (res.op == UserOperation.GetSite) {
+ let data = res.data as GetSiteResponse;
+ this.state.site = data.site;
+ this.setState(this.state);
}
}
}
import { Component } from 'inferno';
+import { Subscription } from 'rxjs';
+import { retryWhen, delay, take } from 'rxjs/operators';
import { CommunityForm } from './community-form';
-import { Community } from '../interfaces';
+import {
+ Community,
+ UserOperation,
+ WebSocketJsonResponse,
+ GetSiteResponse,
+} from '../interfaces';
+import { toast, wsJsonToRes } from '../utils';
import { WebSocketService } from '../services';
import { i18n } from '../i18next';
-export class CreateCommunity extends Component<any, any> {
+interface CreateCommunityState {
+ enableNsfw: boolean;
+}
+
+export class CreateCommunity extends Component<any, CreateCommunityState> {
+ private subscription: Subscription;
+ private emptyState: CreateCommunityState = {
+ enableNsfw: null,
+ };
constructor(props: any, context: any) {
super(props, context);
this.handleCommunityCreate = this.handleCommunityCreate.bind(this);
+ 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('create_community')} - ${
- WebSocketService.Instance.site.name
- }`;
+ componentWillUnmount() {
+ this.subscription.unsubscribe();
}
render() {
<div class="row">
<div class="col-12 col-lg-6 offset-lg-3 mb-4">
<h5>{i18n.t('create_community')}</h5>
- <CommunityForm onCreate={this.handleCommunityCreate} />
+ <CommunityForm
+ onCreate={this.handleCommunityCreate}
+ enableNsfw={this.state.enableNsfw}
+ />
</div>
</div>
</div>
handleCommunityCreate(community: Community) {
this.props.history.push(`/c/${community.name}`);
}
+
+ 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.enableNsfw = data.site.enable_nsfw;
+ this.setState(this.state);
+ document.title = `${i18n.t('create_community')} - ${data.site.name}`;
+ }
+ }
}
import { Component } from 'inferno';
+import { Subscription } from 'rxjs';
+import { retryWhen, delay, take } from 'rxjs/operators';
import { PostForm } from './post-form';
+import { toast, wsJsonToRes } from '../utils';
import { WebSocketService } from '../services';
-import { PostFormParams } from '../interfaces';
+import {
+ UserOperation,
+ PostFormParams,
+ WebSocketJsonResponse,
+ GetSiteResponse,
+ Site,
+} from '../interfaces';
import { i18n } from '../i18next';
-export class CreatePost extends Component<any, any> {
+interface CreatePostState {
+ site: Site;
+}
+
+export class CreatePost extends Component<any, CreatePostState> {
+ private subscription: Subscription;
+ private emptyState: CreatePostState = {
+ 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,
+ },
+ };
+
constructor(props: any, context: any) {
super(props, context);
this.handlePostCreate = this.handlePostCreate.bind(this);
+ 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('create_post')} - ${
- WebSocketService.Instance.site.name
- }`;
+ componentWillUnmount() {
+ this.subscription.unsubscribe();
}
render() {
<div class="row">
<div class="col-12 col-lg-6 offset-lg-3 mb-4">
<h5>{i18n.t('create_post')}</h5>
- <PostForm onCreate={this.handlePostCreate} params={this.params} />
+ <PostForm
+ onCreate={this.handlePostCreate}
+ params={this.params}
+ enableDownvotes={this.state.site.enable_downvotes}
+ enableNsfw={this.state.site.enable_nsfw}
+ />
</div>
</div>
</div>
handlePostCreate(id: number) {
this.props.history.push(`/post/${id}`);
}
+
+ 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);
+ document.title = `${i18n.t('create_post')} - ${data.site.name}`;
+ }
+ }
}
import { Component } from 'inferno';
+import { Subscription } from 'rxjs';
+import { retryWhen, delay, take } from 'rxjs/operators';
import { PrivateMessageForm } from './private-message-form';
import { WebSocketService } from '../services';
-import { PrivateMessageFormParams } from '../interfaces';
-import { toast } from '../utils';
+import {
+ UserOperation,
+ WebSocketJsonResponse,
+ GetSiteResponse,
+ PrivateMessageFormParams,
+} from '../interfaces';
+import { toast, wsJsonToRes } from '../utils';
import { i18n } from '../i18next';
export class CreatePrivateMessage extends Component<any, any> {
+ private subscription: Subscription;
constructor(props: any, context: any) {
super(props, context);
this.handlePrivateMessageCreate = this.handlePrivateMessageCreate.bind(
this
);
+
+ 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('create_private_message')} - ${
- WebSocketService.Instance.site.name
- }`;
+ componentWillUnmount() {
+ this.subscription.unsubscribe();
}
render() {
// Navigate to the front
this.props.history.push(`/`);
}
+
+ 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('create_private_message')} - ${
+ data.site.name
+ }`;
+ }
+ }
}
GetPrivateMessagesForm,
PrivateMessagesResponse,
PrivateMessageResponse,
+ GetSiteResponse,
} from '../interfaces';
import { WebSocketService, UserService } from '../services';
import {
messages: Array<PrivateMessageI>;
sort: SortType;
page: number;
+ enableDownvotes: boolean;
}
export class Inbox extends Component<any, InboxState> {
messages: [],
sort: SortType.New,
page: 1,
+ enableDownvotes: undefined,
};
constructor(props: any, context: any) {
);
this.refetch();
+ WebSocketService.Instance.getSite();
}
componentWillUnmount() {
this.subscription.unsubscribe();
}
- componentDidMount() {
- document.title = `/u/${UserService.Instance.user.username} ${i18n.t(
- 'inbox'
- )} - ${WebSocketService.Instance.site.name}`;
- }
-
render() {
return (
<div class="container">
noIndent
markable
showContext
+ enableDownvotes={this.state.enableDownvotes}
/>
) : (
<PrivateMessage privateMessage={i} />
noIndent
markable
showContext
+ enableDownvotes={this.state.enableDownvotes}
/>
</div>
);
noIndent
markable
showContext
+ enableDownvotes={this.state.enableDownvotes}
/>
))}
</div>
let data = res.data as CommentResponse;
createCommentLikeRes(data, this.state.replies);
this.setState(this.state);
+ } else if (res.op == UserOperation.GetSite) {
+ let data = res.data as GetSiteResponse;
+ this.state.enableDownvotes = data.site.enable_downvotes;
+ this.setState(this.state);
+ document.title = `/u/${UserService.Instance.user.username} ${i18n.t(
+ 'inbox'
+ )} - ${data.site.name}`;
}
}
let data = res.data as GetSiteResponse;
this.state.enable_nsfw = data.site.enable_nsfw;
this.setState(this.state);
- document.title = `${i18n.t('login')} - ${
- WebSocketService.Instance.site.name
- }`;
+ document.title = `${i18n.t('login')} - ${data.site.name}`;
}
}
}
showCommunity
removeDuplicates
sort={this.state.sort}
+ enableDownvotes={this.state.siteRes.site.enable_downvotes}
+ enableNsfw={this.state.siteRes.site.enable_nsfw}
/>
) : (
<CommentNodes
showCommunity
sortType={this.state.sort}
showContext
+ enableDownvotes={this.state.siteRes.site.enable_downvotes}
/>
);
}
this.state.siteRes.banned = data.banned;
this.state.siteRes.online = data.online;
this.setState(this.state);
- document.title = `${WebSocketService.Instance.site.name}`;
+ document.title = `${this.state.siteRes.site.name}`;
} else if (res.op == UserOperation.EditSite) {
let data = res.data as SiteResponse;
this.state.siteRes.site = data.site;
ModAddCommunity,
ModAdd,
WebSocketJsonResponse,
+ GetSiteResponse,
} from '../interfaces';
import { WebSocketService } from '../services';
import { wsJsonToRes, addTypeInfo, fetchLimit, toast } from '../utils';
);
this.refetch();
+ WebSocketService.Instance.getSite();
}
componentWillUnmount() {
this.subscription.unsubscribe();
}
- componentDidMount() {
- document.title = `Modlog - ${WebSocketService.Instance.site.name}`;
- }
-
setCombined(res: GetModlogResponse) {
let removed_posts = addTypeInfo(res.removed_posts, 'removed_posts');
let locked_posts = addTypeInfo(res.locked_posts, 'locked_posts');
this.state.loading = false;
window.scrollTo(0, 0);
this.setCombined(data);
+ } else if (res.op == UserOperation.GetSite) {
+ let data = res.data as GetSiteResponse;
+ document.title = `Modlog - ${data.site.name}`;
}
}
}
if (data.site && !this.state.siteName) {
this.state.siteName = data.site.name;
this.state.admins = data.admins;
- WebSocketService.Instance.site = data.site;
- WebSocketService.Instance.admins = data.admins;
-
this.setState(this.state);
}
}
LoginResponse,
PasswordChangeForm,
WebSocketJsonResponse,
+ GetSiteResponse,
} from '../interfaces';
import { WebSocketService, UserService } from '../services';
import { wsJsonToRes, capitalizeFirstLetter, toast } from '../utils';
err => console.error(err),
() => console.log('complete')
);
+ WebSocketService.Instance.getSite();
}
componentWillUnmount() {
this.subscription.unsubscribe();
}
- componentDidMount() {
- document.title = `${i18n.t('password_change')} - ${
- WebSocketService.Instance.site.name
- }`;
- }
-
render() {
return (
<div class="container">
this.state.loading = false;
this.setState(this.state);
return;
- } else {
- if (res.op == UserOperation.PasswordChange) {
- let data = res.data as LoginResponse;
- this.state = this.emptyState;
- this.setState(this.state);
- UserService.Instance.login(data);
- this.props.history.push('/');
- }
+ } else if (res.op == UserOperation.PasswordChange) {
+ let data = res.data as LoginResponse;
+ this.state = this.emptyState;
+ this.setState(this.state);
+ UserService.Instance.login(data);
+ this.props.history.push('/');
+ } else if (res.op == UserOperation.GetSite) {
+ let data = res.data as GetSiteResponse;
+ document.title = `${i18n.t('password_change')} - ${data.site.name}`;
}
}
}
SearchForm,
SearchType,
SearchResponse,
- GetSiteResponse,
WebSocketJsonResponse,
} from '../interfaces';
import { WebSocketService, UserService } from '../services';
onCancel?(): any;
onCreate?(id: number): any;
onEdit?(post: Post): any;
+ enableNsfw: boolean;
+ enableDownvotes: boolean;
}
interface PostFormState {
suggestedTitle: string;
suggestedPosts: Array<Post>;
crossPosts: Array<Post>;
- enable_nsfw: boolean;
}
export class PostForm extends Component<PostFormProps, PostFormState> {
suggestedTitle: undefined,
suggestedPosts: [],
crossPosts: [],
- enable_nsfw: undefined,
};
constructor(props: any, context: any) {
};
WebSocketService.Instance.listCommunities(listCommunitiesForm);
- WebSocketService.Instance.getSite();
}
componentDidMount() {
<div class="my-1 text-muted small font-weight-bold">
{i18n.t('cross_posts')}
</div>
- <PostListings showCommunity posts={this.state.crossPosts} />
+ <PostListings
+ showCommunity
+ posts={this.state.crossPosts}
+ enableDownvotes={this.props.enableDownvotes}
+ enableNsfw={this.props.enableNsfw}
+ />
</>
)}
</div>
<div class="my-1 text-muted small font-weight-bold">
{i18n.t('related_posts')}
</div>
- <PostListings posts={this.state.suggestedPosts} />
+ <PostListings
+ posts={this.state.suggestedPosts}
+ enableDownvotes={this.props.enableDownvotes}
+ enableNsfw={this.props.enableNsfw}
+ />
</>
)}
</div>
</div>
</div>
)}
- {this.state.enable_nsfw && (
+ {this.props.enableNsfw && (
<div class="form-group row">
<div class="col-sm-10">
<div class="form-check">
this.state.crossPosts = data.posts;
}
this.setState(this.state);
- } else if (res.op == UserOperation.GetSite) {
- let data = res.data as GetSiteResponse;
- this.state.enable_nsfw = data.site.enable_nsfw;
- this.setState(this.state);
}
}
}
showBody?: boolean;
moderators?: Array<CommunityUser>;
admins?: Array<UserView>;
+ enableDownvotes: boolean;
+ enableNsfw: boolean;
}
export class PostListing extends Component<PostListingProps, PostListingState> {
post={this.props.post}
onEdit={this.handleEditPost}
onCancel={this.handleEditCancel}
+ enableNsfw={this.props.enableNsfw}
+ enableDownvotes={this.props.enableDownvotes}
/>
</div>
)}
>
{this.state.score}
</div>
- {WebSocketService.Instance.site.enable_downvotes && (
+ {this.props.enableDownvotes && (
<button
className={`btn-animate btn btn-link p-0 ${
this.state.my_vote == -1 ? 'text-danger' : 'text-muted'
showCommunity?: boolean;
removeDuplicates?: boolean;
sort?: SortType;
+ enableDownvotes: boolean;
+ enableNsfw: boolean;
}
export class PostListings extends Component<PostListingsProps, any> {
<PostListing
post={post}
showCommunity={this.props.showCommunity}
+ enableDownvotes={this.props.enableDownvotes}
+ enableNsfw={this.props.enableNsfw}
/>
<hr class="my-2" />
</>
BanUserResponse,
AddModToCommunityResponse,
AddAdminResponse,
- UserView,
SearchType,
SortType,
SearchForm,
commentSort: CommentSortType;
community: Community;
moderators: Array<CommunityUser>;
- admins: Array<UserView>;
online: number;
scrolled?: boolean;
scrolled_comment_id?: number;
loading: boolean;
crossPosts: Array<PostI>;
+ siteRes: GetSiteResponse;
}
export class Post extends Component<any, PostState> {
commentSort: CommentSortType.Hot,
community: null,
moderators: [],
- admins: [],
online: null,
scrolled: false,
loading: true,
crossPosts: [],
+ siteRes: {
+ admins: [],
+ banned: [],
+ 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,
+ },
+ online: null,
+ },
};
constructor(props: any, context: any) {
id: postId,
};
WebSocketService.Instance.getPost(form);
+ WebSocketService.Instance.getSite();
}
componentWillUnmount() {
showBody
showCommunity
moderators={this.state.moderators}
- admins={this.state.admins}
+ admins={this.state.siteRes.admins}
+ enableDownvotes={this.state.siteRes.site.enable_downvotes}
+ enableNsfw={this.state.siteRes.site.enable_nsfw}
/>
<div className="mb-2" />
<CommentForm
noIndent
locked={this.state.post.locked}
moderators={this.state.moderators}
- admins={this.state.admins}
+ admins={this.state.siteRes.admins}
postCreatorId={this.state.post.creator_id}
showContext
+ enableDownvotes={this.state.siteRes.site.enable_downvotes}
/>
</div>
</div>
<Sidebar
community={this.state.community}
moderators={this.state.moderators}
- admins={this.state.admins}
+ admins={this.state.siteRes.admins}
online={this.state.online}
+ enableNsfw={this.state.siteRes.site.enable_nsfw}
/>
</div>
);
nodes={nodes}
locked={this.state.post.locked}
moderators={this.state.moderators}
- admins={this.state.admins}
+ admins={this.state.siteRes.admins}
postCreatorId={this.state.post.creator_id}
sort={this.state.commentSort}
+ enableDownvotes={this.state.siteRes.site.enable_downvotes}
/>
</div>
);
this.state.comments = data.comments;
this.state.community = data.community;
this.state.moderators = data.moderators;
- this.state.admins = data.admins;
+ this.state.siteRes.admins = data.admins;
this.state.online = data.online;
this.state.loading = false;
- document.title = `${this.state.post.name} - ${WebSocketService.Instance.site.name}`;
+ document.title = `${this.state.post.name} - ${this.state.siteRes.site.name}`;
// Get cross-posts
if (this.state.post.url) {
this.setState(this.state);
} else if (res.op == UserOperation.AddAdmin) {
let data = res.data as AddAdminResponse;
- this.state.admins = data.admins;
+ this.state.siteRes.admins = data.admins;
this.setState(this.state);
} else if (res.op == UserOperation.Search) {
let data = res.data as SearchResponse;
this.state.post.duplicates = this.state.crossPosts;
}
this.setState(this.state);
- } else if (res.op == UserOperation.TransferSite) {
+ } else if (
+ res.op == UserOperation.TransferSite ||
+ res.op == UserOperation.GetSite
+ ) {
let data = res.data as GetSiteResponse;
- this.state.admins = data.admins;
+ this.state.siteRes = data;
this.setState(this.state);
} else if (res.op == UserOperation.TransferCommunity) {
let data = res.data as GetCommunityResponse;
this.state.community = data.community;
this.state.moderators = data.moderators;
- this.state.admins = data.admins;
+ this.state.siteRes.admins = data.admins;
this.setState(this.state);
}
}
import { Component, linkEvent } from 'inferno';
import { Prompt } from 'inferno-router';
-import { Link } from 'inferno-router';
import { Subscription } from 'rxjs';
import { retryWhen, delay, take } from 'rxjs/operators';
import {
PostResponse,
CommentResponse,
WebSocketJsonResponse,
+ GetSiteResponse,
+ Site,
} from '../interfaces';
import { WebSocketService } from '../services';
import {
page: number;
searchResponse: SearchResponse;
loading: boolean;
+ site: Site;
}
export class Search extends Component<any, SearchState> {
users: [],
},
loading: 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,
+ },
};
getSearchQueryFromProps(props: any): string {
() => console.log('complete')
);
+ WebSocketService.Instance.getSite();
+
if (this.state.q) {
this.search();
}
}
}
- componentDidMount() {
- document.title = `${i18n.t('search')} - ${
- WebSocketService.Instance.site.name
- }`;
- }
-
render() {
return (
<div class="container">
<div class="row">
<div class="col-12">
{i.type_ == 'posts' && (
- <PostListing post={i.data as Post} showCommunity />
+ <PostListing
+ post={i.data as Post}
+ showCommunity
+ enableDownvotes={this.state.site.enable_downvotes}
+ enableNsfw={this.state.site.enable_nsfw}
+ />
)}
{i.type_ == 'comments' && (
<CommentNodes
nodes={[{ comment: i.data as Comment }]}
locked
noIndent
+ enableDownvotes={this.state.site.enable_downvotes}
/>
)}
{i.type_ == 'communities' && (
nodes={commentsToFlatNodes(this.state.searchResponse.comments)}
locked
noIndent
+ enableDownvotes={this.state.site.enable_downvotes}
/>
);
}
{this.state.searchResponse.posts.map(post => (
<div class="row">
<div class="col-12">
- <PostListing post={post} showCommunity />
+ <PostListing
+ post={post}
+ showCommunity
+ enableDownvotes={this.state.site.enable_downvotes}
+ enableNsfw={this.state.site.enable_nsfw}
+ />
</div>
</div>
))}
this.state.searchResponse = data;
this.state.loading = false;
document.title = `${i18n.t('search')} - ${this.state.q} - ${
- WebSocketService.Instance.site.name
+ this.state.site.name
}`;
window.scrollTo(0, 0);
this.setState(this.state);
let data = res.data as PostResponse;
createPostLikeFindRes(data, this.state.searchResponse.posts);
this.setState(this.state);
+ } else if (res.op == UserOperation.GetSite) {
+ let data = res.data as GetSiteResponse;
+ this.state.site = data.site;
+ this.setState(this.state);
+ document.title = `${i18n.t('search')} - ${data.site.name}`;
}
}
}
moderators: Array<CommunityUser>;
admins: Array<UserView>;
online: number;
+ enableNsfw: boolean;
}
interface SidebarState {
community={this.props.community}
onEdit={this.handleEditCommunity}
onCancel={this.handleEditCancel}
+ enableNsfw={this.props.enableNsfw}
/>
)}
</div>
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;
// 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">
</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}`;
+ }
+ }
}
DeleteAccountForm,
PostResponse,
WebSocketJsonResponse,
+ GetSiteResponse,
+ Site,
} from '../interfaces';
import { WebSocketService, UserService } from '../services';
import {
deleteAccountLoading: boolean;
deleteAccountShowConfirm: boolean;
deleteAccountForm: DeleteAccountForm;
+ site: Site;
}
export class User extends Component<any, UserState> {
deleteAccountForm: {
password: null,
},
+ 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,
+ },
};
constructor(props: any, context: any) {
);
this.refetch();
+ WebSocketService.Instance.getSite();
}
get isCurrentUser() {
post={i.data as Post}
admins={this.state.admins}
showCommunity
+ enableDownvotes={this.state.site.enable_downvotes}
+ enableNsfw={this.state.site.enable_nsfw}
/>
) : (
<CommentNodes
admins={this.state.admins}
noIndent
showContext
+ enableDownvotes={this.state.site.enable_downvotes}
/>
)}
</div>
admins={this.state.admins}
noIndent
showContext
+ enableDownvotes={this.state.site.enable_downvotes}
/>
</div>
);
return (
<div>
{this.state.posts.map(post => (
- <PostListing post={post} admins={this.state.admins} showCommunity />
+ <PostListing
+ post={post}
+ admins={this.state.admins}
+ showCommunity
+ enableDownvotes={this.state.site.enable_downvotes}
+ enableNsfw={this.state.site.enable_nsfw}
+ />
))}
</div>
);
/>
</div>
</div>
- {WebSocketService.Instance.site.enable_nsfw && (
+ {this.state.site.enable_nsfw && (
<div class="form-group">
<div class="form-check">
<input
UserService.Instance.user.show_avatars;
this.state.userSettingsForm.matrix_user_id = this.state.user.matrix_user_id;
}
- document.title = `/u/${this.state.user.name} - ${WebSocketService.Instance.site.name}`;
+ document.title = `/u/${this.state.user.name} - ${this.state.site.name}`;
window.scrollTo(0, 0);
this.setState(this.state);
setupTippy();
this.state.deleteAccountShowConfirm = false;
this.setState(this.state);
this.context.router.history.push('/');
+ } else if (res.op == UserOperation.GetSite) {
+ let data = res.data as GetSiteResponse;
+ this.state.site = data.site;
+ this.setState(this.state);
}
}
}
TransferSiteForm,
BanUserForm,
SiteForm,
- Site,
UserView,
GetRepliesForm,
GetUserMentionsForm,
public ws: ReconnectingWebSocket;
public subject: Observable<any>;
- public site: Site;
public admins: Array<UserView>;
public banned: Array<UserView>;