ConversationView: Move deleteMessage to redux

This commit is contained in:
Scott Nonnenberg 2022-12-14 14:45:39 -08:00 committed by GitHub
parent 50d9b6e5e1
commit 7c86f02c7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 83 additions and 38 deletions

View file

@ -39,7 +39,10 @@ export type PropsData = {
} & Omit<MessagePropsData, 'renderingContext' | 'menu'>;
export type PropsActions = {
deleteMessage: (id: string) => void;
deleteMessage: (options: {
conversationId: string;
messageId: string;
}) => void;
deleteMessageForEveryone: (id: string) => void;
toggleForwardMessageModal: (id: string) => void;
reactToMessage: (
@ -233,6 +236,7 @@ export function TimelineMessage(props: Props): JSX.Element {
const handleReact = canReact ? () => toggleReactionPicker() : undefined;
const [hasDOEConfirmation, setHasDOEConfirmation] = useState(false);
const [hasDeleteConfirmation, setHasDeleteConfirmation] = useState(false);
const toggleReactionPickerKeyboard = useToggleReactionPicker(
handleReact || noop
@ -266,6 +270,26 @@ export function TimelineMessage(props: Props): JSX.Element {
{i18n('deleteForEveryoneWarning')}
</ConfirmationDialog>
)}
{hasDeleteConfirmation && (
<ConfirmationDialog
actions={[
{
action: () =>
deleteMessage({
conversationId,
messageId: id,
}),
style: 'negative',
text: i18n('delete'),
},
]}
dialogName="TimelineMessage/deleteMessage"
i18n={i18n}
onClose={() => setHasDeleteConfirmation(false)}
>
{i18n('deleteWarning')}
</ConfirmationDialog>
)}
<Message
{...props}
renderingContext="conversation/TimelineItem"
@ -330,7 +354,7 @@ export function TimelineMessage(props: Props): JSX.Element {
: undefined
}
onForward={canForward ? () => toggleForwardMessageModal(id) : undefined}
onDeleteForMe={() => deleteMessage(id)}
onDeleteForMe={() => setHasDeleteConfirmation(true)}
onDeleteForEveryone={
canDeleteForEveryone ? () => setHasDOEConfirmation(true) : undefined
}