1
0
Fork 0
mirror of https://github.com/mastodon/mastodon.git synced 2024-08-20 21:08:15 -07:00

Refactor CW handling in an action (#31103)

This commit is contained in:
Claire 2024-07-22 18:03:58 +02:00 committed by GitHub
parent 03dea64b79
commit 9cb9427133
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 23 additions and 27 deletions

View file

@ -308,6 +308,21 @@ export function revealStatus(ids) {
}; };
} }
export function toggleStatusSpoilers(statusId) {
return (dispatch, getState) => {
const status = getState().statuses.get(statusId);
if (!status)
return;
if (status.get('hidden')) {
dispatch(revealStatus(statusId));
} else {
dispatch(hideStatus(statusId));
}
};
}
export function toggleStatusCollapse(id, isCollapsed) { export function toggleStatusCollapse(id, isCollapsed) {
return { return {
type: STATUS_COLLAPSE, type: STATUS_COLLAPSE,

View file

@ -36,8 +36,7 @@ import {
muteStatus, muteStatus,
unmuteStatus, unmuteStatus,
deleteStatus, deleteStatus,
hideStatus, toggleStatusSpoilers,
revealStatus,
toggleStatusCollapse, toggleStatusCollapse,
editStatus, editStatus,
translateStatus, translateStatus,
@ -223,11 +222,7 @@ const mapDispatchToProps = (dispatch, { intl, contextType }) => ({
}, },
onToggleHidden (status) { onToggleHidden (status) {
if (status.get('hidden')) { dispatch(toggleStatusSpoilers(status.get('id')));
dispatch(revealStatus(status.get('id')));
} else {
dispatch(hideStatus(status.get('id')));
}
}, },
onToggleCollapsed (status, isCollapsed) { onToggleCollapsed (status, isCollapsed) {

View file

@ -18,7 +18,7 @@ import ReplyIcon from '@/material-icons/400-24px/reply.svg?react';
import { replyCompose } from 'mastodon/actions/compose'; import { replyCompose } from 'mastodon/actions/compose';
import { markConversationRead, deleteConversation } from 'mastodon/actions/conversations'; import { markConversationRead, deleteConversation } from 'mastodon/actions/conversations';
import { openModal } from 'mastodon/actions/modal'; import { openModal } from 'mastodon/actions/modal';
import { muteStatus, unmuteStatus, revealStatus, hideStatus } from 'mastodon/actions/statuses'; import { muteStatus, unmuteStatus, toggleStatusSpoilers } from 'mastodon/actions/statuses';
import AttachmentList from 'mastodon/components/attachment_list'; import AttachmentList from 'mastodon/components/attachment_list';
import AvatarComposite from 'mastodon/components/avatar_composite'; import AvatarComposite from 'mastodon/components/avatar_composite';
import { IconButton } from 'mastodon/components/icon_button'; import { IconButton } from 'mastodon/components/icon_button';
@ -138,11 +138,7 @@ export const Conversation = ({ conversation, scrollKey, onMoveUp, onMoveDown })
}, [dispatch, lastStatus]); }, [dispatch, lastStatus]);
const handleShowMore = useCallback(() => { const handleShowMore = useCallback(() => {
if (lastStatus.get('hidden')) { dispatch(toggleStatusSpoilers(lastStatus.get('id')));
dispatch(revealStatus(lastStatus.get('id')));
} else {
dispatch(hideStatus(lastStatus.get('id')));
}
}, [dispatch, lastStatus]); }, [dispatch, lastStatus]);
if (!lastStatus) { if (!lastStatus) {

View file

@ -6,8 +6,7 @@ import {
toggleReblog, toggleReblog,
} from '../../../actions/interactions'; } from '../../../actions/interactions';
import { import {
hideStatus, toggleStatusSpoilers,
revealStatus,
} from '../../../actions/statuses'; } from '../../../actions/statuses';
import { makeGetNotification, makeGetStatus, makeGetReport } from '../../../selectors'; import { makeGetNotification, makeGetStatus, makeGetReport } from '../../../selectors';
import Notification from '../components/notification'; import Notification from '../components/notification';
@ -43,11 +42,7 @@ const mapDispatchToProps = dispatch => ({
}, },
onToggleHidden (status) { onToggleHidden (status) {
if (status.get('hidden')) { dispatch(toggleStatusSpoilers(status.get('id')));
dispatch(revealStatus(status.get('id')));
} else {
dispatch(hideStatus(status.get('id')));
}
}, },
}); });

View file

@ -22,8 +22,7 @@ import {
muteStatus, muteStatus,
unmuteStatus, unmuteStatus,
deleteStatus, deleteStatus,
hideStatus, toggleStatusSpoilers,
revealStatus,
} from '../../../actions/statuses'; } from '../../../actions/statuses';
import { deleteModal } from '../../../initial_state'; import { deleteModal } from '../../../initial_state';
import { makeGetStatus, makeGetPictureInPicture } from '../../../selectors'; import { makeGetStatus, makeGetPictureInPicture } from '../../../selectors';
@ -156,11 +155,7 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
}, },
onToggleHidden (status) { onToggleHidden (status) {
if (status.get('hidden')) { dispatch(toggleStatusSpoilers(status.get('id')));
dispatch(revealStatus(status.get('id')));
} else {
dispatch(hideStatus(status.get('id')));
}
}, },
}); });