@tencentcloud/chat-uikit-react 2.1.4 → 2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +6 -3
  3. package/dist/cjs/components/ConversationPreview/ConversationPreviewContent.js +1 -1
  4. package/dist/cjs/components/TUIContact/TUIContactInfo/TUIContactInfo.d.ts +1 -1
  5. package/dist/cjs/components/TUIContact/TUIContactInfo/TUIContactInfo.js +1 -1
  6. package/dist/cjs/components/TUIContact/TUIContactInfo/friendInfo.js +1 -1
  7. package/dist/cjs/components/TUIContact/TUIContactInfo/groupInfo.js +1 -0
  8. package/dist/cjs/components/TUIContact/TUIContactList/TUIContactList.js +1 -1
  9. package/dist/cjs/components/TUIContact/hooks/useTUIContact.js +1 -1
  10. package/dist/cjs/components/TUIKit/TUIKit.js +1 -1
  11. package/dist/cjs/components/TUIKit/hooks/useTUIKit.d.ts +7 -2
  12. package/dist/cjs/components/TUIKit/hooks/useTUIKit.js +1 -1
  13. package/dist/cjs/index.css +1 -1
  14. package/dist/cjs/index.d.css +1 -0
  15. package/dist/cjs/index.d.ts +1 -0
  16. package/dist/cjs/index.js +1 -1
  17. package/dist/cjs/locales/en/TUIContact.js +1 -1
  18. package/dist/cjs/locales/en/index.js +1 -1
  19. package/dist/cjs/locales/zh_cn/TUIContact.js +1 -1
  20. package/dist/cjs/locales/zh_cn/index.js +1 -1
  21. package/dist/cjs/utils/env.d.ts +4 -0
  22. package/dist/esm/components/ConversationPreview/ConversationPreviewContent.js +1 -1
  23. package/dist/esm/components/TUIContact/TUIContactInfo/TUIContactInfo.d.ts +1 -1
  24. package/dist/esm/components/TUIContact/TUIContactInfo/TUIContactInfo.js +1 -1
  25. package/dist/esm/components/TUIContact/TUIContactInfo/friendInfo.js +1 -1
  26. package/dist/esm/components/TUIContact/TUIContactInfo/groupInfo.js +1 -0
  27. package/dist/esm/components/TUIContact/TUIContactList/TUIContactList.js +1 -1
  28. package/dist/esm/components/TUIContact/hooks/useTUIContact.js +1 -1
  29. package/dist/esm/components/TUIKit/TUIKit.js +1 -1
  30. package/dist/esm/components/TUIKit/hooks/useTUIKit.d.ts +7 -2
  31. package/dist/esm/components/TUIKit/hooks/useTUIKit.js +1 -1
  32. package/dist/esm/index.css +1 -1
  33. package/dist/esm/index.d.css +1 -0
  34. package/dist/esm/index.d.ts +1 -0
  35. package/dist/esm/index.js +1 -1
  36. package/dist/esm/locales/en/TUIContact.js +1 -1
  37. package/dist/esm/locales/en/index.js +1 -1
  38. package/dist/esm/locales/zh_cn/TUIContact.js +1 -1
  39. package/dist/esm/locales/zh_cn/index.js +1 -1
  40. package/dist/esm/utils/env.d.ts +4 -0
  41. package/package.json +1 -1
  42. package/scripts/publish-intl-experience-demo.js +14 -0
  43. package/src/components/ConversationPreview/ConversationPreviewContent.tsx +1 -1
  44. package/src/components/TUIChat/styles/layout.scss +1 -0
  45. package/src/components/TUIContact/TUIContactInfo/TUIContactInfo.tsx +5 -3
  46. package/src/components/TUIContact/TUIContactInfo/friendInfo.tsx +10 -10
  47. package/src/components/TUIContact/TUIContactInfo/groupInfo.tsx +65 -0
  48. package/src/components/TUIContact/TUIContactList/TUIContactList.tsx +71 -65
  49. package/src/components/TUIContact/hooks/useTUIContact.tsx +14 -0
  50. package/src/components/TUIKit/TUIKit.tsx +6 -5
  51. package/src/components/TUIKit/hooks/useTUIKit.tsx +9 -3
  52. package/src/index.ts +1 -0
  53. package/src/locales/en/TUIContact.ts +1 -0
  54. package/src/locales/en/index.ts +2 -0
  55. package/src/locales/zh_cn/TUIContact.ts +1 -0
  56. package/src/locales/zh_cn/index.ts +2 -0
  57. package/src/server.ts +2 -3
