Skip to content

Commit 3a5c833

Browse files
committed
1 parent 1abf238 commit 3a5c833

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

src/modules/GroupChannelList/components/GroupChannelListItem/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export const GroupChannelListItem = ({
2323
const { stringSet } = useLocalization();
2424
const {
2525
state: {
26-
isTypingIndicatorEnabled = false,
27-
isMessageReceiptStatusEnabled = false,
26+
isTypingIndicatorEnabled,
27+
isMessageReceiptStatusEnabled,
2828
},
2929
} = useGroupChannelList();
3030

src/modules/GroupChannelList/context/GroupChannelListProvider.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ export const GroupChannelListManager: React.FC<GroupChannelListProviderProps> =
108108
}: GroupChannelListProviderProps) => {
109109
const { state: sendbirdState } = useSendbird();
110110
const { config, stores } = sendbirdState;
111-
const { state, updateState } = useGroupChannelListStore();
111+
const { state } = useGroupChannelList();
112+
const { updateState } = useGroupChannelListStore();
112113
const { sdkStore } = stores;
113114

114115
const sdk = sdkStore.sdk;

src/modules/GroupChannelList/context/__tests__/GroupChannelListProvider.spec.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import React from 'react';
2-
import {
3-
GroupChannelListProvider,
4-
useGroupChannelListContext,
5-
} from '../GroupChannelListProvider';
2+
import { GroupChannelListProvider, useGroupChannelListStore } from '../GroupChannelListProvider';
3+
import { useGroupChannelList } from '../useGroupChannelList';
64
import { act, renderHook, waitFor } from '@testing-library/react';
75

86
const mockState = {
@@ -16,7 +14,11 @@ const mockState = {
1614
initialized: true,
1715
},
1816
},
19-
config: { logger: console },
17+
config: {
18+
logger: console,
19+
groupChannelList: {
20+
},
21+
},
2022
};
2123
jest.mock('../../../../lib/Sendbird/context/hooks/useSendbird', () => ({
2224
__esModule: true,
@@ -64,9 +66,9 @@ describe('GroupChannelListProvider', () => {
6466
</GroupChannelListProvider>
6567
);
6668

67-
const { result } = renderHook(() => useGroupChannelListContext(), { wrapper });
69+
const { result } = renderHook(() => useGroupChannelList(), { wrapper });
6870

69-
expect(result.current.getState()).toMatchObject(initialState);
71+
expect(result.current.state).toMatchObject(initialState);
7072
});
7173

7274
it('update state correctly', async () => {
@@ -79,14 +81,14 @@ describe('GroupChannelListProvider', () => {
7981

8082
channelListQueryParams.prev = 42;
8183

82-
const { result } = renderHook(() => useGroupChannelListContext(), { wrapper });
83-
expect(result.current.getState().className).toEqual('old-classname');
84+
const { result } = renderHook(() => useGroupChannelListStore(), { wrapper });
85+
expect(result.current.state.className).toEqual('old-classname');
8486

8587
await act(async () => {
86-
result.current.setState({ className: 'new-classname' });
87-
result.current.setState({ disableAutoSelect: true });
88+
result.current.updateState({ className: 'new-classname' });
89+
result.current.updateState({ disableAutoSelect: true });
8890
await waitFor(() => {
89-
const newState = result.current.getState();
91+
const newState = result.current.state;
9092
expect(newState.className).toEqual('new-classname');
9193
expect(newState.disableAutoSelect).toEqual(true);
9294
});
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { GroupChannelListState, useGroupChannelListContext } from './GroupChannelListProvider';
21
import { useSyncExternalStore } from 'use-sync-external-store/shim';
3-
import { useMemo } from 'react';
2+
import { useMemo, useContext } from 'react';
3+
import { GroupChannelListState, GroupChannelListContext } from './GroupChannelListProvider';
44

55
export const useGroupChannelList = () => {
6-
const store = useGroupChannelListContext();
6+
const store = useContext(GroupChannelListContext);
77
if (!store) throw new Error('useGroupChannelList must be used within a GroupChannelListProvider');
88

99
const state: GroupChannelListState = useSyncExternalStore(store.subscribe, store.getState);
@@ -12,3 +12,5 @@ export const useGroupChannelList = () => {
1212

1313
return { state, actions };
1414
};
15+
16+
export default useGroupChannelList;

0 commit comments

Comments
 (0)