Skip to content

Commit 9c8150f

Browse files
authored
fix: hmr issue due to disconnect (#2169)
1 parent ec515b6 commit 9c8150f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

package/src/components/ChannelPreview/ChannelPreviewMessenger.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useEffect, useState } from 'react';
22
import { StyleSheet, View } from 'react-native';
33
import { TouchableOpacity } from 'react-native-gesture-handler';
44

@@ -17,6 +17,7 @@ import {
1717
ChannelsContextValue,
1818
useChannelsContext,
1919
} from '../../contexts/channelsContext/ChannelsContext';
20+
import { useChatContext } from '../../contexts/chatContext/ChatContext';
2021
import { useTheme } from '../../contexts/themeContext/ThemeContext';
2122
import type { DefaultStreamChatGenerics } from '../../types/types';
2223
import { vw } from '../../utils/utils';
@@ -127,12 +128,21 @@ const ChannelPreviewMessengerWithContext = <
127128
},
128129
} = useTheme();
129130

131+
const { client } = useChatContext<StreamChatGenerics>();
132+
130133
const displayName = useChannelPreviewDisplayName(
131134
channel,
132135
Math.floor(maxWidth / ((title.fontSize || styles.title.fontSize) / 2)),
133136
);
134137

135-
const isChannelMuted = channel.muteStatus().muted;
138+
const [isChannelMuted, setIsChannelMuted] = useState(() => channel.muteStatus().muted);
139+
140+
useEffect(() => {
141+
const handleEvent = () => setIsChannelMuted(channel.muteStatus().muted);
142+
143+
client.on('notification.channel_mutes_updated', handleEvent);
144+
return () => client.off('notification.channel_mutes_updated', handleEvent);
145+
}, []);
136146

137147
return (
138148
<TouchableOpacity

0 commit comments

Comments
 (0)