diff --git a/CHANGELOG.md b/CHANGELOG.md index c687988c..de09cda8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Fix delete and report button colors. - Fix modal backgrounds missing in some menus. +- Reply is now a toggle. When you click/swipe to reply to the message you're already replying to, it's reset. ## 1.1.6 diff --git a/src/app/features/room/RoomTimeline.tsx b/src/app/features/room/RoomTimeline.tsx index 6b758c1a..6dad66fe 100644 --- a/src/app/features/room/RoomTimeline.tsx +++ b/src/app/features/room/RoomTimeline.tsx @@ -458,6 +458,8 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli const nicknames = useAtomValue(nicknamesAtom); const setReplyDraft = useSetAtom(roomIdToReplyDraftAtomFamily(room.roomId)); + const replyDraft = useAtomValue(roomIdToReplyDraftAtomFamily(room.roomId)); + const activeReplyId = replyDraft?.eventId; const powerLevels = usePowerLevelsContext(); const creators = useRoomCreators(room); @@ -1033,6 +1035,11 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli const triggerReply = useCallback( (replyId: string, startThread = false) => { + if (activeReplyId === replyId) { + setReplyDraft(undefined); + return; + } + const replyEvt = room.findEventById(replyId); if (!replyEvt) return; const editedReply = getEditedEvent(replyId, replyEvt, room.getUnfilteredTimelineSet()); @@ -1053,15 +1060,19 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli setTimeout(() => ReactEditor.focus(editor), 100); } }, - [room, setReplyDraft, editor] + [room, setReplyDraft, editor, activeReplyId] ); const handleReplyClick: MouseEventHandler = useCallback( (evt) => { const replyId = evt.currentTarget.getAttribute('data-event-id'); + if (!replyId) { + setReplyDraft(undefined); + return; + } if (replyId) triggerReply(replyId); }, - [triggerReply] + [triggerReply, setReplyDraft] ); const handleReactionToggle = useCallback( @@ -1143,6 +1154,7 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli senderId={senderId} senderDisplayName={senderDisplayName} onEditId={handleEdit} + activeReplyId={activeReplyId} reply={ replyEventId && ( void, delay = 300) { @@ -312,6 +313,7 @@ function MessageInternal( children, senderId, senderDisplayName, + activeReplyId, ...props }: MessageProps & { className?: string; children?: ReactNode }, ref: any @@ -518,9 +520,11 @@ function MessageInternal( }; const handleSwipeReply = () => { + const currentId = mEvent.getId(); + const targetId = activeReplyId === currentId ? null : currentId; const mockEvent = { currentTarget: { - getAttribute: (attr: string) => (attr === 'data-event-id' ? mEvent.getId() : null), + getAttribute: (attr: string) => (attr === 'data-event-id' ? targetId : null), }, } as unknown as React.MouseEvent; @@ -605,6 +609,9 @@ function MessageInternal( {!isThreadedMessage && ( { + if (activeReplyId === mEvent.getId()) { + ev.currentTarget.setAttribute('data-event-id', ''); + } onReplyClick(ev, true); setMobileOptionsOpen(false); }}