Add reaction popover, socket guards, dedupe reactions
Build a members lookup and enrich reaction groups with reactor info; introduce a ReactionPill component that shows a tabbed popover listing who reacted (with ability to remove your own reaction). Move reaction button into the new component and adapt styling/UX. Fix WebSocket handling in useChatSocket by adding a mounted guard to avoid handling events from torn-down sockets (addresses React StrictMode double-invoke issues) and avoid setting state after unmount. Prevent duplicate local reaction entries in ChatRoomPage by skipping "added" events when the same user/emoji reaction already exists.
This commit is contained in:
@@ -198,7 +198,12 @@ export default function ChatRoomPage() {
|
||||
if (m.id !== event.message_id) return m;
|
||||
let reactions = [...(m.reactions ?? [])] as typeof m.reactions;
|
||||
if (event.action === "added") {
|
||||
reactions = [...reactions, { id: -Date.now(), user: event.user_id, emoji: event.emoji, created_at: new Date().toISOString() } as never];
|
||||
const alreadyExists = reactions.some(
|
||||
(r) => (r.user as unknown as number) === event.user_id && r.emoji === event.emoji,
|
||||
);
|
||||
if (!alreadyExists) {
|
||||
reactions = [...reactions, { id: -Date.now(), user: event.user_id, emoji: event.emoji, created_at: new Date().toISOString() } as never];
|
||||
}
|
||||
} else if (event.action === "removed") {
|
||||
reactions = reactions.filter((r) => !((r.user as unknown as number) === event.user_id && r.emoji === event.emoji));
|
||||
} else if (event.action === "switched") {
|
||||
|
||||
Reference in New Issue
Block a user