Skip to content

Commit 3662a4c

Browse files
authored
chore: upgrade stream-chat-react to v13.1.0 (#111)
1 parent be590ae commit 3662a4c

80 files changed

Lines changed: 1138 additions & 1100 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

gaming-livestream/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
"emoji-mart": "^5.5.2",
1111
"react": "^19.0.0",
1212
"react-dom": "^19.0.0",
13-
"stream-chat": "^8.56.0",
14-
"stream-chat-react": "^12.12.0"
13+
"stream-chat": "^9.6.0",
14+
"stream-chat-react": "^13.1.0"
1515
},
1616
"devDependencies": {
1717
"@types/react": "^19.0.8",
1818
"@types/react-dom": "^19.0.3",
1919
"react-scripts": "^5.0.1",
2020
"sass": "^1.77.7",
21-
"typescript": "^4.8.4"
21+
"typescript": "^5.8.3"
2222
},
2323
"scripts": {
2424
"start": "react-scripts start",

gaming-livestream/src/components/Chat/ChannelContainer.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import {MessageTimestampController} from "../../context/MessageTimestampControll
44
import {GamingChatInner} from "./GamingChatInner";
55
import {Channel, useChatContext} from "stream-chat-react";
66
import React, {useEffect} from "react";
7-
import {StreamChatType} from "../../types";
87

98

109
export const ChannelContainer = () => {
11-
const {channel, client, setActiveChannel} = useChatContext<StreamChatType>();
10+
const {channel, client, setActiveChannel} = useChatContext();
1211
useEffect(() => {
1312
const loadChat = async () => {
1413
const channel = client.channel('gaming', 'gaming-demo', { name: 'Gaming Demo' });

gaming-livestream/src/components/Chat/GamingChatInner.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, {useCallback} from 'react';
2-
import {logChatPromiseExecution} from 'stream-chat';
3-
import {MessageInput, MessageList, MessageToSend, useChannelActionContext, Window} from 'stream-chat-react';
2+
import {type LocalMessage, logChatPromiseExecution, type Message, type SendMessageOptions} from 'stream-chat';
3+
import {MessageInput, MessageList, useChannelActionContext, Window} from 'stream-chat-react';
44

55
import {GamingChatHeader} from './GamingChatHeader';
66
import {GamingMessage} from './GamingMessage';
@@ -10,8 +10,6 @@ import {GamingThread} from './GamingThread';
1010
import {useLayoutController} from '../../context/LayoutController';
1111
import {useMessageTimestamp} from "../../context/MessageTimestampController";
1212

13-
import type {StreamChatType} from '../../types';
14-
1513
const NOTIFICATION_TEXT_FOR_COMMAND: Record<string, string> = {
1614
'/ban': 'User banned',
1715
'/flag': 'User flagged',
@@ -33,10 +31,15 @@ export const GamingChatInner = () => {
3331
const { publishAppNotification } = useLayoutController();
3432
const {timestampEnabled, toggleTimestamp} = useMessageTimestamp();
3533

36-
const overrideSubmitHandler = useCallback((message: MessageToSend<StreamChatType>) => {
34+
const overrideSubmitHandler = useCallback(({localMessage, message, sendOptions}: {
35+
cid: string;
36+
localMessage: LocalMessage;
37+
message: Message;
38+
sendOptions: SendMessageOptions;
39+
}) => {
3740
const { text } = message;
3841
publishAppNotification(getNotificationText(text))
39-
const sendMessagePromise = sendMessage(message);
42+
const sendMessagePromise = sendMessage({localMessage, message, options: sendOptions});
4043
logChatPromiseExecution(sendMessagePromise, 'send message');
4144
}, [publishAppNotification, sendMessage]);
4245

@@ -50,7 +53,8 @@ export const GamingChatInner = () => {
5053
<MessageList Message={GamingMessage} />
5154
<MessageInput
5255
focus
53-
grow
56+
minRows={1}
57+
maxRows={8}
5458
Input={GamingMessageInput}
5559
overrideSubmitHandler={overrideSubmitHandler}
5660
/>

gaming-livestream/src/components/Chat/GamingMessage.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ import ReactionUpVote from '../../assets/icons/ReactionUpVote';
1010
import {getColor} from '../../assets/data';
1111

1212
import {TimestampContextValue, useMessageTimestamp} from "../../context/MessageTimestampController";
13+
import type {LocalMessage} from "stream-chat";
1314

14-
import type {StreamMessage} from 'stream-chat-react/dist/context/ChannelStateContext';
15-
import type {StreamChatType} from '../../types';
16-
17-
const getTimeStamp = (messageCreatedAt?: StreamMessage<StreamChatType>['created_at']) => {
15+
const getTimeStamp = (messageCreatedAt?: LocalMessage['created_at']) => {
1816
if (!messageCreatedAt) return '';
1917

2018
const createdAt = new Date(messageCreatedAt);
@@ -91,10 +89,10 @@ const MessageActions = ({downVote, upVote, onOpenThread}: MessageActionsProps) =
9189

9290
type ReactionListProps = VotingStatsProps
9391
& Pick<MessageActionsProps, 'onOpenThread'>
94-
& Pick<StreamMessage<StreamChatType>, 'reply_count'>;
92+
& Pick<LocalMessage, 'reply_count'>;
9593

9694
const ReactionList = ({upVotes, downVotes, onOpenThread}: ReactionListProps) => {
97-
const {message} = useMessageContext<StreamChatType>();
95+
const {message} = useMessageContext();
9896
return (
9997
<div className='custom-message__reaction-list'>
10098
<VotingStats upVotes={upVotes} downVotes={downVotes}/>
@@ -108,7 +106,7 @@ const ReactionList = ({upVotes, downVotes, onOpenThread}: ReactionListProps) =>
108106
}
109107

110108
type MessageContentProps = {color?: string}
111-
& Pick<MessageContextValue<StreamChatType>, 'message' | 'handleAction'>
109+
& Pick<MessageContextValue, 'message' | 'handleAction'>
112110
& Pick<TimestampContextValue, 'timestampEnabled'>;
113111

114112
const MessageContent = ({color, message, handleAction, timestampEnabled}: MessageContentProps) => {
@@ -132,8 +130,8 @@ const MessageContent = ({color, message, handleAction, timestampEnabled}: Messag
132130
}
133131

134132
export const GamingMessage = () => {
135-
const {openThread} = useChannelActionContext<StreamChatType>();
136-
const {handleAction, message} = useMessageContext<StreamChatType>();
133+
const {openThread} = useChannelActionContext();
134+
const {handleAction, message} = useMessageContext();
137135
const {timestampEnabled} = useMessageTimestamp();
138136
const [downVotes, setDownVotes] = useState(0);
139137
const [upVotes, setUpVotes] = useState(0);

gaming-livestream/src/components/Chat/GamingMessageInput.tsx

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
import React from 'react';
22
import {
3-
ChatAutoComplete,
3+
TextareaComposer,
44
useChannelStateContext,
5+
useMessageComposerHasSendableData,
56
useMessageInputContext,
67
useTypingContext,
78
} from 'stream-chat-react';
8-
import { EmojiPicker } from 'stream-chat-react/emojis';
9+
import {EmojiPicker} from 'stream-chat-react/emojis';
910

1011
import SendIcon from '../../assets/icons/SendIcon';
1112
import StarIcon from '../../assets/icons/StarIcon';
1213
import EmojiIcon from '../../assets/icons/EmojiIcon';
1314

14-
import { useLayoutController } from '../../context/LayoutController';
15-
16-
import type { StreamChatType } from '../../types';
15+
import {useLayoutController} from '../../context/LayoutController';
1716

1817
const TypingIndicator = () => (
1918
<div className='typing-indicator'>
@@ -26,16 +25,29 @@ const TypingIndicator = () => (
2625
</div>
2726
);
2827

28+
const SendMessageButton = () => {
29+
const {handleSubmit} = useMessageInputContext();
30+
const hasSendableData = useMessageComposerHasSendableData();
31+
return (
32+
<button
33+
className='send-message-button'
34+
disabled={!hasSendableData}
35+
onClick={handleSubmit}
36+
>
37+
<SendIcon/>
38+
</button>
39+
);
40+
};
41+
2942
export const GamingMessageInput = React.memo(() => {
3043
const { showUpgradePanel } = useLayoutController();
31-
const { thread } = useChannelStateContext<StreamChatType>();
32-
const { typing } = useTypingContext<StreamChatType>();
33-
const messageInput = useMessageInputContext<StreamChatType>();
44+
const { thread } = useChannelStateContext();
45+
const { typing } = useTypingContext();
3446

3547
return (
3648
<div className='channel-footer'>
3749
<div className='channel-footer__top'>
38-
<ChatAutoComplete rows={1} placeholder='Say something' />
50+
<TextareaComposer rows={1} placeholder='Say something' />
3951
{!thread && (
4052
<EmojiPicker
4153
popperOptions={{ placement: 'top-end', strategy: 'fixed' }}
@@ -51,13 +63,7 @@ export const GamingMessageInput = React.memo(() => {
5163
<p>68</p>
5264
</button>
5365
{typing && !!Object.keys(typing).length && <TypingIndicator />}
54-
<button
55-
className='send-message-button'
56-
disabled={!messageInput.text}
57-
onClick={messageInput.handleSubmit}
58-
>
59-
<SendIcon />
60-
</button>
66+
<SendMessageButton/>
6167
</div>
6268
</div>
6369
);

gaming-livestream/src/components/Chat/GamingThreadHeader.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import type { MouseEventHandler } from 'react';
22

33
import type { ThreadHeaderProps } from 'stream-chat-react';
4-
import type { StreamChatType } from '../../types';
54

6-
type GamingThreadHeaderProps = Pick<ThreadHeaderProps<StreamChatType>, 'closeThread' | 'thread'>
5+
type GamingThreadHeaderProps = Pick<ThreadHeaderProps, 'closeThread' | 'thread'>
76

87
export const GamingThreadHeader = ({ closeThread, thread }: GamingThreadHeaderProps) => {
98
const onCloseThread: MouseEventHandler<HTMLButtonElement> = (event) => {

gaming-livestream/src/components/Chat/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {useChecklist} from '../../hooks/useChecklistTasks';
1313

1414
import {useConnectUser} from '../../hooks/useConnectUser';
1515
import {useLayoutController} from '../../context/LayoutController';
16-
import type {StreamChatType} from '../../types';
1716
import {ChannelContainer} from "./ChannelContainer";
1817

1918
init({ data });
@@ -32,7 +31,7 @@ const userToConnect = {
3231

3332
export const GamingChat = () => {
3433
const { memberListVisible, popUpText, upgradePanelVisible, chatVisible } = useLayoutController();
35-
const chatClient = useConnectUser<StreamChatType>(apiKey!, userToConnect, userToken);
34+
const chatClient = useConnectUser(apiKey!, userToConnect, userToken);
3635
useChecklist({ chatClient, targetOrigin });
3736

3837
if (!chatClient) return null;

gaming-livestream/src/hooks/useChecklistTasks.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ import { useEffect } from 'react';
22

33
import type { Event, StreamChat } from 'stream-chat';
44

5-
import type { StreamChatType } from '../types';
6-
7-
85
const notifyParent = (parent: string) => (message: any) => {
96
window.parent.postMessage(message, parent);
107
};
@@ -22,7 +19,7 @@ const [REACT_TO_MESSAGE, RUN_GIPHY, SEND_YOUTUBE, DRAG_DROP, START_THREAD, SEND_
2219
];
2320

2421
type ChecklistTaskProps = {
25-
chatClient: StreamChat<StreamChatType> | null;
22+
chatClient: StreamChat | null;
2623
targetOrigin?: string;
2724
};
2825

@@ -34,7 +31,7 @@ export const useChecklist = (props: ChecklistTaskProps): void => {
3431
const notify = notifyParent(targetOrigin);
3532

3633
const handleNewEvent = (
37-
props: Event<StreamChatType>,
34+
props: Event,
3835
) => {
3936
const { message, type } = props;
4037

gaming-livestream/src/hooks/useConnectUser.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { useEffect, useState } from 'react';
22
import {
3-
DefaultGenerics,
4-
ExtendableGenerics,
53
OwnUserResponse,
64
StreamChat,
75
TokenOrProvider,
@@ -16,14 +14,14 @@ import {
1614
* @param userToConnect the user information.
1715
* @param userTokenOrProvider the user's token.
1816
*/
19-
export const useConnectUser = <SCG extends ExtendableGenerics = DefaultGenerics>(
17+
export const useConnectUser = (
2018
apiKey: string,
21-
userToConnect: OwnUserResponse<SCG> | UserResponse<SCG>,
19+
userToConnect: OwnUserResponse | UserResponse,
2220
userTokenOrProvider: TokenOrProvider,
2321
) => {
24-
const [chatClient, setChatClient] = useState<StreamChat<SCG> | null>(null);
22+
const [chatClient, setChatClient] = useState<StreamChat | null>(null);
2523
useEffect(() => {
26-
const client = new StreamChat<SCG>(apiKey, {
24+
const client = new StreamChat(apiKey, {
2725
enableInsights: true,
2826
enableWSFallback: true,
2927
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import 'stream-chat';
2+
3+
declare module 'stream-chat' {
4+
interface CustomChannelData {
5+
name: string;
6+
}
7+
8+
interface CustomUserData {
9+
color: string;
10+
userRole: UserRole;
11+
}
12+
}

0 commit comments

Comments
 (0)