[Glitch] Refactor CW handling in an action

Port 9cb9427133 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
shrike
Claire 2024-07-22 18:03:58 +02:00
parent f13a231b39
commit 643b1ef3e9
3 changed files with 19 additions and 13 deletions

View File

@ -309,6 +309,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) {
return {
type: STATUS_COLLAPSE,

View File

@ -28,8 +28,7 @@ import {
muteStatus,
unmuteStatus,
deleteStatus,
hideStatus,
revealStatus,
toggleStatusSpoilers,
editStatus,
translateStatus,
undoStatusTranslation,
@ -234,11 +233,7 @@ const mapDispatchToProps = (dispatch, { intl, contextType }) => ({
},
onToggleHidden (status) {
if (status.get('hidden')) {
dispatch(revealStatus(status.get('id')));
} else {
dispatch(hideStatus(status.get('id')));
}
dispatch(toggleStatusSpoilers(status.get('id')));
},
deployPictureInPicture (status, type, mediaProps) {

View File

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