Merge branch 'close-compose-modal' into 'develop'
Consistent behavior of compose modal close confirmation See merge request soapbox-pub/soapbox-fe!1758
This commit is contained in:
commit
7f99568c73
2 changed files with 4 additions and 5 deletions
|
@ -14,13 +14,11 @@ const messages = defineMessages({
|
||||||
confirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' },
|
confirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' },
|
||||||
});
|
});
|
||||||
|
|
||||||
const checkComposeContent = compose => {
|
export const checkComposeContent = compose => {
|
||||||
return [
|
return [
|
||||||
compose.text.length > 0,
|
compose.text.length > 0,
|
||||||
compose.spoiler_text.length > 0,
|
compose.spoiler_text.length > 0,
|
||||||
compose.media_attachments.size > 0,
|
compose.media_attachments.size > 0,
|
||||||
compose.in_reply_to !== null,
|
|
||||||
compose.quote !== null,
|
|
||||||
compose.poll !== null,
|
compose.poll !== null,
|
||||||
].some(check => check === true);
|
].some(check => check === true);
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
|
||||||
|
|
||||||
import { cancelReplyCompose } from 'soapbox/actions/compose';
|
import { cancelReplyCompose } from 'soapbox/actions/compose';
|
||||||
import { openModal, closeModal } from 'soapbox/actions/modals';
|
import { openModal, closeModal } from 'soapbox/actions/modals';
|
||||||
|
import { checkComposeContent } from 'soapbox/components/modal_root';
|
||||||
import { Modal } from 'soapbox/components/ui';
|
import { Modal } from 'soapbox/components/ui';
|
||||||
import { useAppDispatch, useAppSelector } from 'soapbox/hooks';
|
import { useAppDispatch, useAppSelector } from 'soapbox/hooks';
|
||||||
|
|
||||||
|
@ -23,13 +24,13 @@ const ComposeModal: React.FC<IComposeModal> = ({ onClose }) => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
const statusId = useAppSelector((state) => state.compose.id);
|
const statusId = useAppSelector((state) => state.compose.id);
|
||||||
const composeText = useAppSelector((state) => state.compose.text);
|
const hasComposeContent = useAppSelector((state) => checkComposeContent(state.compose));
|
||||||
const privacy = useAppSelector((state) => state.compose.privacy);
|
const privacy = useAppSelector((state) => state.compose.privacy);
|
||||||
const inReplyTo = useAppSelector((state) => state.compose.in_reply_to);
|
const inReplyTo = useAppSelector((state) => state.compose.in_reply_to);
|
||||||
const quote = useAppSelector((state) => state.compose.quote);
|
const quote = useAppSelector((state) => state.compose.quote);
|
||||||
|
|
||||||
const onClickClose = () => {
|
const onClickClose = () => {
|
||||||
if (composeText) {
|
if (hasComposeContent) {
|
||||||
dispatch(openModal('CONFIRM', {
|
dispatch(openModal('CONFIRM', {
|
||||||
icon: require('@tabler/icons/trash.svg'),
|
icon: require('@tabler/icons/trash.svg'),
|
||||||
heading: statusId
|
heading: statusId
|
||||||
|
|
Loading…
Reference in a new issue