Skip to content

Commit 1e980b8

Browse files
git-babelAhyoungRyu
authored andcommitted
refactor: GroupChannelList migration (#1231)
This is a part of state management migration. This PR migrate 'GroupChannelListProvider' and related files to the new style. * Created `useGroupChannelList()` hook. It'll replace the previous `useGroupChannelContext()` hook.
1 parent 4689d79 commit 1e980b8

File tree

4 files changed

+43
-16
lines changed

4 files changed

+43
-16
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import React, { useState } from 'react';
22
import AddGroupChannelView from './AddGroupChannelView';
3-
import { useGroupChannelListContext } from '../../context/GroupChannelListProvider';
3+
import { useGroupChannelList } from '../../context/useGroupChannelList';
44

55
export const AddGroupChannel = () => {
66
const [createChannelVisible, setCreateChannelVisible] = useState(false);
7-
const { onChannelCreated, onBeforeCreateChannel, onCreateChannelClick } = useGroupChannelListContext();
7+
const {
8+
state: {
9+
onChannelCreated,
10+
onBeforeCreateChannel,
11+
onCreateChannelClick,
12+
},
13+
} = useGroupChannelList();
814

915
return (
1016
<AddGroupChannelView

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import type { SendableMessageType } from '../../../../utils';
55
import * as utils from './utils';
66
import useSendbirdStateContext from '../../../../hooks/useSendbirdStateContext';
77
import { useLocalization } from '../../../../lib/LocalizationContext';
8-
import { useGroupChannelListContext } from '../../context/GroupChannelListProvider';
98
import { GroupChannelListItemBasicProps, GroupChannelListItemView } from './GroupChannelListItemView';
9+
import { useGroupChannelList } from '../../context/useGroupChannelList';
1010

1111
export interface GroupChannelListItemProps extends GroupChannelListItemBasicProps {}
1212

@@ -21,7 +21,12 @@ export const GroupChannelListItem = ({
2121
}: GroupChannelListItemProps) => {
2222
const { config } = useSendbirdStateContext();
2323
const { stringSet } = useLocalization();
24-
const { isTypingIndicatorEnabled = false, isMessageReceiptStatusEnabled = false } = useGroupChannelListContext();
24+
const {
25+
state: {
26+
isTypingIndicatorEnabled = false,
27+
isMessageReceiptStatusEnabled = false,
28+
},
29+
} = useGroupChannelList();
2530

2631
const userId = config.userId;
2732
const isMessageStatusEnabled = isMessageReceiptStatusEnabled

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import './index.scss';
22

33
import React from 'react';
44
import type { GroupChannel } from '@sendbird/chat/groupChannel';
5-
import { useGroupChannelListContext } from '../../context/GroupChannelListProvider';
65
import { GroupChannelListUIView } from './GroupChannelListUIView';
76
import GroupChannelPreviewAction from '../GroupChannelPreviewAction';
87
import useSendbirdStateContext from '../../../../hooks/useSendbirdStateContext';
98
import { GroupChannelListItem } from '../GroupChannelListItem';
109
import AddGroupChannel from '../AddGroupChannel';
1110
import { GroupChannelListItemBasicProps } from '../GroupChannelListItem/GroupChannelListItemView';
1211
import { noop } from '../../../../utils/utils';
12+
import { useGroupChannelList } from '../../context/useGroupChannelList';
1313

1414
interface GroupChannelItemProps extends GroupChannelListItemBasicProps {}
1515

@@ -25,17 +25,19 @@ export const GroupChannelListUI = (props: GroupChannelListUIProps) => {
2525
const { renderHeader, renderChannelPreview, renderPlaceHolderError, renderPlaceHolderLoading, renderPlaceHolderEmptyList } = props;
2626

2727
const {
28-
onChannelSelect,
29-
onThemeChange,
30-
allowProfileEdit,
31-
typingChannelUrls,
32-
groupChannels,
33-
initialized,
34-
selectedChannelUrl,
35-
loadMore,
36-
onUserProfileUpdated,
37-
scrollRef,
38-
} = useGroupChannelListContext();
28+
state: {
29+
onChannelSelect,
30+
onThemeChange,
31+
allowProfileEdit,
32+
typingChannelUrls,
33+
groupChannels,
34+
initialized,
35+
selectedChannelUrl,
36+
loadMore,
37+
onUserProfileUpdated,
38+
scrollRef,
39+
},
40+
} = useGroupChannelList();
3941

4042
const { stores, config } = useSendbirdStateContext();
4143
const { logger, isOnline } = config;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { GroupChannelListState, useGroupChannelListContext } from './GroupChannelListProvider';
2+
import { useSyncExternalStore } from 'use-sync-external-store/shim';
3+
import { useMemo } from 'react';
4+
5+
export const useGroupChannelList = () => {
6+
const store = useGroupChannelListContext();
7+
if (!store) throw new Error('useChannelSettings must be used within a ChannelSettingsProvider');
8+
9+
const state: GroupChannelListState = useSyncExternalStore(store.subscribe, store.getState);
10+
const actions = useMemo(() => ({
11+
}), [store]);
12+
13+
return { state, actions };
14+
};

0 commit comments

Comments
 (0)