Fixing create_post, create_community, and login pages.
- Includes fetching the site for `enable_nsfw` info. Fixes #400
This commit is contained in:
parent
c252785632
commit
747a8f5b96
3 changed files with 31 additions and 9 deletions
10
ui/src/components/community-form.tsx
vendored
10
ui/src/components/community-form.tsx
vendored
|
@ -7,6 +7,7 @@ import {
|
|||
Category,
|
||||
ListCategoriesResponse,
|
||||
CommunityResponse,
|
||||
GetSiteResponse,
|
||||
} from '../interfaces';
|
||||
import { WebSocketService } from '../services';
|
||||
import { msgOp, capitalizeFirstLetter } from '../utils';
|
||||
|
@ -27,6 +28,7 @@ interface CommunityFormState {
|
|||
communityForm: CommunityFormI;
|
||||
categories: Array<Category>;
|
||||
loading: boolean;
|
||||
enable_nsfw: boolean;
|
||||
}
|
||||
|
||||
export class CommunityForm extends Component<
|
||||
|
@ -44,6 +46,7 @@ export class CommunityForm extends Component<
|
|||
},
|
||||
categories: [],
|
||||
loading: false,
|
||||
enable_nsfw: null,
|
||||
};
|
||||
|
||||
constructor(props: any, context: any) {
|
||||
|
@ -79,6 +82,7 @@ export class CommunityForm extends Component<
|
|||
);
|
||||
|
||||
WebSocketService.Instance.listCategories();
|
||||
WebSocketService.Instance.getSite();
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
@ -157,7 +161,7 @@ export class CommunityForm extends Component<
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{WebSocketService.Instance.site.enable_nsfw && (
|
||||
{this.state.enable_nsfw && (
|
||||
<div class="form-group row">
|
||||
<div class="col-12">
|
||||
<div class="form-check">
|
||||
|
@ -267,6 +271,10 @@ export class CommunityForm extends Component<
|
|||
let res: CommunityResponse = msg;
|
||||
this.state.loading = false;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
20
ui/src/components/login.tsx
vendored
20
ui/src/components/login.tsx
vendored
|
@ -7,6 +7,7 @@ import {
|
|||
LoginResponse,
|
||||
UserOperation,
|
||||
PasswordResetForm,
|
||||
GetSiteResponse,
|
||||
} from '../interfaces';
|
||||
import { WebSocketService, UserService } from '../services';
|
||||
import { msgOp, validEmail } from '../utils';
|
||||
|
@ -18,6 +19,7 @@ interface State {
|
|||
registerForm: RegisterForm;
|
||||
loginLoading: boolean;
|
||||
registerLoading: boolean;
|
||||
enable_nsfw: boolean;
|
||||
}
|
||||
|
||||
export class Login extends Component<any, State> {
|
||||
|
@ -37,6 +39,7 @@ export class Login extends Component<any, State> {
|
|||
},
|
||||
loginLoading: false,
|
||||
registerLoading: false,
|
||||
enable_nsfw: undefined,
|
||||
};
|
||||
|
||||
constructor(props: any, context: any) {
|
||||
|
@ -58,18 +61,14 @@ export class Login extends Component<any, State> {
|
|||
err => console.error(err),
|
||||
() => console.log('complete')
|
||||
);
|
||||
|
||||
WebSocketService.Instance.getSite();
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.subscription.unsubscribe();
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
document.title = `${i18n.t('login')} - ${
|
||||
WebSocketService.Instance.site.name
|
||||
}`;
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div class="container">
|
||||
|
@ -205,7 +204,7 @@ export class Login extends Component<any, State> {
|
|||
/>
|
||||
</div>
|
||||
</div>
|
||||
{WebSocketService.Instance.site.enable_nsfw && (
|
||||
{this.state.enable_nsfw && (
|
||||
<div class="form-group row">
|
||||
<div class="col-sm-10">
|
||||
<div class="form-check">
|
||||
|
@ -322,6 +321,13 @@ export class Login extends Component<any, State> {
|
|||
this.props.history.push('/communities');
|
||||
} else if (op == UserOperation.PasswordReset) {
|
||||
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
|
||||
}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
10
ui/src/components/post-form.tsx
vendored
10
ui/src/components/post-form.tsx
vendored
|
@ -15,6 +15,7 @@ import {
|
|||
SearchForm,
|
||||
SearchType,
|
||||
SearchResponse,
|
||||
GetSiteResponse,
|
||||
} from '../interfaces';
|
||||
import { WebSocketService, UserService } from '../services';
|
||||
import {
|
||||
|
@ -49,6 +50,7 @@ interface PostFormState {
|
|||
suggestedTitle: string;
|
||||
suggestedPosts: Array<Post>;
|
||||
crossPosts: Array<Post>;
|
||||
enable_nsfw: boolean;
|
||||
}
|
||||
|
||||
export class PostForm extends Component<PostFormProps, PostFormState> {
|
||||
|
@ -70,6 +72,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
|||
suggestedTitle: undefined,
|
||||
suggestedPosts: [],
|
||||
crossPosts: [],
|
||||
enable_nsfw: undefined,
|
||||
};
|
||||
|
||||
constructor(props: any, context: any) {
|
||||
|
@ -124,6 +127,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
|||
};
|
||||
|
||||
WebSocketService.Instance.listCommunities(listCommunitiesForm);
|
||||
WebSocketService.Instance.getSite();
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
@ -287,7 +291,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
|||
</div>
|
||||
</div>
|
||||
)}
|
||||
{WebSocketService.Instance.site.enable_nsfw && (
|
||||
{this.state.enable_nsfw && (
|
||||
<div class="form-group row">
|
||||
<div class="col-sm-10">
|
||||
<div class="form-check">
|
||||
|
@ -498,6 +502,10 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
|||
this.state.crossPosts = res.posts;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue