File tree Expand file tree Collapse file tree 1 file changed +22
-8
lines changed
Expand file tree Collapse file tree 1 file changed +22
-8
lines changed Original file line number Diff line number Diff line change @@ -76,17 +76,31 @@ export const useFetchReactions = ({
7676 } ) ,
7777 ) ;
7878
79- [ 'reaction.new' , 'reaction.updated' ] . forEach ( ( eventType ) => {
80- listeners . push (
81- client . on ( eventType , ( event ) => {
82- const { reaction } = event ;
79+ listeners . push (
80+ client . on ( 'reaction.new' , ( event ) => {
81+ const { reaction } = event ;
82+
83+ if ( reaction && reaction . type === reactionType ) {
84+ setReactions ( ( prevReactions ) => [ reaction , ...prevReactions ] ) ;
85+ }
86+ } ) ,
87+ ) ;
8388
84- if ( reaction && reaction . type === reactionType ) {
89+ listeners . push (
90+ client . on ( 'reaction.updated' , ( event ) => {
91+ const { reaction } = event ;
92+
93+ if ( reaction ) {
94+ if ( reaction . type === reactionType ) {
8595 setReactions ( ( prevReactions ) => [ reaction , ...prevReactions ] ) ;
96+ } else {
97+ setReactions ( ( prevReactions ) =>
98+ prevReactions . filter ( ( r ) => r . user_id !== reaction . user_id ) ,
99+ ) ;
86100 }
87- } ) ,
88- ) ;
89- } ) ;
101+ }
102+ } ) ,
103+ ) ;
90104
91105 listeners . push (
92106 client . on ( 'reaction.deleted' , ( event ) => {
You can’t perform that action at this time.
0 commit comments