feat: make replies toggle replies
This commit is contained in:
1 parent
f4cc4d51de
commit
5aeb8a9800
3 files changed
+25
-3
No files matched your search
@@ -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
|
||||
|
||||
|
||||
@@ -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<HTMLButtonElement> = 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 && (
|
||||
<Reply
|
||||
@@ -1225,6 +1237,7 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli
|
||||
onReactionToggle={handleReactionToggle}
|
||||
onEditId={handleEdit}
|
||||
senderId={senderId}
|
||||
activeReplyId={activeReplyId}
|
||||
senderDisplayName={senderDisplayName}
|
||||
reply={
|
||||
replyEventId && (
|
||||
@@ -1339,6 +1352,7 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli
|
||||
onReplyClick={handleReplyClick}
|
||||
onReactionToggle={handleReactionToggle}
|
||||
senderId={senderId}
|
||||
activeReplyId={activeReplyId}
|
||||
senderDisplayName={senderDisplayName}
|
||||
reactions={
|
||||
reactionRelations && (
|
||||
|
||||
@@ -228,6 +228,7 @@ export type MessageProps = {
|
||||
senderId: string;
|
||||
senderDisplayName: string;
|
||||
content?: string;
|
||||
activeReplyId?: string | null;
|
||||
};
|
||||
|
||||
function useMobileDoubleTap(callback: () => 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<HTMLButtonElement>;
|
||||
|
||||
@@ -605,6 +609,9 @@ function MessageInternal(
|
||||
{!isThreadedMessage && (
|
||||
<IconButton
|
||||
onClick={(ev) => {
|
||||
if (activeReplyId === mEvent.getId()) {
|
||||
ev.currentTarget.setAttribute('data-event-id', '');
|
||||
}
|
||||
onReplyClick(ev, true);
|
||||
setMobileOptionsOpen(false);
|
||||
}}
|
||||
|
||||
Reference in new issue
Block a user