@@ -4,13 +4,20 @@ import TencentCloudChat from '@tencentcloud/chat';
4
4
  import { isH5 } from '../../../utils/env';
5
5
  import { useTUIKitContext, useTUIContactContext } from '../../../context';
6
6
  import useContactInfo from '../TUIContactInfo/hooks/useContactInfo';
7
-
7
+ import useTUIContact from '../hooks/useTUIContact';
8
8
  import { Avatar, defaultUserAvatar } from '../../Avatar';
9
9
  import rightArrow from '../../Icon/images/right-arrow.svg';
10
10
  import downArrow from '../../Icon/images/down-arrow.png';
11
-
12
11
  import './index.scss';
13
12
 
13
+ interface RenderContactListProps {
14
+ type: 'group' | 'block' | 'friend' ,
15
+ isShow: boolean,
16
+ title: string,
17
+ list: Array<any> | undefined,
18
+ setShow: (value: boolean) => void
19
+ }
20
+
14
21
  function UnMemoizedTUIContactList<T>(): React.ReactElement {
15
22
  const { setActiveContact } = useTUIKitContext();
16
23
  const { t } = useTranslation();
@@ -20,16 +27,56 @@ function UnMemoizedTUIContactList<T>(): React.ReactElement {
20
27
  const {
21
28
  acceptFriendApplication,
22
29
  } = useContactInfo();
23
-
30
+ const { groupList } = useTUIContact();
24
31
  const [iShowFriendApplication, setShowFriendApplication] = useState(false);
25
32
  const [iShowFriends, setShowFriends] = useState(false);
26
33
  const [isShowBlocklist, setShowBlocklist] = useState(false);
34
+ const [isShowGrouplist, setShowGrouplist] = useState(false);
27
35
 
28
36
  const acceptFriendApplicationHandle = (e: any, userID: string) => {
29
37
  e.stopPropagation();
30
38
  acceptFriendApplication(userID);
31
39
  setActiveContact();
32
40
  };
41
+
42
+ const RenderContactList = ({ type, isShow, setShow, list, title } : RenderContactListProps) => {
43
+ return (
44
+ <>
45
+ <div
46
+ className="tui-contacts-title"
47
+ role="button"
48
+ tabIndex={0}
49
+ onClick={() => setShow(!isShow)}
50
+ >
51
+ <div className="tui-contacts-list-title">{title}</div>
52
+ <div className="tui-contacts-list-icon">
53
+ <img src={isShow ? downArrow : rightArrow} alt="" />
54
+ </div>
55
+ </div>
56
+ {isShow
57
+ && list?.map((item: any) => {
58
+ const { userID, groupID, avatar, name, nick } = item.profile || item;
59
+ const showName = item.remark || nick || userID || name || groupID;
60
+ return (
61
+ <div
62
+ role="button"
63
+ tabIndex={0}
64
+ className="tui-contacts-list-item"
65
+ key={userID || groupID}
66
+ onClick={() => {
67
+ setActiveContact({ type, data: item });
68
+ }}
69
+ >
70
+ <Avatar size={30} image={avatar || defaultUserAvatar} />
71
+ <div className="tui-contacts-list-item-container">
72
+ <p className="tui-contacts-list-item-name">{ showName }</p>
73
+ </div>
74
+ </div>
75
+ );
76
+ })}
77
+ </>
78
+ );
79
+ }
33
80
  // eslint-disable-next-line
34
81
  // @ts-ignore
35
82
  return (
@@ -96,68 +143,27 @@ function UnMemoizedTUIContactList<T>(): React.ReactElement {
96
143
  </div>
97
144
  );
98
145
  })}
