Hide NSFW field for create post form, for NSFW communities. (#2887)

- Fixes #2885
This commit is contained in:
Dessalines 2025-01-10 13:05:09 -05:00 committed by GitHub
parent 8e545f4914
commit dafc33d9ab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 22 additions and 3 deletions

View file

@ -86,6 +86,7 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
blocked_instances: this.props.blockedInstances?.map(i => i.domain), blocked_instances: this.props.blockedInstances?.map(i => i.domain),
blocked_urls: this.props.siteRes.blocked_urls.map(u => u.url), blocked_urls: this.props.siteRes.blocked_urls.map(u => u.url),
content_warning: this.props.siteRes.site_view.site.content_warning, 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) { handleSiteEnableNsfwChange(i: SiteForm, event: any) {
i.state.siteForm.enable_nsfw = event.target.checked; i.state.siteForm.enable_nsfw = event.target.checked;
if (!event.target.checked) {
i.state.siteForm.content_warning = "";
}
i.setState(i.state); i.setState(i.state);
} }
@ -1025,6 +1029,10 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
} }
handleSiteContentWarningChange(val: string) { 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);
} }
} }

View file

@ -89,6 +89,7 @@ interface CreatePostState {
siteRes: GetSiteResponse; siteRes: GetSiteResponse;
loading: boolean; loading: boolean;
selectedCommunityChoice?: Choice; selectedCommunityChoice?: Choice;
selectedCommunityIsNsfw: boolean;
initialCommunitiesRes: RequestState<ListCommunitiesResponse>; initialCommunitiesRes: RequestState<ListCommunitiesResponse>;
isIsomorphic: boolean; isIsomorphic: boolean;
resetCounter: number; // resets PostForm when changed resetCounter: number; // resets PostForm when changed
@ -115,6 +116,7 @@ export class CreatePost extends Component<
initialCommunitiesRes: EMPTY_REQUEST, initialCommunitiesRes: EMPTY_REQUEST,
isIsomorphic: false, isIsomorphic: false,
resetCounter: 0, resetCounter: 0,
selectedCommunityIsNsfw: false,
}; };
constructor(props: CreatePostRouteProps, context: any) { constructor(props: CreatePostRouteProps, context: any) {
@ -165,6 +167,7 @@ export class CreatePost extends Component<
if (res.state === "success") { if (res.state === "success") {
this.setState({ this.setState({
selectedCommunityChoice: communityToChoice(res.data.community_view), selectedCommunityChoice: communityToChoice(res.data.community_view),
selectedCommunityIsNsfw: res.data.community_view.community.nsfw,
loading: false, loading: false,
}); });
} }
@ -229,7 +232,12 @@ export class CreatePost extends Component<
} }
render() { render() {
const { selectedCommunityChoice, siteRes, loading } = this.state; const {
selectedCommunityChoice,
selectedCommunityIsNsfw,
siteRes,
loading,
} = this.state;
const { const {
body, body,
communityId, communityId,
@ -286,6 +294,7 @@ export class CreatePost extends Component<
onNsfwChange={this.handleNsfwChange} onNsfwChange={this.handleNsfwChange}
onAltTextBlur={this.handleAltTextBlur} onAltTextBlur={this.handleAltTextBlur}
onCopySuggestedTitle={this.handleCopySuggestedTitle} onCopySuggestedTitle={this.handleCopySuggestedTitle}
isNsfwCommunity={selectedCommunityIsNsfw}
/> />
</div> </div>
</div> </div>

View file

@ -69,6 +69,7 @@ interface PostFormProps {
enableDownvotes?: boolean; enableDownvotes?: boolean;
voteDisplayMode: LocalUserVoteDisplayMode; voteDisplayMode: LocalUserVoteDisplayMode;
selectedCommunityChoice?: Choice; selectedCommunityChoice?: Choice;
isNsfwCommunity: boolean;
onSelectCommunity?: (choice: Choice) => void; onSelectCommunity?: (choice: Choice) => void;
initialCommunities?: CommunityView[]; initialCommunities?: CommunityView[];
loading: boolean; loading: boolean;
@ -694,7 +695,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
</div> </div>
</div> </div>
)} )}
{this.props.enableNsfw && ( {this.props.enableNsfw && !this.props.isNsfwCommunity && (
<div className="form-check mb-3"> <div className="form-check mb-3">
<input <input
className="form-check-input" className="form-check-input"

View file

@ -202,6 +202,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
allLanguages={this.props.allLanguages} allLanguages={this.props.allLanguages}
siteLanguages={this.props.siteLanguages} siteLanguages={this.props.siteLanguages}
loading={this.state.loading} loading={this.state.loading}
isNsfwCommunity={this.postView.community.nsfw}
/> />
)} )}
</div> </div>