Frontend Settings - "Blur NSFW" and "Auto Expand" (#1640)

* fix for en-AU locale

* add setting checkboxes for auto-expand and blur nsfw

* mappings for backend

* blur and nsfw settings

* add icon blur

* fix lint

* revert remove en-au
This commit is contained in:
Domenic Horner 2023-08-08 01:48:55 +08:00 committed by GitHub
parent 2efe167f6d
commit 9fd75faa16
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 80 additions and 3 deletions

View file

@ -251,7 +251,7 @@ hr {
flex: 1; flex: 1;
} }
.img-blur { .img-blur-thumb {
filter: blur(10px); filter: blur(10px);
-webkit-filter: blur(10px); -webkit-filter: blur(10px);
-moz-filter: blur(10px); -moz-filter: blur(10px);
@ -259,6 +259,18 @@ hr {
-ms-filter: blur(10px); -ms-filter: blur(10px);
} }
.img-blur-icon {
filter: blur(3px);
-webkit-filter: blur(3px);
-moz-filter: blur(3px);
-o-filter: blur(3px);
-ms-filter: blur(3px);
}
.img-cover {
object-fit: cover;
}
.img-expanded { .img-expanded {
max-height: 90vh; max-height: 90vh;
} }

View file

@ -1,6 +1,8 @@
import classNames from "classnames"; import classNames from "classnames";
import { Component } from "inferno"; import { Component } from "inferno";
import { UserService } from "../../services";
const iconThumbnailSize = 96; const iconThumbnailSize = 96;
const thumbnailSize = 256; const thumbnailSize = 256;
@ -21,6 +23,14 @@ export class PictrsImage extends Component<PictrsImageProps, any> {
} }
render() { render() {
let user_blur_nsfw = true;
if (UserService.Instance.myUserInfo) {
user_blur_nsfw =
UserService.Instance.myUserInfo?.local_user_view.local_user.blur_nsfw;
}
const blur_image = this.props.nsfw && user_blur_nsfw;
return ( return (
<picture> <picture>
<source srcSet={this.src("webp")} type="image/webp" /> <source srcSet={this.src("webp")} type="image/webp" />
@ -38,7 +48,8 @@ export class PictrsImage extends Component<PictrsImageProps, any> {
this.props.thumbnail && !this.props.icon && !this.props.banner, this.props.thumbnail && !this.props.icon && !this.props.banner,
"img-expanded slight-radius": "img-expanded slight-radius":
!this.props.thumbnail && !this.props.icon, !this.props.thumbnail && !this.props.icon,
"img-blur": this.props.thumbnail && this.props.nsfw, "img-blur-icon": this.props.icon && blur_image,
"img-blur-thumb": this.props.thumbnail && blur_image,
"object-fit-cover img-icon me-1": this.props.icon, "object-fit-cover img-icon me-1": this.props.icon,
"ms-2 mb-0 rounded-circle object-fit-cover avatar-overlay": "ms-2 mb-0 rounded-circle object-fit-cover avatar-overlay":
this.props.iconOverlay, this.props.iconOverlay,

View file

@ -58,12 +58,14 @@ export class CommunityLink extends Component<CommunityLinkProps, any> {
avatarAndName(displayName: string) { avatarAndName(displayName: string) {
const icon = this.props.community.icon; const icon = this.props.community.icon;
const nsfw = this.props.community.nsfw;
return ( return (
<> <>
{!this.props.hideAvatar && {!this.props.hideAvatar &&
!this.props.community.removed && !this.props.community.removed &&
showAvatars() && showAvatars() &&
icon && <PictrsImage src={icon} icon />} icon && <PictrsImage src={icon} icon nsfw={nsfw} />}
<span className="overflow-wrap-anywhere">{displayName}</span> <span className="overflow-wrap-anywhere">{displayName}</span>
</> </>
); );

View file

@ -54,6 +54,8 @@ interface SettingsState {
// TODO redo these forms // TODO redo these forms
saveUserSettingsForm: { saveUserSettingsForm: {
show_nsfw?: boolean; show_nsfw?: boolean;
blur_nsfw?: boolean;
auto_expand?: boolean;
theme?: string; theme?: string;
default_sort_type?: SortType; default_sort_type?: SortType;
default_listing_type?: ListingType; default_listing_type?: ListingType;
@ -177,6 +179,8 @@ export class Settings extends Component<any, SettingsState> {
const { const {
local_user: { local_user: {
show_nsfw, show_nsfw,
blur_nsfw,
auto_expand,
theme, theme,
default_sort_type, default_sort_type,
default_listing_type, default_listing_type,
@ -206,6 +210,8 @@ export class Settings extends Component<any, SettingsState> {
saveUserSettingsForm: { saveUserSettingsForm: {
...this.state.saveUserSettingsForm, ...this.state.saveUserSettingsForm,
show_nsfw, show_nsfw,
blur_nsfw,
auto_expand,
theme: theme ?? "browser", theme: theme ?? "browser",
default_sort_type, default_sort_type,
default_listing_type, default_listing_type,
@ -665,6 +671,34 @@ export class Settings extends Component<any, SettingsState> {
</label> </label>
</div> </div>
</div> </div>
<div className="input-group mb-3">
<div className="form-check">
<input
className="form-check-input"
id="user-blur-nsfw"
type="checkbox"
checked={this.state.saveUserSettingsForm.blur_nsfw}
onChange={linkEvent(this, this.handleBlurNsfwChange)}
/>
<label className="form-check-label" htmlFor="user-blur-nsfw">
{I18NextService.i18n.t("blur_nsfw")}
</label>
</div>
</div>
<div className="input-group mb-3">
<div className="form-check">
<input
className="form-check-input"
id="user-auto-expand"
type="checkbox"
checked={this.state.saveUserSettingsForm.auto_expand}
onChange={linkEvent(this, this.handleAutoExpandChange)}
/>
<label className="form-check-label" htmlFor="user-auto-expand">
{I18NextService.i18n.t("auto_expand")}
</label>
</div>
</div>
<div className="input-group mb-3"> <div className="input-group mb-3">
<div className="form-check"> <div className="form-check">
<input <input
@ -1009,6 +1043,18 @@ export class Settings extends Component<any, SettingsState> {
); );
} }
handleBlurNsfwChange(i: Settings, event: any) {
i.setState(
s => ((s.saveUserSettingsForm.blur_nsfw = event.target.checked), s),
);
}
handleAutoExpandChange(i: Settings, event: any) {
i.setState(
s => ((s.saveUserSettingsForm.auto_expand = event.target.checked), s),
);
}
handleShowAvatarsChange(i: Settings, event: any) { handleShowAvatarsChange(i: Settings, event: any) {
const mui = UserService.Instance.myUserInfo; const mui = UserService.Instance.myUserInfo;
if (mui) { if (mui) {

View file

@ -169,6 +169,11 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
constructor(props: any, context: any) { constructor(props: any, context: any) {
super(props, context); super(props, context);
if (UserService.Instance.myUserInfo) {
this.state.imageExpanded =
UserService.Instance.myUserInfo.local_user_view.local_user.auto_expand;
}
this.handleEditPost = this.handleEditPost.bind(this); this.handleEditPost = this.handleEditPost.bind(this);
this.handleEditCancel = this.handleEditCancel.bind(this); this.handleEditCancel = this.handleEditCancel.bind(this);
} }
@ -297,6 +302,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
imgThumb(src: string) { imgThumb(src: string) {
const post_view = this.postView; const post_view = this.postView;
return ( return (
<PictrsImage <PictrsImage
src={src} src={src}