99
- <div
100
- className="tui-contacts-title"
101
- role="button"
102
- tabIndex={0}
103
- onClick={() => setShowBlocklist(!isShowBlocklist)}
104
- >
105
- <div className="tui-contacts-list-title">{t('TUIContact.Blocked List')}</div>
106
- <div className="tui-contacts-list-icon">
107
- <img src={isShowBlocklist ? downArrow : rightArrow} alt="" />
108
- </div>
109
- </div>
110
- {isShowBlocklist
111
- && blocklistProfile?.map((item, index) => {
112
- const { userID, avatar, nick } = item;
113
- return (
114
- <div
115
- role="button"
116
- tabIndex={0}
117
- className="tui-contacts-list-item"
118
- key={userID}
119
- onClick={() => {
120
- setActiveContact({ type: 'block', data: item });
121
- }}
122
- >
123
- <Avatar size={30} image={avatar || defaultUserAvatar} />
124
- <div className="tui-contacts-list-item-container">
125
- <p className="tui-contacts-list-item-name">{ nick || userID}</p>
126
- </div>
127
- </div>
128
- );
129
- })}
130
- <div
131
- className="tui-contacts-title"
132
- role="button"
133
- tabIndex={0}
134
- onClick={() => setShowFriends(!iShowFriends)}
135
- >
136
- <div className="tui-contacts-list-title">{t('TUIContact.Friends')}</div>
137
- <div className="tui-contacts-list-icon">
138
- <img src={iShowFriends ? downArrow : rightArrow} alt="" />
139
- </div>
140
- </div>
141
- {iShowFriends
142
- && friendList?.map((item, index) => {
143
- const { userID, avatar, nick } = item.profile;
144
- return (
145
- <div
146
- className="tui-contacts-list-item"
147
- key={userID}
148
- role="button"
149
- tabIndex={0}
150
- onClick={() => {
151
- setActiveContact({ type: 'friend', data: item });
152
- }}
153
- >
154
- <Avatar size={30} image={avatar || defaultUserAvatar} />
155
- <div className="tui-contacts-list-item-container">
156
- <p className="tui-contacts-list-item-name">{item.remark || nick || userID}</p>
157
- </div>
158
- </div>
159
- );
160
- })}
146
+ <RenderContactList
147
+ type={'block'}
148
+ title={t('TUIContact.Blocked List')}
149
+ isShow={isShowBlocklist}
150
+ setShow={setShowBlocklist}
151
+ list={blocklistProfile}
152
+ />
153
+ <RenderContactList
154
+ type={'group'}
155
+ title={t('TUIContact.Group List')}
156
+ setShow={setShowGrouplist}
157
+ isShow={isShowGrouplist}
158
+ list={groupList}
159
+ />
160
+ <RenderContactList
161
+ type={'friend'}
162
+ title={t('TUIContact.Friends')}
163
+ setShow={setShowFriends}
164
+ isShow={iShowFriends}
165
+ list={friendList}
166
+ />
161
167
  </div>
162
168
  )
163
169
  );
@@ -1,5 +1,10 @@
1
1
  import React, { useEffect, useState } from 'react';
2
2
  import TencentCloudChat from '@tencentcloud/chat';
3
+ import {
4
+ TUIStore,
5
+ StoreName,
6
+ IGroupModel,
7
+ } from '@tencentcloud/chat-uikit-engine';
3
8
  import { useTUIKitContext } from '../../../context';
4
9
 
