Skip to content

Commit 1cb8965

Browse files
refactor: rename StreamChatType to StreamChatGenerics in sample apps and docs
1 parent a0f2ff5 commit 1cb8965

35 files changed

+154
-142
lines changed

docusaurus/docs/reactnative/basics/upgrade_helper.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,13 @@ user won't be able to see a cropped image on UI. In this version, we render imag
291291
The Typescript generics can be simplified using a single Generic which can be passed to the component.
292292

293293
```tsx
294-
const client = StreamChat.getInstance<StreamChatType>('YOUR_API_KEY');
294+
const client = StreamChat.getInstance<StreamChatGenerics>('YOUR_API_KEY');
295295
```
296296

297-
where `StreamChatType` can be defined as;
297+
where `StreamChatGenerics` can be defined as;
298298

299299
```tsx
300-
type StreamChatType = {
300+
type StreamChatGenerics = {
301301
attachmentType: LocalAttachmentType;
302302
channelType: LocalChannelType;
303303
commandType: LocalCommandType;

docusaurus/docs/reactnative/customization/typescript.mdx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ The [documentation on `stream-chat-js` TypeScript](https://github.com/GetStream/
2424
The client a generic type that defines seven customizable fields that currently exist in [`stream-chat-js`](https://github.com/GetStream/stream-chat-js#typescript-v2xx).
2525

2626
```tsx
27-
const client = StreamChat.getInstance<StreamChatType>('YOUR_API_KEY');
27+
const client = StreamChat.getInstance<StreamChatGenerics>('YOUR_API_KEY');
2828
```
2929

30-
where `StreamChatType` can be defined as a type with the seven generics that correspond to the seven customizable fields as follows:
30+
where `StreamChatGenerics` can be defined as a type with the seven generics that correspond to the seven customizable fields as follows:
3131

3232
```tsx
33-
type StreamChatType = {
33+
type StreamChatGenerics = {
3434
attachmentType: LocalAttachmentType;
3535
channelType: LocalChannelType;
3636
commandType: LocalCommandType;
@@ -93,7 +93,7 @@ Additional fields on the defaults, i.e. `image`, are custom fields used by `stre
9393
When wanting to set a subset of generics, the preceding and interceding generics must also be set for the TypeScript compiler to understand intent correctly.
9494

9595
```tsx
96-
type StreamChatType = {
96+
type StreamChatGenerics = {
9797
attachmentType: DefaultAttachmentType;
9898
channelType: DefaultChannelType;
9999
commandType: DefaultCommandType;
@@ -105,7 +105,7 @@ type StreamChatType = {
105105
```
106106

107107
```tsx
108-
const client = StreamChat.getInstance<StreamChatType>('YOUR_API_KEY');
108+
const client = StreamChat.getInstance<StreamChatGenerics>('YOUR_API_KEY');
109109
```
110110

111111
:::note
@@ -121,7 +121,7 @@ The [TypeScript Example App](https://github.com/GetStream/stream-chat-react-nati
121121
Core to understanding this usage is [how generics can be applied to JSX elements](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-9.html#generic-type-arguments-in-jsx-elements).
122122

123123
In many cases the use of a single prop such as `client` or `channel` allows TypeScript to infer the generics on an element.
124-
In this case `channelType` within `StreamChatType` is inferred from `channel` and passed to the props type for a custom Attachment component.
124+
In this case `channelType` within `StreamChatGenerics` is inferred from `channel` and passed to the props type for a custom Attachment component.
125125

126126
<img src={inference} alt='TypeScript Inference' />
127127

@@ -130,7 +130,7 @@ In these cases the generics must be applied to the component directly.
130130
`MessageList` for instance could have the previous generics used on `client` applied to it in a similar manner.
131131

132132
```tsx
133-
<MessageList<StreamChatType>
133+
<MessageList<StreamChatGenerics>
134134
onThreadSelect={thread => {
135135
/** Set thread and navigate to thread screen */
136136
}}
@@ -147,7 +147,7 @@ Hooks, including those to access contexts, also require generics to be applied t
147147
`useChannelContext` for instance would have the previous generics applied to it to get a correctly typed return for `channel`.
148148

149149
```tsx
150-
const { channel } = useChannelContext<StreamChatType>();
150+
const { channel } = useChannelContext<StreamChatGenerics>();
151151
```
152152

153153
## Partial inference
@@ -161,5 +161,5 @@ The lack of partial inference is particularly relevant if Higher Order Component
161161
The `withChannelContext` HOC accepts the generics similarly to the `useChannelContext` hook, but because partial inference is not supported the props for the wrapped component must also be explicitly provided.
162162

163163
```tsx {2}
164-
withChannelContext<MyComponentProps, StreamChatType>(MyComponent);
164+
withChannelContext<MyComponentProps, StreamChatGenerics>(MyComponent);
165165
```

examples/SampleApp/App.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ import { UserSelectorScreen } from './src/screens/UserSelectorScreen';
2929

3030
import type { StreamChat } from 'stream-chat';
3131

32-
import type { StackNavigatorParamList, StreamChatType, UserSelectorParamList } from './src/types';
32+
import type {
33+
StackNavigatorParamList,
34+
StreamChatGenerics,
35+
UserSelectorParamList,
36+
} from './src/types';
3337

3438
LogBox.ignoreAllLogs(true);
3539
LogBox.ignoreLogs(['Non-serializable values were found in the navigation state']);
@@ -87,14 +91,14 @@ const DrawerNavigator: React.FC = () => (
8791
);
8892

8993
const DrawerNavigatorWrapper: React.FC<{
90-
chatClient: StreamChat<StreamChatType>;
94+
chatClient: StreamChat<StreamChatGenerics>;
9195
}> = ({ chatClient }) => {
9296
const { bottom } = useSafeAreaInsets();
9397
const streamChatTheme = useStreamChatTheme();
9498

9599
return (
96-
<OverlayProvider<StreamChatType> bottomInset={bottom} value={{ style: streamChatTheme }}>
97-
<Chat<StreamChatType> client={chatClient}>
100+
<OverlayProvider<StreamChatGenerics> bottomInset={bottom} value={{ style: streamChatTheme }}>
101+
<Chat<StreamChatGenerics> client={chatClient}>
98102
<AppOverlayProvider>
99103
<UserSearchProvider>
100104
<DrawerNavigator />

examples/SampleApp/src/ChatUsers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { UserResponse } from 'stream-chat';
2-
import { StreamChatType } from './types';
2+
import { StreamChatGenerics } from './types';
33

44
export const USER_TOKENS: Record<string, string> = {
55
e2etest1:
@@ -21,7 +21,7 @@ export const USER_TOKENS: Record<string, string> = {
2121
vishal:
2222
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoidmlzaGFsIn0.HOlVh-ZyQnjyuL20G-67RTgKufBuAH-I-gbEELFlass',
2323
};
24-
export const USERS: Record<string, UserResponse<StreamChatType>> = {
24+
export const USERS: Record<string, UserResponse<StreamChatGenerics>> = {
2525
neil: {
2626
id: 'neil',
2727
image: 'https://ca.slack-edge.com/T02RM6X6B-U01173D1D5J-0dead6eea6ea-512',

examples/SampleApp/src/components/AddMemberBottomSheet.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { usePaginatedUsers } from '../hooks/usePaginatedUsers';
1515

1616
import type { UserResponse } from 'stream-chat';
1717

18-
import { StreamChatType } from '../types';
18+
import { StreamChatGenerics } from '../types';
1919

2020
const styles = StyleSheet.create({
2121
container: {
@@ -89,7 +89,7 @@ export const AddMemberBottomSheet: React.FC = () => {
8989
return null;
9090
}
9191

92-
const addMember = async (user: UserResponse<StreamChatType>) => {
92+
const addMember = async (user: UserResponse<StreamChatGenerics>) => {
9393
setAddMemberQueryInProgress(true);
9494

9595
try {

examples/SampleApp/src/components/ChannelPreview.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { useChannelInfoOverlayContext } from '../context/ChannelInfoOverlayConte
1818

1919
import type { StackNavigationProp } from '@react-navigation/stack';
2020

21-
import type { StackNavigatorParamList, StreamChatType } from '../types';
21+
import type { StackNavigatorParamList, StreamChatGenerics } from '../types';
2222

2323
const styles = StyleSheet.create({
2424
leftSwipeableButton: {
@@ -42,7 +42,9 @@ type ChannelListScreenNavigationProp = StackNavigationProp<
4242
'ChannelListScreen'
4343
>;
4444

45-
export const ChannelPreview: React.FC<ChannelPreviewMessengerProps<StreamChatType>> = (props) => {
45+
export const ChannelPreview: React.FC<ChannelPreviewMessengerProps<StreamChatGenerics>> = (
46+
props,
47+
) => {
4648
const { channel } = props;
4749

4850
const { setOverlay } = useAppOverlayContext();
@@ -51,7 +53,7 @@ export const ChannelPreview: React.FC<ChannelPreviewMessengerProps<StreamChatTyp
5153

5254
const { data, setData } = useChannelInfoOverlayContext();
5355

54-
const { client } = useChatContext<StreamChatType>();
56+
const { client } = useChatContext<StreamChatGenerics>();
5557

5658
const navigation = useNavigation<ChannelListScreenNavigationProp>();
5759

examples/SampleApp/src/components/MessageSearch/MessageSearchList.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { MESSAGE_SEARCH_LIMIT } from '../../hooks/usePaginatedSearchedMessages';
88

99
import type { MessageResponse } from 'stream-chat';
1010

11-
import type { StreamChatType } from '../../types';
11+
import type { StreamChatGenerics } from '../../types';
1212

1313
const styles = StyleSheet.create({
1414
contentContainer: { flexGrow: 1 },
@@ -52,13 +52,13 @@ export type MessageSearchListProps = {
5252
EmptySearchIndicator: React.ComponentType;
5353
loading: boolean;
5454
loadMore: () => void;
55-
messages: MessageResponse<StreamChatType>[] | undefined;
55+
messages: MessageResponse<StreamChatGenerics>[] | undefined;
5656
refreshing?: boolean;
5757
refreshList?: () => void;
5858
showResultCount?: boolean;
5959
};
6060
export const MessageSearchList: React.FC<MessageSearchListProps> = React.forwardRef(
61-
(props, scrollRef: React.Ref<FlatList<MessageResponse<StreamChatType>> | null>) => {
61+
(props, scrollRef: React.Ref<FlatList<MessageResponse<StreamChatGenerics>> | null>) => {
6262
const {
6363
EmptySearchIndicator,
6464
loading,

examples/SampleApp/src/components/NewDirectMessagingSendButton.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323

2424
import { NewDirectMessagingScreenNavigationProp } from '../screens/NewDirectMessagingScreen';
2525

26-
import { StreamChatType } from '../types';
26+
import { StreamChatGenerics } from '../types';
2727

2828
type NewDirectMessagingSendButtonPropsWithContext<
2929
At extends UnknownType = DefaultAttachmentType,
@@ -123,11 +123,11 @@ export type SendButtonProps<
123123
/**
124124
* UI Component for send button in MessageInput component.
125125
*/
126-
export const NewDirectMessagingSendButton = (props: SendButtonProps<StreamChatType>) => {
126+
export const NewDirectMessagingSendButton = (props: SendButtonProps<StreamChatGenerics>) => {
127127
const navigation = useNavigation<NewDirectMessagingScreenNavigationProp>();
128-
const { channel } = useChannelContext<StreamChatType>();
128+
const { channel } = useChannelContext<StreamChatGenerics>();
129129

130-
const { giphyActive, text } = useMessageInputContext<StreamChatType>();
130+
const { giphyActive, text } = useMessageInputContext<StreamChatGenerics>();
131131

132132
const sendMessage = async () => {
133133
if (!channel) return;
@@ -144,7 +144,7 @@ export const NewDirectMessagingSendButton = (props: SendButtonProps<StreamChatTy
144144
};
145145

146146
return (
147-
<MemoizedNewDirectMessagingSendButton<StreamChatType>
147+
<MemoizedNewDirectMessagingSendButton<StreamChatGenerics>
148148
{...{ giphyActive, sendMessage }}
149149
{...props}
150150
{...{ disabled: props.disabled || false }}

examples/SampleApp/src/components/UserSearch/SelectedUserTag.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useTheme } from 'stream-chat-react-native';
44

55
import type { UserResponse } from 'stream-chat';
66

7-
import type { StreamChatType } from '../../types';
7+
import type { StreamChatGenerics } from '../../types';
88

99
const styles = StyleSheet.create({
1010
tagContainer: {
@@ -29,7 +29,7 @@ const styles = StyleSheet.create({
2929
type SelectedUserTagProps = {
3030
index: number;
3131
onPress: () => void;
32-
tag: UserResponse<StreamChatType>;
32+
tag: UserResponse<StreamChatGenerics>;
3333
disabled?: boolean;
3434
};
3535

examples/SampleApp/src/components/UserSearch/UserGridItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Avatar, Close, useTheme } from 'stream-chat-react-native';
55

66
import type { UserResponse } from 'stream-chat';
77

8-
import type { StreamChatType } from '../../types';
8+
import type { StreamChatGenerics } from '../../types';
99

1010
const presenceIndicator = { cx: 7, cy: 7, r: 5 };
1111

@@ -40,7 +40,7 @@ const styles = StyleSheet.create({
4040

4141
export type UserGridItemProps = {
4242
onPress: () => void;
43-
user: UserResponse<StreamChatType>;
43+
user: UserResponse<StreamChatGenerics>;
4444
removeButton?: boolean;
4545
};
4646

0 commit comments

Comments
 (0)