mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2025-01-15 14:35:49 +00:00
Hide NSFW field for create post form, for NSFW communities. (#2887)
- Fixes #2885
This commit is contained in:
parent
8e545f4914
commit
dafc33d9ab
4 changed files with 22 additions and 3 deletions
|
@ -86,6 +86,7 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
|
|||
blocked_instances: this.props.blockedInstances?.map(i => i.domain),
|
||||
blocked_urls: this.props.siteRes.blocked_urls.map(u => u.url),
|
||||
content_warning: this.props.siteRes.site_view.site.content_warning,
|
||||
enable_nsfw: !!this.props.siteRes.site_view.site.content_warning,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -908,6 +909,9 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
|
|||
|
||||
handleSiteEnableNsfwChange(i: SiteForm, event: any) {
|
||||
i.state.siteForm.enable_nsfw = event.target.checked;
|
||||
if (!event.target.checked) {
|
||||
i.state.siteForm.content_warning = "";
|
||||
}
|
||||
i.setState(i.state);
|
||||
}
|
||||
|
||||
|
@ -1025,6 +1029,10 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
|
|||
}
|
||||
|
||||
handleSiteContentWarningChange(val: string) {
|
||||
this.setState(s => ((s.siteForm.content_warning = val), s));
|
||||
this.state.siteForm.content_warning = val;
|
||||
if (val) {
|
||||
this.state.siteForm.enable_nsfw = true;
|
||||
}
|
||||
this.setState(this.state);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,6 +89,7 @@ interface CreatePostState {
|
|||
siteRes: GetSiteResponse;
|
||||
loading: boolean;
|
||||
selectedCommunityChoice?: Choice;
|
||||
selectedCommunityIsNsfw: boolean;
|
||||
initialCommunitiesRes: RequestState<ListCommunitiesResponse>;
|
||||
isIsomorphic: boolean;
|
||||
resetCounter: number; // resets PostForm when changed
|
||||
|
@ -115,6 +116,7 @@ export class CreatePost extends Component<
|
|||
initialCommunitiesRes: EMPTY_REQUEST,
|
||||
isIsomorphic: false,
|
||||
resetCounter: 0,
|
||||
selectedCommunityIsNsfw: false,
|
||||
};
|
||||
|
||||
constructor(props: CreatePostRouteProps, context: any) {
|
||||
|
@ -165,6 +167,7 @@ export class CreatePost extends Component<
|
|||
if (res.state === "success") {
|
||||
this.setState({
|
||||
selectedCommunityChoice: communityToChoice(res.data.community_view),
|
||||
selectedCommunityIsNsfw: res.data.community_view.community.nsfw,
|
||||
loading: false,
|
||||
});
|
||||
}
|
||||
|
@ -229,7 +232,12 @@ export class CreatePost extends Component<
|
|||
}
|
||||
|
||||
render() {
|
||||
const { selectedCommunityChoice, siteRes, loading } = this.state;
|
||||
const {
|
||||
selectedCommunityChoice,
|
||||
selectedCommunityIsNsfw,
|
||||
siteRes,
|
||||
loading,
|
||||
} = this.state;
|
||||
const {
|
||||
body,
|
||||
communityId,
|
||||
|
@ -286,6 +294,7 @@ export class CreatePost extends Component<
|
|||
onNsfwChange={this.handleNsfwChange}
|
||||
onAltTextBlur={this.handleAltTextBlur}
|
||||
onCopySuggestedTitle={this.handleCopySuggestedTitle}
|
||||
isNsfwCommunity={selectedCommunityIsNsfw}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -69,6 +69,7 @@ interface PostFormProps {
|
|||
enableDownvotes?: boolean;
|
||||
voteDisplayMode: LocalUserVoteDisplayMode;
|
||||
selectedCommunityChoice?: Choice;
|
||||
isNsfwCommunity: boolean;
|
||||
onSelectCommunity?: (choice: Choice) => void;
|
||||
initialCommunities?: CommunityView[];
|
||||
loading: boolean;
|
||||
|
@ -694,7 +695,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
|||
</div>
|
||||
</div>
|
||||
)}
|
||||
{this.props.enableNsfw && (
|
||||
{this.props.enableNsfw && !this.props.isNsfwCommunity && (
|
||||
<div className="form-check mb-3">
|
||||
<input
|
||||
className="form-check-input"
|
||||
|
|
|
@ -202,6 +202,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
|||
allLanguages={this.props.allLanguages}
|
||||
siteLanguages={this.props.siteLanguages}
|
||||
loading={this.state.loading}
|
||||
isNsfwCommunity={this.postView.community.nsfw}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue