1
1
import { isEmpty , isEqual } from 'lodash' ;
2
2
import React , { ReactElement , useEffect , useState } from 'react' ;
3
- import { useDispatch } from 'react-redux' ;
3
+ import { useDispatch , useSelector } from 'react-redux' ;
4
4
import styled from 'styled-components' ;
5
5
import { Data } from '../../data/data' ;
6
6
import { useMessageReactsPropsById , useWeAreModerator } from '../../hooks/useParamSelector' ;
@@ -11,6 +11,7 @@ import {
11
11
updateReactListModal ,
12
12
updateUserDetailsModal ,
13
13
} from '../../state/ducks/modalDialog' ;
14
+ import { getSelectedConversationIsPublic } from '../../state/selectors/conversations' ;
14
15
import { SortedReactionList } from '../../types/Reaction' ;
15
16
import { nativeEmojiData } from '../../util/emoji' ;
16
17
import { Reactions } from '../../util/reactions' ;
@@ -169,6 +170,7 @@ const StyledCountText = styled.p`
169
170
color: var(--color-text);
170
171
}
171
172
` ;
173
+ // tslint:disable: use-simple-attributes
172
174
173
175
const CountText = ( { count, emoji } : { count : number ; emoji : string } ) => {
174
176
return (
@@ -226,6 +228,7 @@ export const ReactListModal = (props: Props): ReactElement => {
226
228
const [ senders , setSenders ] = useState < Array < string > > ( [ ] ) ;
227
229
228
230
const msgProps = useMessageReactsPropsById ( messageId ) ;
231
+ const isPublic = useSelector ( getSelectedConversationIsPublic ) ;
229
232
const weAreModerator = useWeAreModerator ( msgProps ?. convoId ) ;
230
233
const me = UserUtils . getOurPubKeyStrFromCache ( ) ;
231
234
@@ -245,7 +248,8 @@ export const ReactListModal = (props: Props): ReactElement => {
245
248
if (
246
249
reactions &&
247
250
reactions . length > 0 &&
248
- ( msgProps ?. sortedReacts === [ ] || msgProps ?. sortedReacts === undefined )
251
+ ( ( msgProps ?. sortedReacts && msgProps . sortedReacts . length === 0 ) ||
252
+ msgProps ?. sortedReacts === undefined )
249
253
) {
250
254
setReactions ( [ ] ) ;
251
255
}
@@ -259,7 +263,11 @@ export const ReactListModal = (props: Props): ReactElement => {
259
263
if ( _senders . length > 0 ) {
260
264
_senders = handleSenders ( _senders , me ) ;
261
265
}
262
- setSenders ( _senders ) ;
266
+
267
+ // make sure to deep compare here otherwise we get stuck in a ever rendering look (only happens when we are one of the reactor)
268
+ if ( ! isEqual ( _senders , senders ) ) {
269
+ setSenders ( _senders ) ;
270
+ }
263
271
}
264
272
265
273
if ( senders . length > 0 && ( ! reactionsMap [ currentReact ] ?. senders || isEmpty ( _senders ) ) ) {
@@ -284,8 +292,6 @@ export const ReactListModal = (props: Props): ReactElement => {
284
292
return < > </ > ;
285
293
}
286
294
287
- const { isPublic } = msgProps ;
288
-
289
295
const handleSelectedReaction = ( emoji : string ) : boolean => {
290
296
return currentReact === emoji ;
291
297
} ;
0 commit comments