5
10
  function useTUIContact() {
@@ -8,14 +13,22 @@ function useTUIContact() {
8
13
  const [blockList, setBlockList] = useState([]);
9
14
  const [friendApplicationList, setFriendApplicationList] = useState([]);
10
15
  const [blocklistProfile, setBlocklistProfile] = useState([]);
16
+ const [groupList, setGroupList] = useState<IGroupModel[]>();
17
+
11
18
  const [isShowContactList, setShowContactList] = useState(true);
12
19
 
13
20
  useEffect(() => {
21
+ TUIStore.watch(StoreName.GRP, {
22
+ groupList: onGroupListUpdated,
23
+ });
14
24
  getFriendList();
15
25
  getBlocklist();
16
26
  getFriendApplicationList();
17
27
  }, [chat]);
18
28
 
29
+ const onGroupListUpdated = (list: IGroupModel[]) => {
30
+ setGroupList(list);
31
+ };
19
32
  useEffect(() => {
20
33
  chat?.on(TencentCloudChat.EVENT.BLACKLIST_UPDATED, onBlocklistUpdated);
21
34
  chat?.on(TencentCloudChat.EVENT.FRIEND_LIST_UPDATED, onFriendListUpdated);
@@ -64,6 +77,7 @@ function useTUIContact() {
64
77
 
65
78
  return {
66
79
  friendList,
80
+ groupList,
67
81
  blocklistProfile,
68
82
  friendApplicationList,
69
83
  blockList,
@@ -1,6 +1,6 @@
1
1
  import React, { PropsWithChildren, useState, useEffect } from 'react';
2
2
  import { ChatSDK, Conversation } from '@tencentcloud/chat';
3
- import { TUIStore, StoreName, IConversationModel } from '@tencentcloud/chat-uikit-engine';
3
+ import { TUIStore, StoreName, IConversationModel, TUIConversationService } from '@tencentcloud/chat-uikit-engine';
4
4
  import { TUILogin } from '@tencentcloud/tui-core';
5
5
  import { useTranslation } from 'react-i18next';
6
6
  import { isH5, isPC } from '../../utils/env';
@@ -81,7 +81,7 @@ function RenderForPC({ moduleValue, tabbarRender, setModuleValue } : RenderPCPro
81
81
  {moduleValue === TUIKIT_TABBAR.CONTACTS && (
82
82
  <TUIContact>
83
83
  <TUIContactInfo
84
- showChat={() => {
84
+ showChats={() => {
85
85
  setModuleValue(TUIKIT_TABBAR.CHATS);
86
86
  }}
87
87
  />
@@ -95,7 +95,7 @@ function RenderForH5({
95
95
  moduleValue, contactData, tabbarRender, currentConversationID, setModuleValue,
96
96
  }: RenderH5Props) {
97
97
  return (
98
- <>
98
+ <div className='sample-chat-h5'>
99
99
  {!currentConversationID && !contactData && (
100
100
  <div className="sample-chat-h5-container">
101
101
  <TUIProfile className="sample-profile" />
@@ -113,13 +113,13 @@ function RenderForH5({
113
113
  { moduleValue === TUIKIT_TABBAR.CONTACTS && contactData && (
114
114
  <TUIContact>
115
115
  <TUIContactInfo
116
- showChat={() => {
116
+ showChats={() => {
117
117
  setModuleValue(TUIKIT_TABBAR.CHATS);
118
118
  }}
119
119
  />
120
120
  </TUIContact>
121
121
  )}
122
- </>
122
+ </div>
123
123
  );
124
124
  }
125
125
  export function TUIKit<
@@ -176,6 +176,7 @@ export function TUIKit<
176
176
 
177
177
  const switchTabbar = (value: string) => {
178
178
  setModuleValue(value);
179
+ TUIConversationService.switchConversation('');
179
180
  };
180
181
  const onCurrentConversation = (conversationModel: IConversationModel) => {
181
182
  setActiveConversation(conversationModel?.getConversation());
@@ -2,6 +2,7 @@ import React, { useState, useCallback, useEffect } from 'react';
2
2
  import {
3
3
  TUIStore,
4
4
  StoreName,
5
+ IGroupModel
5
6
  } from '@tencentcloud/chat-uikit-engine';
6
7
  import { useTranslation } from 'react-i18next';
7
8
  import {
@@ -32,8 +33,13 @@ interface addFriendData {
32
33
  data: Profile
33
34
  }
34
35
 
36
+ interface GroupData {
37
+ type: 'group',
38
+ data: IGroupModel
39
+ }
40
+
35
41
  export type UseContactParams = blockData | friendData |
36
- friendApplicationData | addFriendData| undefined;
42
+ friendApplicationData | addFriendData| GroupData | undefined;
37
43
 
38
44
  export interface UseChatParams{
39
45
  chat: ChatSDK,
@@ -68,11 +74,11 @@ export const useTUIKit = ({
68
74
  if (conversation && (activeConversation?.conversationID !== conversation.conversationID)) {
69
75
  setTUIManageShow(false);
70
76
  }
71
- activeConversation && setConversation(activeConversation);
77
+ setConversation(activeConversation);
72
78
  },
73
79
  [chat],
74
80
  );
75
- const setActiveContact = (actionContactData: UseContactParams) => {
81
+ const setActiveContact = (actionContactData?: UseContactParams) => {
76
82
  setContactData(actionContactData);
77
83
  };
78
84
 
package/src/index.ts CHANGED
@@ -5,3 +5,4 @@ export * from './components';
5
5
  export * from './context';
6
6
  export * from './hooks';
7
7
  export * from './locales';
8
+ export * from './utils/env';
@@ -12,6 +12,7 @@ const TUIContact = {
12
12
  'Signature': 'Signature',
13
13
  'New Contacts': 'New Contacts',
14
14
  'Blocked List': 'Blocked List',
15
+ 'Group List': 'Group List',
15
16
  'No Result': 'No Result',
16
17
  'ID': 'ID',
17
18
  'User': 'User',
@@ -4,6 +4,8 @@ import TUIContact from './TUIContact';
4
4
  import TUIProfile from './TUIProfile';
5
5
 
6
6
  export const message = {
7
+ 'chats': 'Messages',
8
+ 'contacts': 'Contacts',
7
9
  TUIChat,
8
10
  TUIConversation,
9
11
  TUIContact,
@@ -13,6 +13,7 @@ const TUIContact = {
13
13
  'Successful application, waiting for the administrator to agree to join the group application': '等待管理员同意',
14
14
  'New Contacts': '新的联系人',
15
15
  'Blocked List': '黑名单',
16
+ 'Group List': '我的群聊',
16
17
  'No Result': '无搜索结果',
17
18
  'ID': 'ID',
18
19
  'User': '联系人',
@@ -4,6 +4,8 @@ import TUIContact from './TUIContact';
4
4
  import TUIProfile from './TUIProfile';
5
5
 
6
6
  export const message = {
7
+ 'chats': '消息',
8
+ 'contacts': '通讯录',
7
9
  TUIChat,
8
10
  TUIConversation,
9
11
  TUIContact,
package/src/server.ts CHANGED
@@ -12,8 +12,7 @@ export default class TUIChatKit {
12
12
  }
13
13
 
14
14
  /**
15
- * 监听 TUILogin.login 的成功通知
16
- * @param { TUIInitParam } params 初始化参数
15
+ * @param { TUIInitParam } params
17
16
  */
18
17
  public onNotifyEvent(eventName: string, subKey: string) {
19
18
  if (eventName === TUIConstants.TUILogin.EVENT.LOGIN_STATE_CHANGED) {
@@ -28,7 +27,7 @@ export default class TUIChatKit {
28
27
  }
29
28
 
30
29
  /**
31
- * login 登录
30
+ * login
32
31
  */
33
32
  private login() {
34
33
  const {