Created
August 24, 2023 10:19
-
-
Save tayfun/50d6329173a6699caec81b5196d87623 to your computer and use it in GitHub Desktop.
sendbird custom channel preview override
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useSendbirdStateContext } from "@sendbird/uikit-react"; | |
import ChannelPreview from "@sendbird/uikit-react/ChannelList/components/ChannelPreview"; | |
import SendbirdUIKitGlobal from 'SendbirdUIKitGlobal'; | |
interface CustomChannelPreviewInterface extends SendbirdUIKitGlobal.ChannelPreviewInterface { | |
startupId: number; | |
} | |
const CustomChannelPreview = (props:CustomChannelPreviewInterface) => { | |
const {channel, startupId, ...restProps} = props; | |
const sbState = useSendbirdStateContext(); | |
const currentUserId = sbState?.stores?.userStore?.user?.userId; | |
if (!channel.name || channel.name === "Group Channel") { | |
const defaultChannelTitle = (channel?.members || []) | |
.filter(({ userId }: {userId:string}) => userId !== currentUserId) | |
.map(({ nickname }: {nickname:string}) => (nickname || "")) | |
.join(', '); | |
const customChannelName = `${defaultChannelTitle} - Startup ${startupId}`; | |
channel.name = customChannelName; | |
} | |
return <ChannelPreview channel={channel} {...restProps} />; | |
}; | |
export default CustomChannelPreview; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment