Settings: Move sensitive content toggle to Privacy section (#1202)

This commit is contained in:
Alexander Zinchuk 2021-06-23 11:22:24 +03:00
parent d2ca29e961
commit 6b8bfdf3ab
2 changed files with 33 additions and 28 deletions

View File

@ -35,16 +35,14 @@ type StateProps = Pick<ISettings, (
'shouldAutoPlayGifs' |
'shouldAutoPlayVideos' |
'shouldSuggestStickers' |
'shouldLoopStickers' |
'isSensitiveEnabled' |
'canChangeSensitive'
'shouldLoopStickers'
)> & {
stickerSetIds?: string[];
stickerSetsById?: Record<string, ApiStickerSet>;
};
type DispatchProps = Pick<GlobalActions, (
'setSettingOption' | 'loadStickerSets' | 'loadAddedStickers' | 'loadContentSettings' | 'updateContentSettings'
'setSettingOption' | 'loadStickerSets' | 'loadAddedStickers'
)>;
const ANIMATION_LEVEL_OPTIONS = [
@ -68,13 +66,9 @@ const SettingsGeneral: FC<OwnProps & StateProps & DispatchProps> = ({
shouldAutoPlayVideos,
shouldSuggestStickers,
shouldLoopStickers,
isSensitiveEnabled,
canChangeSensitive,
setSettingOption,
loadStickerSets,
loadAddedStickers,
loadContentSettings,
updateContentSettings,
}) => {
// eslint-disable-next-line no-null/no-null
const stickerSettingsRef = useRef<HTMLDivElement>(null);
@ -95,8 +89,7 @@ const SettingsGeneral: FC<OwnProps & StateProps & DispatchProps> = ({
useEffect(() => {
loadStickerSets();
loadContentSettings();
}, [loadContentSettings, loadStickerSets]);
}, [loadStickerSets]);
useEffect(() => {
if (stickerSetIds && stickerSetIds.length) {
@ -176,19 +169,6 @@ const SettingsGeneral: FC<OwnProps & StateProps & DispatchProps> = ({
</div>
)}
<div className="settings-item">
<h4 className="settings-item-header" dir={lang.isRtl ? 'rtl' : undefined}>
{lang('lng_settings_sensitive_title')}
</h4>
<Checkbox
label={lang('lng_settings_sensitive_disable_filtering')}
subLabel={lang('lng_settings_sensitive_about')}
checked={Boolean(isSensitiveEnabled)}
disabled={!canChangeSensitive}
onCheck={updateContentSettings}
/>
</div>
<div className="settings-item">
<h4 className="settings-item-header" dir={lang.isRtl ? 'rtl' : undefined}>{lang('AutoDownloadMedia')}</h4>
@ -288,6 +268,6 @@ export default memo(withGlobal<OwnProps>(
};
},
(setGlobal, actions): DispatchProps => pick(actions, [
'setSettingOption', 'loadStickerSets', 'loadAddedStickers', 'loadContentSettings', 'updateContentSettings',
'setSettingOption', 'loadStickerSets', 'loadAddedStickers',
]),
)(SettingsGeneral));

View File

@ -8,6 +8,7 @@ import { pick } from '../../../util/iteratees';
import useLang from '../../../hooks/useLang';
import ListItem from '../../ui/ListItem';
import Checkbox from '../../ui/Checkbox';
type OwnProps = {
onScreenSelect: (screen: SettingsScreens) => void;
@ -17,6 +18,8 @@ type StateProps = {
hasPassword?: boolean;
blockedCount: number;
sessionsCount: number;
isSensitiveEnabled?: boolean;
canChangeSensitive?: boolean;
visibilityPrivacyPhoneNumber?: PrivacyVisibility;
visibilityPrivacyLastSeen?: PrivacyVisibility;
visibilityPrivacyProfilePhoto?: PrivacyVisibility;
@ -24,13 +27,17 @@ type StateProps = {
visibilityPrivacyGroupChats?: PrivacyVisibility;
};
type DispatchProps = Pick<GlobalActions, 'loadBlockedContacts' | 'loadAuthorizations' | 'loadPrivacySettings'>;
type DispatchProps = Pick<GlobalActions, (
'loadBlockedContacts' | 'loadAuthorizations' | 'loadPrivacySettings' | 'loadContentSettings' | 'updateContentSettings'
)>;
const SettingsPrivacy: FC<OwnProps & StateProps & DispatchProps> = ({
onScreenSelect,
hasPassword,
blockedCount,
sessionsCount,
isSensitiveEnabled,
canChangeSensitive,
visibilityPrivacyPhoneNumber,
visibilityPrivacyLastSeen,
visibilityPrivacyProfilePhoto,
@ -39,12 +46,15 @@ const SettingsPrivacy: FC<OwnProps & StateProps & DispatchProps> = ({
loadPrivacySettings,
loadBlockedContacts,
loadAuthorizations,
loadContentSettings,
updateContentSettings,
}) => {
useEffect(() => {
loadBlockedContacts();
loadAuthorizations();
loadPrivacySettings();
}, [loadBlockedContacts, loadAuthorizations, loadPrivacySettings]);
loadContentSettings();
}, [loadBlockedContacts, loadAuthorizations, loadPrivacySettings, loadContentSettings]);
const lang = useLang();
@ -169,6 +179,19 @@ const SettingsPrivacy: FC<OwnProps & StateProps & DispatchProps> = ({
</div>
</ListItem>
</div>
<div className="settings-item">
<h4 className="settings-item-header" dir={lang.isRtl ? 'rtl' : undefined}>
{lang('lng_settings_sensitive_title')}
</h4>
<Checkbox
label={lang('lng_settings_sensitive_disable_filtering')}
subLabel={lang('lng_settings_sensitive_about')}
checked={Boolean(isSensitiveEnabled)}
disabled={!canChangeSensitive}
onCheck={updateContentSettings}
/>
</div>
</div>
);
};
@ -177,7 +200,7 @@ export default memo(withGlobal<OwnProps>(
(global): StateProps => {
const {
settings: {
byKey: { hasPassword },
byKey: { hasPassword, isSensitiveEnabled, canChangeSensitive },
privacy,
},
blocked,
@ -188,6 +211,8 @@ export default memo(withGlobal<OwnProps>(
hasPassword,
blockedCount: blocked.totalCount,
sessionsCount: activeSessions.length,
isSensitiveEnabled,
canChangeSensitive,
visibilityPrivacyPhoneNumber: privacy.phoneNumber && privacy.phoneNumber.visibility,
visibilityPrivacyLastSeen: privacy.lastSeen && privacy.lastSeen.visibility,
visibilityPrivacyProfilePhoto: privacy.profilePhoto && privacy.profilePhoto.visibility,
@ -196,6 +221,6 @@ export default memo(withGlobal<OwnProps>(
};
},
(setGlobal, actions): DispatchProps => pick(actions, [
'loadBlockedContacts', 'loadAuthorizations', 'loadPrivacySettings',
'loadBlockedContacts', 'loadAuthorizations', 'loadPrivacySettings', 'loadContentSettings', 'updateContentSettings',
]),
)(SettingsPrivacy));