From 8b79fa17e1c65719effd978303de07d3d7ee061c Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 22 Feb 2024 23:24:23 +0100 Subject: [PATCH] [WiP] Reimplement sensitive checkbox --- .../compose/components/sensitive_button.jsx | 57 +++++++++++++++++++ .../compose/components/upload_form.jsx | 4 ++ 2 files changed, 61 insertions(+) create mode 100644 app/javascript/flavours/glitch/features/compose/components/sensitive_button.jsx diff --git a/app/javascript/flavours/glitch/features/compose/components/sensitive_button.jsx b/app/javascript/flavours/glitch/features/compose/components/sensitive_button.jsx new file mode 100644 index 00000000000000..37debf9dd76728 --- /dev/null +++ b/app/javascript/flavours/glitch/features/compose/components/sensitive_button.jsx @@ -0,0 +1,57 @@ +import { useCallback } from 'react'; + +import { useIntl, defineMessages, FormattedMessage } from 'react-intl'; + +import classNames from 'classnames'; + +import { changeComposeSensitivity } from 'flavours/glitch/actions/compose'; +import { useAppSelector, useAppDispatch } from 'flavours/glitch/store'; + +const messages = defineMessages({ + marked: { + id: 'compose_form.sensitive.marked', + defaultMessage: '{count, plural, one {Media is marked as sensitive} other {Media is marked as sensitive}}', + }, + unmarked: { + id: 'compose_form.sensitive.unmarked', + defaultMessage: '{count, plural, one {Media is not marked as sensitive} other {Media is not marked as sensitive}}', + }, +}); + +export const SensitiveButton = () => { + const intl = useIntl(); + + const spoilersAlwaysOn = useAppSelector((state) => state.getIn(['local_settings', 'always_show_spoilers_field'])); + const spoilerText = useAppSelector((state) => state.getIn(['compose', 'spoiler_text'])); + const sensitive = useAppSelector((state) => state.getIn(['compose', 'sensitive'])); + const disabled = useAppSelector((state) => state.getIn(['compose', 'spoiler'])); + const mediaCount = useAppSelector((state) => state.getIn(['compose', 'media_attachments']).size); + + const active = sensitive || (spoilersAlwaysOn && spoilerText && spoilerText.length > 0); + + const dispatch = useAppDispatch(); + + const handleClick = useCallback(() => { + dispatch(changeComposeSensitivity()); + }, [dispatch]); + + return ( +
+ +
+ ); +}; diff --git a/app/javascript/flavours/glitch/features/compose/components/upload_form.jsx b/app/javascript/flavours/glitch/features/compose/components/upload_form.jsx index 46bac7823b8d16..5c6406c3bacacc 100644 --- a/app/javascript/flavours/glitch/features/compose/components/upload_form.jsx +++ b/app/javascript/flavours/glitch/features/compose/components/upload_form.jsx @@ -4,6 +4,8 @@ import ImmutablePureComponent from 'react-immutable-pure-component'; import UploadContainer from '../containers/upload_container'; import UploadProgressContainer from '../containers/upload_progress_container'; +import { SensitiveButton } from './sensitive_button'; + export default class UploadForm extends ImmutablePureComponent { static propTypes = { @@ -24,6 +26,8 @@ export default class UploadForm extends ImmutablePureComponent { ))} )} + + {!mediaIds.isEmpty() && } ); }