From 9fd75faa16c975152dfa4c35ab1f4891aba8ae96 Mon Sep 17 00:00:00 2001 From: Domenic Horner Date: Tue, 8 Aug 2023 01:48:55 +0800 Subject: [PATCH] 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 --- src/assets/css/main.css | 14 +++++- src/shared/components/common/pictrs-image.tsx | 13 +++++- .../components/community/community-link.tsx | 4 +- src/shared/components/person/settings.tsx | 46 +++++++++++++++++++ src/shared/components/post/post-listing.tsx | 6 +++ 5 files changed, 80 insertions(+), 3 deletions(-) diff --git a/src/assets/css/main.css b/src/assets/css/main.css index 36566b9b..f1e0c4d6 100644 --- a/src/assets/css/main.css +++ b/src/assets/css/main.css @@ -251,7 +251,7 @@ hr { flex: 1; } -.img-blur { +.img-blur-thumb { filter: blur(10px); -webkit-filter: blur(10px); -moz-filter: blur(10px); @@ -259,6 +259,18 @@ hr { -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 { max-height: 90vh; } diff --git a/src/shared/components/common/pictrs-image.tsx b/src/shared/components/common/pictrs-image.tsx index f1285129..ab22db0f 100644 --- a/src/shared/components/common/pictrs-image.tsx +++ b/src/shared/components/common/pictrs-image.tsx @@ -1,6 +1,8 @@ import classNames from "classnames"; import { Component } from "inferno"; +import { UserService } from "../../services"; + const iconThumbnailSize = 96; const thumbnailSize = 256; @@ -21,6 +23,14 @@ export class PictrsImage extends Component { } 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 ( @@ -38,7 +48,8 @@ export class PictrsImage extends Component { this.props.thumbnail && !this.props.icon && !this.props.banner, "img-expanded slight-radius": !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, "ms-2 mb-0 rounded-circle object-fit-cover avatar-overlay": this.props.iconOverlay, diff --git a/src/shared/components/community/community-link.tsx b/src/shared/components/community/community-link.tsx index 77accf66..83194caa 100644 --- a/src/shared/components/community/community-link.tsx +++ b/src/shared/components/community/community-link.tsx @@ -58,12 +58,14 @@ export class CommunityLink extends Component { avatarAndName(displayName: string) { const icon = this.props.community.icon; + const nsfw = this.props.community.nsfw; + return ( <> {!this.props.hideAvatar && !this.props.community.removed && showAvatars() && - icon && } + icon && } {displayName} ); diff --git a/src/shared/components/person/settings.tsx b/src/shared/components/person/settings.tsx index 659c77c2..7576a22a 100644 --- a/src/shared/components/person/settings.tsx +++ b/src/shared/components/person/settings.tsx @@ -54,6 +54,8 @@ interface SettingsState { // TODO redo these forms saveUserSettingsForm: { show_nsfw?: boolean; + blur_nsfw?: boolean; + auto_expand?: boolean; theme?: string; default_sort_type?: SortType; default_listing_type?: ListingType; @@ -177,6 +179,8 @@ export class Settings extends Component { const { local_user: { show_nsfw, + blur_nsfw, + auto_expand, theme, default_sort_type, default_listing_type, @@ -206,6 +210,8 @@ export class Settings extends Component { saveUserSettingsForm: { ...this.state.saveUserSettingsForm, show_nsfw, + blur_nsfw, + auto_expand, theme: theme ?? "browser", default_sort_type, default_listing_type, @@ -665,6 +671,34 @@ export class Settings extends Component { +
+
+ + +
+
+
+
+ + +
+
{ ); } + 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) { const mui = UserService.Instance.myUserInfo; if (mui) { diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx index c9266350..95d1a468 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -169,6 +169,11 @@ export class PostListing extends Component { constructor(props: any, context: any) { 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.handleEditCancel = this.handleEditCancel.bind(this); } @@ -297,6 +302,7 @@ export class PostListing extends Component { imgThumb(src: string) { const post_view = this.postView; + return (