Skip to content

Commit

Permalink
Merge pull request #183 from LemmyNet/main
Browse files Browse the repository at this point in the history
[pull] master from LemmyNet:main
  • Loading branch information
pull[bot] authored Jan 10, 2025
2 parents 4397e45 + dafc33d commit a5cd701
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/shared/components/home/site-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
}
11 changes: 10 additions & 1 deletion src/shared/components/post/create-post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -115,6 +116,7 @@ export class CreatePost extends Component<
initialCommunitiesRes: EMPTY_REQUEST,
isIsomorphic: false,
resetCounter: 0,
selectedCommunityIsNsfw: false,
};

constructor(props: CreatePostRouteProps, context: any) {
Expand Down Expand Up @@ -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,
});
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -286,6 +294,7 @@ export class CreatePost extends Component<
onNsfwChange={this.handleNsfwChange}
onAltTextBlur={this.handleAltTextBlur}
onCopySuggestedTitle={this.handleCopySuggestedTitle}
isNsfwCommunity={selectedCommunityIsNsfw}
/>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/shared/components/post/post-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ interface PostFormProps {
enableDownvotes?: boolean;
voteDisplayMode: LocalUserVoteDisplayMode;
selectedCommunityChoice?: Choice;
isNsfwCommunity: boolean;
onSelectCommunity?: (choice: Choice) => void;
initialCommunities?: CommunityView[];
loading: boolean;
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/shared/components/post/post-listing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit a5cd701

Please sign in to comment.