Skip to content

Commit

Permalink
fix: useChannel instead of channel from livecollection (#139)
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/chat/components/ChatItem/index.tsx
  • Loading branch information
bonanaaaaaa authored and frankent committed Feb 9, 2024
1 parent f729824 commit 7c6d3a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/chat/components/ChatItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import useChatInfo from '~/chat/hooks/useChatInfo';

import { ChatItemLeft, Title, Avatar, ChatItemContainer, UnreadCount } from './styles';
import { useCustomComponent } from '~/core/providers/CustomComponentsProvider';
import useChannelSubscription from '~/social/hooks/useChannelSubscription';
import useChannel from '~/chat/hooks/useChannel';

function getNormalizedUnreadCount(channelUnreadCount: number) {
// Within this range the unread counter will show an actuall number
Expand All @@ -24,16 +26,22 @@ function getNormalizedUnreadCount(channelUnreadCount: number) {
}

interface ChatItemProps {
channel?: Amity.Channel;
channelId: string;
isSelected: boolean;
onSelect: ({ channelId, type }: { channelId: string; type: string }) => void;
}

const ChatItem = ({ channel, isSelected, onSelect }: ChatItemProps) => {
const { chatName, chatAvatar } = useChatInfo({ channel: channel || null });
const ChatItem = ({ channelId, isSelected, onSelect }: ChatItemProps) => {
const channel = useChannel(channelId);
const { chatName, chatAvatar } = useChatInfo({ channel });

const normalizedUnreadCount = getNormalizedUnreadCount(channel?.unreadCount || 0);

useChannelSubscription({
channelId: channel?.channelId,
shouldSubscribe: () => !!channel?.channelId,
});

return (
<ChatItemContainer
data-qa-anchor="chat-item"
Expand Down
2 changes: 1 addition & 1 deletion src/chat/components/RecentChat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const RecentChat = ({
channels.map((channel) => (
<ChatItem
key={channel.channelId}
channel={channel}
channelId={channel.channelId}
isSelected={selectedChannelId === channel.channelId}
onSelect={(data) => {
onChannelSelect?.(data);
Expand Down

0 comments on commit 7c6d3a0

Please sign in to comment.