Skip to content

Commit

Permalink
[WiP] Reimplement sensitive checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire committed Feb 22, 2024
1 parent 5fd5075 commit 8b79fa1
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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 (
<div className='compose-form__sensitive-button'>
<label className={classNames('icon-button', { active })} title={intl.formatMessage(active ? messages.marked : messages.unmarked, { count: mediaCount })}>
<input
name='mark-sensitive'
type='checkbox'
checked={active}
onChange={handleClick}
disabled={disabled}
/>

<FormattedMessage
id='compose_form.sensitive.hide'
defaultMessage='{count, plural, one {Mark media as sensitive} other {Mark media as sensitive}}'
values={{ count: mediaCount }}
/>
</label>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -24,6 +26,8 @@ export default class UploadForm extends ImmutablePureComponent {
))}
</div>
)}

{!mediaIds.isEmpty() && <SensitiveButton />}
</>
);
}
Expand Down

0 comments on commit 8b79fa1

Please sign in to comment.