Fixing create_post, create_community, and login pages.

- Includes fetching the site for `enable_nsfw` info. Fixes #400
This commit is contained in:
Dessalines 2020-01-03 13:52:21 -05:00
parent 02cf67de4a
commit 07d7664a38
3 changed files with 31 additions and 9 deletions

View file

@ -7,6 +7,7 @@ import {
Category, Category,
ListCategoriesResponse, ListCategoriesResponse,
CommunityResponse, CommunityResponse,
GetSiteResponse,
} from '../interfaces'; } from '../interfaces';
import { WebSocketService } from '../services'; import { WebSocketService } from '../services';
import { msgOp, capitalizeFirstLetter } from '../utils'; import { msgOp, capitalizeFirstLetter } from '../utils';
@ -27,6 +28,7 @@ interface CommunityFormState {
communityForm: CommunityFormI; communityForm: CommunityFormI;
categories: Array<Category>; categories: Array<Category>;
loading: boolean; loading: boolean;
enable_nsfw: boolean;
} }
export class CommunityForm extends Component< export class CommunityForm extends Component<
@ -44,6 +46,7 @@ export class CommunityForm extends Component<
}, },
categories: [], categories: [],
loading: false, loading: false,
enable_nsfw: null,
}; };
constructor(props: any, context: any) { constructor(props: any, context: any) {
@ -79,6 +82,7 @@ export class CommunityForm extends Component<
); );
WebSocketService.Instance.listCategories(); WebSocketService.Instance.listCategories();
WebSocketService.Instance.getSite();
} }
componentDidMount() { componentDidMount() {
@ -157,7 +161,7 @@ export class CommunityForm extends Component<
</div> </div>
</div> </div>
{WebSocketService.Instance.site.enable_nsfw && ( {this.state.enable_nsfw && (
<div class="form-group row"> <div class="form-group row">
<div class="col-12"> <div class="col-12">
<div class="form-check"> <div class="form-check">
@ -267,6 +271,10 @@ export class CommunityForm extends Component<
let res: CommunityResponse = msg; let res: CommunityResponse = msg;
this.state.loading = false; this.state.loading = false;
this.props.onEdit(res.community); this.props.onEdit(res.community);
} else if (op == UserOperation.GetSite) {
let res: GetSiteResponse = msg;
this.state.enable_nsfw = res.site.enable_nsfw;
this.setState(this.state);
} }
} }
} }

View file

@ -7,6 +7,7 @@ import {
LoginResponse, LoginResponse,
UserOperation, UserOperation,
PasswordResetForm, PasswordResetForm,
GetSiteResponse,
} from '../interfaces'; } from '../interfaces';
import { WebSocketService, UserService } from '../services'; import { WebSocketService, UserService } from '../services';
import { msgOp, validEmail } from '../utils'; import { msgOp, validEmail } from '../utils';
@ -18,6 +19,7 @@ interface State {
registerForm: RegisterForm; registerForm: RegisterForm;
loginLoading: boolean; loginLoading: boolean;
registerLoading: boolean; registerLoading: boolean;
enable_nsfw: boolean;
} }
export class Login extends Component<any, State> { export class Login extends Component<any, State> {
@ -37,6 +39,7 @@ export class Login extends Component<any, State> {
}, },
loginLoading: false, loginLoading: false,
registerLoading: false, registerLoading: false,
enable_nsfw: undefined,
}; };
constructor(props: any, context: any) { constructor(props: any, context: any) {
@ -58,18 +61,14 @@ export class Login extends Component<any, State> {
err => console.error(err), err => console.error(err),
() => console.log('complete') () => console.log('complete')
); );
WebSocketService.Instance.getSite();
} }
componentWillUnmount() { componentWillUnmount() {
this.subscription.unsubscribe(); this.subscription.unsubscribe();
} }
componentDidMount() {
document.title = `${i18n.t('login')} - ${
WebSocketService.Instance.site.name
}`;
}
render() { render() {
return ( return (
<div class="container"> <div class="container">
@ -205,7 +204,7 @@ export class Login extends Component<any, State> {
/> />
</div> </div>
</div> </div>
{WebSocketService.Instance.site.enable_nsfw && ( {this.state.enable_nsfw && (
<div class="form-group row"> <div class="form-group row">
<div class="col-sm-10"> <div class="col-sm-10">
<div class="form-check"> <div class="form-check">
@ -322,6 +321,13 @@ export class Login extends Component<any, State> {
this.props.history.push('/communities'); this.props.history.push('/communities');
} else if (op == UserOperation.PasswordReset) { } else if (op == UserOperation.PasswordReset) {
alert(i18n.t('reset_password_mail_sent')); alert(i18n.t('reset_password_mail_sent'));
} else if (op == UserOperation.GetSite) {
let res: GetSiteResponse = msg;
this.state.enable_nsfw = res.site.enable_nsfw;
this.setState(this.state);
document.title = `${i18n.t('login')} - ${
WebSocketService.Instance.site.name
}`;
} }
} }
} }

View file

@ -15,6 +15,7 @@ import {
SearchForm, SearchForm,
SearchType, SearchType,
SearchResponse, SearchResponse,
GetSiteResponse,
} from '../interfaces'; } from '../interfaces';
import { WebSocketService, UserService } from '../services'; import { WebSocketService, UserService } from '../services';
import { import {
@ -49,6 +50,7 @@ interface PostFormState {
suggestedTitle: string; suggestedTitle: string;
suggestedPosts: Array<Post>; suggestedPosts: Array<Post>;
crossPosts: Array<Post>; crossPosts: Array<Post>;
enable_nsfw: boolean;
} }
export class PostForm extends Component<PostFormProps, PostFormState> { export class PostForm extends Component<PostFormProps, PostFormState> {
@ -70,6 +72,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
suggestedTitle: undefined, suggestedTitle: undefined,
suggestedPosts: [], suggestedPosts: [],
crossPosts: [], crossPosts: [],
enable_nsfw: undefined,
}; };
constructor(props: any, context: any) { constructor(props: any, context: any) {
@ -124,6 +127,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
}; };
WebSocketService.Instance.listCommunities(listCommunitiesForm); WebSocketService.Instance.listCommunities(listCommunitiesForm);
WebSocketService.Instance.getSite();
} }
componentDidMount() { componentDidMount() {
@ -287,7 +291,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
</div> </div>
</div> </div>
)} )}
{WebSocketService.Instance.site.enable_nsfw && ( {this.state.enable_nsfw && (
<div class="form-group row"> <div class="form-group row">
<div class="col-sm-10"> <div class="col-sm-10">
<div class="form-check"> <div class="form-check">
@ -498,6 +502,10 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
this.state.crossPosts = res.posts; this.state.crossPosts = res.posts;
} }
this.setState(this.state); this.setState(this.state);
} else if (op == UserOperation.GetSite) {
let res: GetSiteResponse = msg;
this.state.enable_nsfw = res.site.enable_nsfw;
this.setState(this.state);
} }
} }
} }