@webinex/chatify 1.0.0-rc3 → 1.0.2-rc3

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 (98) hide show
  1. package/dist/esm/index.js +1 -1
  2. package/dist/esm/index.js.map +1 -1
  3. package/dist/esm/types/core/action.d.ts +10 -4
  4. package/dist/esm/types/core/state.d.ts +2 -1
  5. package/dist/esm/types/core/useGetAccountsQuery.d.ts +3 -1
  6. package/dist/esm/types/core/useGetChatListQuery.d.ts +3 -1
  7. package/dist/esm/types/core/useGetChatQuery.d.ts +3 -1
  8. package/dist/esm/types/ui/Icon.d.ts +8 -8
  9. package/dist/index.d.ts +21 -14
  10. package/package.json +92 -92
  11. package/src/ChatifyContext.tsx +41 -41
  12. package/src/core/action.tsx +421 -405
  13. package/src/core/client.ts +143 -143
  14. package/src/core/index.ts +17 -17
  15. package/src/core/models.tsx +82 -82
  16. package/src/core/reducer.tsx +87 -87
  17. package/src/core/state.ts +93 -92
  18. package/src/core/useAddChatMutation.tsx +22 -22
  19. package/src/core/useAddMemberMutation.tsx +25 -25
  20. package/src/core/useFetchNextMutation.tsx +28 -28
  21. package/src/core/useGetAccountsQuery.tsx +30 -33
  22. package/src/core/useGetChatListQuery.tsx +30 -33
  23. package/src/core/useGetChatQuery.tsx +31 -34
  24. package/src/core/useGetMessagesQuery.tsx +35 -35
  25. package/src/core/useReadMonitor.tsx +32 -32
  26. package/src/core/useRemoveMemberMutation.tsx +23 -23
  27. package/src/core/useSendMutation.tsx +24 -24
  28. package/src/core/useSignalRMonitor.tsx +66 -66
  29. package/src/core/useUpdateChatNameMutation.tsx +23 -23
  30. package/src/index.ts +3 -3
  31. package/src/styles/aside.scss +94 -94
  32. package/src/styles/chat.scss +222 -222
  33. package/src/styles/index.scss +79 -79
  34. package/src/styles/keyframes.scss +14 -14
  35. package/src/styles/mixins.scss +20 -20
  36. package/src/styles/settings.scss +5 -5
  37. package/src/styles/variables.scss +10 -10
  38. package/src/ui/AddChatButton.tsx +15 -15
  39. package/src/ui/Avatar.tsx +18 -18
  40. package/src/ui/ChatList/ChatList.tsx +42 -42
  41. package/src/ui/ChatList/ChatListItemBox.tsx +22 -22
  42. package/src/ui/ChatList/ChatListItemLastMessage.tsx +13 -13
  43. package/src/ui/ChatList/ChatListItemLastMessageAuthor.tsx +20 -20
  44. package/src/ui/ChatList/ChatListItemLastMessageContent.tsx +21 -21
  45. package/src/ui/ChatList/ChatListItemName.tsx +13 -13
  46. package/src/ui/ChatList/ChatListItemUnreadCount.tsx +12 -12
  47. package/src/ui/ChatList/index.ts +7 -7
  48. package/src/ui/ChatName.tsx +10 -10
  49. package/src/ui/ChatPanel/ChatBody.tsx +44 -44
  50. package/src/ui/ChatPanel/ChatHeader.tsx +33 -33
  51. package/src/ui/ChatPanel/ChatHeaderMembers.tsx +26 -26
  52. package/src/ui/ChatPanel/ChatHeaderName.tsx +67 -67
  53. package/src/ui/ChatPanel/ChatMembersButton.tsx +21 -21
  54. package/src/ui/ChatPanel/ChatMembersPanel.tsx +117 -117
  55. package/src/ui/ChatPanel/ChatPanel.tsx +27 -27
  56. package/src/ui/ChatPanel/index.ts +6 -6
  57. package/src/ui/Chatify.tsx +148 -148
  58. package/src/ui/CreateChatPanel/CreateChatForm.tsx +36 -36
  59. package/src/ui/CreateChatPanel/CreateChatMemberInput.tsx +66 -66
  60. package/src/ui/CreateChatPanel/CreateChatNameInput.tsx +25 -25
  61. package/src/ui/CreateChatPanel/CreateChatPanel.tsx +33 -33
  62. package/src/ui/CreateChatPanel/index.ts +4 -4
  63. package/src/ui/Icon.tsx +33 -33
  64. package/src/ui/InputBox/InputBox.tsx +38 -38
  65. package/src/ui/InputBox/InputFilesBox.tsx +9 -9
  66. package/src/ui/InputBox/InputSubmitButtonBox.tsx +17 -17
  67. package/src/ui/InputBox/InputTextBox.tsx +50 -50
  68. package/src/ui/InputBox/index.ts +4 -4
  69. package/src/ui/Layout/Aside.tsx +10 -10
  70. package/src/ui/Layout/Body.tsx +10 -10
  71. package/src/ui/Layout/Footer.tsx +3 -3
  72. package/src/ui/Layout/Header.tsx +10 -10
  73. package/src/ui/Layout/Main.tsx +15 -15
  74. package/src/ui/Layout/index.ts +5 -5
  75. package/src/ui/Message/MessageAuthor.tsx +13 -13
  76. package/src/ui/Message/MessageBox.tsx +20 -20
  77. package/src/ui/Message/MessageContent.tsx +13 -13
  78. package/src/ui/Message/MessageInfoBox.tsx +25 -25
  79. package/src/ui/Message/MessageRow.tsx +24 -24
  80. package/src/ui/Message/MessageText.tsx +7 -7
  81. package/src/ui/Message/index.ts +6 -6
  82. package/src/ui/MessageReadObserver.tsx +45 -45
  83. package/src/ui/MessageSkeleton.tsx +19 -19
  84. package/src/ui/Next.tsx +48 -48
  85. package/src/ui/SendingMessage/SendingMessageBox.tsx +16 -16
  86. package/src/ui/SendingMessage/SendingMessageContent.tsx +13 -13
  87. package/src/ui/SendingMessage/SendingMessageInfoBox.tsx +13 -13
  88. package/src/ui/SendingMessage/SendingMessageText.tsx +7 -7
  89. package/src/ui/SendingMessage/index.ts +4 -4
  90. package/src/ui/SystemMessage/SystemMessageBox.tsx +20 -20
  91. package/src/ui/SystemMessage/SystemMessageRow.tsx +43 -43
  92. package/src/ui/SystemMessage/index.ts +2 -2
  93. package/src/ui/customize.tsx +45 -45
  94. package/src/ui/index.ts +11 -11
  95. package/src/ui/localizer.tsx +80 -80
  96. package/src/util/index.ts +2 -2
  97. package/src/util/uniqBy.tsx +17 -17
  98. package/src/util/uniqId.tsx +3 -3
@@ -1,10 +1,10 @@
1
- $borderColor: #ddd;
2
- $border: 1px solid #ddd;
3
- $background: white;
4
- $radius: 4px;
5
- $chatBodyBackground: #f5f5f5;
6
- $messageBackground: #e1f5fe;
7
- $myMessageBackground: #b9f6ca;
8
- $unreadCountBackground: #ffa726;
9
- $avatarSize: 40px;
10
- $messageBorderRadius: 10px;
1
+ $borderColor: #ddd;
2
+ $border: 1px solid #ddd;
3
+ $background: white;
4
+ $radius: 4px;
5
+ $chatBodyBackground: #f5f5f5;
6
+ $messageBackground: #e1f5fe;
7
+ $myMessageBackground: #b9f6ca;
8
+ $unreadCountBackground: #ffa726;
9
+ $avatarSize: 40px;
10
+ $messageBorderRadius: 10px;
@@ -1,15 +1,15 @@
1
- import { Button } from 'antd';
2
- import { useDispatch } from '../core';
3
- import { useCallback } from 'react';
4
- import { customize } from './customize';
5
-
6
- export const AddChatButton = customize('AddChatButton', () => {
7
- const dispatch = useDispatch();
8
- const onAddChat = useCallback(() => dispatch({ type: 'new_chat_open', data: undefined }), [dispatch]);
9
-
10
- return (
11
- <Button onClick={onAddChat} icon={'+'} type="link">
12
- Add chat
13
- </Button>
14
- );
15
- });
1
+ import { Button } from 'antd';
2
+ import { useDispatch } from '../core';
3
+ import { useCallback } from 'react';
4
+ import { customize } from './customize';
5
+
6
+ export const AddChatButton = customize('AddChatButton', () => {
7
+ const dispatch = useDispatch();
8
+ const onAddChat = useCallback(() => dispatch({ type: 'new_chat_open', data: undefined }), [dispatch]);
9
+
10
+ return (
11
+ <Button onClick={onAddChat} icon={'+'} type="link">
12
+ Add chat
13
+ </Button>
14
+ );
15
+ });
package/src/ui/Avatar.tsx CHANGED
@@ -1,18 +1,18 @@
1
- import { FC } from 'react';
2
- import { Account } from '../core';
3
- import { Avatar as AntdAvatar } from 'antd';
4
- import { customize } from './customize';
5
-
6
- export interface AvatarProps {
7
- account: Account;
8
- }
9
-
10
- const _Avatar: FC<AvatarProps> = (props: AvatarProps) => {
11
- const { account } = props;
12
-
13
- return <AntdAvatar src={account.avatar} />;
14
- };
15
-
16
- _Avatar.displayName = 'Avatar';
17
-
18
- export const Avatar = customize('Avatar', _Avatar);
1
+ import { FC } from 'react';
2
+ import { Account } from '../core';
3
+ import { Avatar as AntdAvatar } from 'antd';
4
+ import { customize } from './customize';
5
+
6
+ export interface AvatarProps {
7
+ account: Account;
8
+ }
9
+
10
+ const _Avatar: FC<AvatarProps> = (props: AvatarProps) => {
11
+ const { account } = props;
12
+
13
+ return <AntdAvatar src={account.avatar} />;
14
+ };
15
+
16
+ _Avatar.displayName = 'Avatar';
17
+
18
+ export const Avatar = customize('Avatar', _Avatar);
@@ -1,42 +1,42 @@
1
- import { Menu, MenuProps } from 'antd';
2
- import { useCallback, useMemo } from 'react';
3
- import type { MenuItemType } from 'antd/es/menu/hooks/useItems';
4
- import { useGetChatListQuery, useDispatch, useSelect } from '../../core';
5
- import { ChatListItemBox } from './ChatListItemBox';
6
- import { customize } from '../customize';
7
-
8
- function useOnSelect() {
9
- const dispatch = useDispatch();
10
-
11
- return useCallback(
12
- (info: Parameters<NonNullable<MenuProps['onSelect']>>[0]) =>
13
- dispatch({ type: 'chat_open', data: { chatId: info.selectedKeys[0] } }),
14
- [dispatch],
15
- );
16
- }
17
-
18
- function useMenuItems() {
19
- const { data: chats } = useGetChatListQuery();
20
-
21
- return useMemo<MenuItemType[] | undefined>(() => {
22
- return chats
23
- ?.slice()
24
- .sort((a, b) => -a.message.id.substring(47).localeCompare(b.message.id.substring(47)))
25
- .map((x) => ({ key: x.id, label: <ChatListItemBox chat={x} /> }));
26
- }, [chats]);
27
- }
28
-
29
- export const ChatList = customize('ChatList', () => {
30
- const activeChatId = useSelect((x) => x.ui.chatId, []);
31
- const selected = useMemo(() => (activeChatId ? [activeChatId] : []), [activeChatId]);
32
- const onSelect = useOnSelect();
33
- const items = useMenuItems();
34
-
35
- return (
36
- <>
37
- {items && (
38
- <Menu className="wxchtf-chat-list" selectedKeys={selected} onSelect={onSelect} items={items} />
39
- )}
40
- </>
41
- );
42
- });
1
+ import { Menu, MenuProps } from 'antd';
2
+ import { useCallback, useMemo } from 'react';
3
+ import type { MenuItemType } from 'antd/es/menu/hooks/useItems';
4
+ import { useGetChatListQuery, useDispatch, useSelect } from '../../core';
5
+ import { ChatListItemBox } from './ChatListItemBox';
6
+ import { customize } from '../customize';
7
+
8
+ function useOnSelect() {
9
+ const dispatch = useDispatch();
10
+
11
+ return useCallback(
12
+ (info: Parameters<NonNullable<MenuProps['onSelect']>>[0]) =>
13
+ dispatch({ type: 'chat_open', data: { chatId: info.selectedKeys[0] } }),
14
+ [dispatch],
15
+ );
16
+ }
17
+
18
+ function useMenuItems() {
19
+ const { data: chats } = useGetChatListQuery();
20
+
21
+ return useMemo<MenuItemType[] | undefined>(() => {
22
+ return chats
23
+ ?.slice()
24
+ .sort((a, b) => -a.message.id.substring(47).localeCompare(b.message.id.substring(47)))
25
+ .map((x) => ({ key: x.id, label: <ChatListItemBox chat={x} /> }));
26
+ }, [chats]);
27
+ }
28
+
29
+ export const ChatList = customize('ChatList', () => {
30
+ const activeChatId = useSelect((x) => x.ui.chatId, []);
31
+ const selected = useMemo(() => (activeChatId ? [activeChatId] : []), [activeChatId]);
32
+ const onSelect = useOnSelect();
33
+ const items = useMenuItems();
34
+
35
+ return (
36
+ <>
37
+ {items && (
38
+ <Menu className="wxchtf-chat-list" selectedKeys={selected} onSelect={onSelect} items={items} />
39
+ )}
40
+ </>
41
+ );
42
+ });
@@ -1,22 +1,22 @@
1
- import { ChatListItem as ChatListItemModel } from '../../core';
2
- import { customize } from '../customize';
3
- import { ChatListItemName } from './ChatListItemName';
4
- import { ChatListItemUnreadCount } from './ChatListItemUnreadCount';
5
- import { ChatListItemLastMessage } from './ChatListItemLastMessage';
6
-
7
- export interface ChatListItemBoxProps {
8
- chat: ChatListItemModel;
9
- }
10
-
11
- export const ChatListItemBox = customize('ChatListItemBox', (props: ChatListItemBoxProps) => {
12
- const { message, lastReadMessageId } = props.chat;
13
- const read = lastReadMessageId != null && lastReadMessageId.localeCompare(message.id) >= 0;
14
-
15
- return (
16
- <div className={'wxchtf-chat' + (!read ? ' --unread' : '')}>
17
- <ChatListItemName {...props} />
18
- <ChatListItemUnreadCount {...props} />
19
- <ChatListItemLastMessage {...props} />
20
- </div>
21
- );
22
- });
1
+ import { ChatListItem as ChatListItemModel } from '../../core';
2
+ import { customize } from '../customize';
3
+ import { ChatListItemName } from './ChatListItemName';
4
+ import { ChatListItemUnreadCount } from './ChatListItemUnreadCount';
5
+ import { ChatListItemLastMessage } from './ChatListItemLastMessage';
6
+
7
+ export interface ChatListItemBoxProps {
8
+ chat: ChatListItemModel;
9
+ }
10
+
11
+ export const ChatListItemBox = customize('ChatListItemBox', (props: ChatListItemBoxProps) => {
12
+ const { message, lastReadMessageId } = props.chat;
13
+ const read = lastReadMessageId != null && lastReadMessageId.localeCompare(message.id) >= 0;
14
+
15
+ return (
16
+ <div className={'wxchtf-chat' + (!read ? ' --unread' : '')}>
17
+ <ChatListItemName {...props} />
18
+ <ChatListItemUnreadCount {...props} />
19
+ <ChatListItemLastMessage {...props} />
20
+ </div>
21
+ );
22
+ });
@@ -1,13 +1,13 @@
1
- import { customize } from '../customize';
2
- import type { ChatListItemBoxProps } from './ChatListItemBox';
3
- import { ChatListItemLastMessageContent } from './ChatListItemLastMessageContent';
4
- import { ChatListItemLastMessageAuthor } from './ChatListItemLastMessageAuthor';
5
-
6
- export const ChatListItemLastMessage = customize('ChatListItemLastMessage', (props: ChatListItemBoxProps) => {
7
- return (
8
- <div className="wxchtf-chat-last">
9
- <ChatListItemLastMessageAuthor {...props} />
10
- <ChatListItemLastMessageContent {...props} />
11
- </div>
12
- );
13
- });
1
+ import { customize } from '../customize';
2
+ import type { ChatListItemBoxProps } from './ChatListItemBox';
3
+ import { ChatListItemLastMessageContent } from './ChatListItemLastMessageContent';
4
+ import { ChatListItemLastMessageAuthor } from './ChatListItemLastMessageAuthor';
5
+
6
+ export const ChatListItemLastMessage = customize('ChatListItemLastMessage', (props: ChatListItemBoxProps) => {
7
+ return (
8
+ <div className="wxchtf-chat-last">
9
+ <ChatListItemLastMessageAuthor {...props} />
10
+ <ChatListItemLastMessageContent {...props} />
11
+ </div>
12
+ );
13
+ });
@@ -1,20 +1,20 @@
1
- import { Avatar } from '../Avatar';
2
- import { customize } from '../customize';
3
- import type { ChatListItemBoxProps } from './ChatListItemBox';
4
-
5
- export const ChatListItemLastMessageAuthor = customize(
6
- 'ChatListItemLastMessageAuthor',
7
- (props: ChatListItemBoxProps) => {
8
- const { message } = props.chat;
9
-
10
- if (message.sentBy.id === 'chatify::system') {
11
- return null;
12
- }
13
-
14
- return (
15
- <div className="wxchtf-chat-last-author">
16
- <Avatar account={message.sentBy} /> {message.sentBy.name}
17
- </div>
18
- );
19
- },
20
- );
1
+ import { Avatar } from '../Avatar';
2
+ import { customize } from '../customize';
3
+ import type { ChatListItemBoxProps } from './ChatListItemBox';
4
+
5
+ export const ChatListItemLastMessageAuthor = customize(
6
+ 'ChatListItemLastMessageAuthor',
7
+ (props: ChatListItemBoxProps) => {
8
+ const { message } = props.chat;
9
+
10
+ if (message.sentBy.id === 'chatify::system') {
11
+ return null;
12
+ }
13
+
14
+ return (
15
+ <div className="wxchtf-chat-last-author">
16
+ <Avatar account={message.sentBy} /> {message.sentBy.name}
17
+ </div>
18
+ );
19
+ },
20
+ );
@@ -1,21 +1,21 @@
1
- import { useLocalizer } from '../localizer';
2
- import { formatSystemMessage } from '../SystemMessage/SystemMessageRow';
3
- import { FC } from 'react';
4
- import { customize } from '../customize';
5
- import type { ChatListItemBoxProps } from './ChatListItemBox';
6
-
7
- export const ChatListItemLastMessageContent = customize<FC<ChatListItemBoxProps>>(
8
- 'ChatListItemLastMessageContent',
9
- (props) => {
10
- const { message } = props.chat;
11
- const localizer = useLocalizer();
12
-
13
- return (
14
- <div className="wxchtf-chat-last-message">
15
- {message.sentBy.id === 'chatify::system'
16
- ? formatSystemMessage(localizer, message.text)
17
- : message.text}
18
- </div>
19
- );
20
- },
21
- );
1
+ import { useLocalizer } from '../localizer';
2
+ import { formatSystemMessage } from '../SystemMessage/SystemMessageRow';
3
+ import { FC } from 'react';
4
+ import { customize } from '../customize';
5
+ import type { ChatListItemBoxProps } from './ChatListItemBox';
6
+
7
+ export const ChatListItemLastMessageContent = customize<FC<ChatListItemBoxProps>>(
8
+ 'ChatListItemLastMessageContent',
9
+ (props) => {
10
+ const { message } = props.chat;
11
+ const localizer = useLocalizer();
12
+
13
+ return (
14
+ <div className="wxchtf-chat-last-message">
15
+ {message.sentBy.id === 'chatify::system'
16
+ ? formatSystemMessage(localizer, message.text)
17
+ : message.text}
18
+ </div>
19
+ );
20
+ },
21
+ );
@@ -1,13 +1,13 @@
1
- import { ChatName } from '../ChatName';
2
- import { customize } from '../customize';
3
- import type { ChatListItemBoxProps } from './ChatListItemBox';
4
-
5
- export const ChatListItemName = customize('ChatListItemName', (props: ChatListItemBoxProps) => {
6
- const { name } = props.chat;
7
-
8
- return (
9
- <div className="wxchtf-chat-name">
10
- <ChatName name={name} />
11
- </div>
12
- );
13
- });
1
+ import { ChatName } from '../ChatName';
2
+ import { customize } from '../customize';
3
+ import type { ChatListItemBoxProps } from './ChatListItemBox';
4
+
5
+ export const ChatListItemName = customize('ChatListItemName', (props: ChatListItemBoxProps) => {
6
+ const { name } = props.chat;
7
+
8
+ return (
9
+ <div className="wxchtf-chat-name">
10
+ <ChatName name={name} />
11
+ </div>
12
+ );
13
+ });
@@ -1,12 +1,12 @@
1
- import { customize } from '../customize';
2
- import { ChatListItemBoxProps } from './ChatListItemBox';
3
-
4
- export const ChatListItemUnreadCount = customize('ChatListItemUnreadCount', (props: ChatListItemBoxProps) => {
5
- const { totalUnreadCount: unreadCount } = props.chat;
6
-
7
- if (unreadCount <= 0) {
8
- return null;
9
- }
10
-
11
- return <div className="wxchtf-unread-count">{unreadCount}</div>;
12
- });
1
+ import { customize } from '../customize';
2
+ import { ChatListItemBoxProps } from './ChatListItemBox';
3
+
4
+ export const ChatListItemUnreadCount = customize('ChatListItemUnreadCount', (props: ChatListItemBoxProps) => {
5
+ const { totalUnreadCount: unreadCount } = props.chat;
6
+
7
+ if (unreadCount <= 0) {
8
+ return null;
9
+ }
10
+
11
+ return <div className="wxchtf-unread-count">{unreadCount}</div>;
12
+ });
@@ -1,7 +1,7 @@
1
- export * from './ChatList';
2
- export * from './ChatListItemBox';
3
- export * from './ChatListItemLastMessage';
4
- export * from './ChatListItemLastMessageAuthor';
5
- export * from './ChatListItemLastMessageContent';
6
- export * from './ChatListItemName';
7
- export * from './ChatListItemUnreadCount';
1
+ export * from './ChatList';
2
+ export * from './ChatListItemBox';
3
+ export * from './ChatListItemLastMessage';
4
+ export * from './ChatListItemLastMessageAuthor';
5
+ export * from './ChatListItemLastMessageContent';
6
+ export * from './ChatListItemName';
7
+ export * from './ChatListItemUnreadCount';
@@ -1,10 +1,10 @@
1
- import { customize } from './customize';
2
-
3
- export interface ChatNameProps {
4
- name: string;
5
- }
6
-
7
- export const ChatName = customize('ChatName', (props: ChatNameProps) => {
8
- const { name } = props;
9
- return <>{name}</>;
10
- });
1
+ import { customize } from './customize';
2
+
3
+ export interface ChatNameProps {
4
+ name: string;
5
+ }
6
+
7
+ export const ChatName = customize('ChatName', (props: ChatNameProps) => {
8
+ const { name } = props;
9
+ return <>{name}</>;
10
+ });
@@ -1,44 +1,44 @@
1
- import { MessageBox } from '../Message';
2
- import { useGetMessagesQuery } from '../../core';
3
- import { Next } from '../Next';
4
- import { SendingMessageBox } from '../SendingMessage';
5
- import { SystemMessageBox } from '../SystemMessage/SystemMessageBox';
6
- import { MessageSkeleton } from '../MessageSkeleton';
7
- import { customize } from '../customize';
8
-
9
- export interface ChatBodyProps {
10
- id: string;
11
- }
12
-
13
- export const ChatBody = customize('ChatBody', (props: ChatBodyProps) => {
14
- const { id } = props;
15
- const { data: messages } = useGetMessagesQuery({ chatId: id });
16
-
17
- return (
18
- <div className="wxchtf-chat-body">
19
- {!messages && <MessageSkeleton count={5} />}
20
- {messages?.map((x, index) => {
21
- if (x.type === 'message' && x.sentBy.id === 'chatify::system') {
22
- return <SystemMessageBox key={x.id} message={x} />;
23
- }
24
-
25
- switch (x.type) {
26
- case 'message': {
27
- return <MessageBox message={x} key={x.id} />;
28
- }
29
-
30
- case 'sending': {
31
- return <SendingMessageBox key={x.requestId} text={x.text} files={x.files} />;
32
- }
33
-
34
- case 'next': {
35
- return <Next key={'next-' + messages.length + '-' + index} chatId={id} />;
36
- }
37
-
38
- default:
39
- return null;
40
- }
41
- })}
42
- </div>
43
- );
44
- });
1
+ import { MessageBox } from '../Message';
2
+ import { useGetMessagesQuery } from '../../core';
3
+ import { Next } from '../Next';
4
+ import { SendingMessageBox } from '../SendingMessage';
5
+ import { SystemMessageBox } from '../SystemMessage/SystemMessageBox';
6
+ import { MessageSkeleton } from '../MessageSkeleton';
7
+ import { customize } from '../customize';
8
+
9
+ export interface ChatBodyProps {
10
+ id: string;
11
+ }
12
+
13
+ export const ChatBody = customize('ChatBody', (props: ChatBodyProps) => {
14
+ const { id } = props;
15
+ const { data: messages } = useGetMessagesQuery({ chatId: id });
16
+
17
+ return (
18
+ <div className="wxchtf-chat-body">
19
+ {!messages && <MessageSkeleton count={5} />}
20
+ {messages?.map((x, index) => {
21
+ if (x.type === 'message' && x.sentBy.id === 'chatify::system') {
22
+ return <SystemMessageBox key={x.id} message={x} />;
23
+ }
24
+
25
+ switch (x.type) {
26
+ case 'message': {
27
+ return <MessageBox message={x} key={x.id} />;
28
+ }
29
+
30
+ case 'sending': {
31
+ return <SendingMessageBox key={x.requestId} text={x.text} files={x.files} />;
32
+ }
33
+
34
+ case 'next': {
35
+ return <Next key={'next-' + messages.length + '-' + index} chatId={id} />;
36
+ }
37
+
38
+ default:
39
+ return null;
40
+ }
41
+ })}
42
+ </div>
43
+ );
44
+ });
@@ -1,33 +1,33 @@
1
- import { Col, Row, Space } from 'antd';
2
- import { ChatHeaderMembers } from './ChatHeaderMembers';
3
- import { ChatMembersButton } from './ChatMembersButton';
4
- import { customize } from '../customize';
5
- import { ChatHeaderName } from './ChatHeaderName';
6
- import { useSelect } from '../../core';
7
-
8
- export interface ChatHeaderProps {
9
- id: string;
10
- }
11
-
12
- export const ChatHeader = customize('ChatHeader', (props: ChatHeaderProps) => {
13
- const { id } = props;
14
- const chat = useSelect((x) => x.query.chatList.data!.find((x) => x.id === id)!, [id]);
15
-
16
- return (
17
- <div className="wxchtf-chat-header">
18
- <Row justify="space-between" align="middle">
19
- <Col>
20
- <ChatHeaderName id={id} />
21
- </Col>
22
- {chat.active && (
23
- <Col className="wxchtf-chat-members">
24
- <Space align="center">
25
- <ChatHeaderMembers id={id} />
26
- <ChatMembersButton id={id} />
27
- </Space>
28
- </Col>
29
- )}
30
- </Row>
31
- </div>
32
- );
33
- });
1
+ import { Col, Row, Space } from 'antd';
2
+ import { ChatHeaderMembers } from './ChatHeaderMembers';
3
+ import { ChatMembersButton } from './ChatMembersButton';
4
+ import { customize } from '../customize';
5
+ import { ChatHeaderName } from './ChatHeaderName';
6
+ import { useSelect } from '../../core';
7
+
8
+ export interface ChatHeaderProps {
9
+ id: string;
10
+ }
11
+
12
+ export const ChatHeader = customize('ChatHeader', (props: ChatHeaderProps) => {
13
+ const { id } = props;
14
+ const chat = useSelect((x) => x.query.chatList.data!.find((x) => x.id === id)!, [id]);
15
+
16
+ return (
17
+ <div className="wxchtf-chat-header">
18
+ <Row justify="space-between" align="middle">
19
+ <Col>
20
+ <ChatHeaderName id={id} />
21
+ </Col>
22
+ {chat.active && (
23
+ <Col className="wxchtf-chat-members">
24
+ <Space align="center">
25
+ <ChatHeaderMembers id={id} />
26
+ <ChatMembersButton id={id} />
27
+ </Space>
28
+ </Col>
29
+ )}
30
+ </Row>
31
+ </div>
32
+ );
33
+ });
@@ -1,26 +1,26 @@
1
- import { useGetChatQuery } from '../../core';
2
- import { Avatar, Tooltip } from 'antd';
3
- import { customize } from '../customize';
4
-
5
- export interface ChatHeaderMembersProps {
6
- id: string;
7
- }
8
-
9
- export const ChatHeaderMembers = customize('ChatHeaderMembers', (props: ChatHeaderMembersProps) => {
10
- const { id } = props;
11
- const { data: chat } = useGetChatQuery({ chatId: id });
12
-
13
- if (!chat?.members) {
14
- return null;
15
- }
16
-
17
- return (
18
- <Avatar.Group maxCount={5}>
19
- {chat.members.map((x) => (
20
- <Tooltip key={x.id} title={x.name}>
21
- <Avatar src={x.avatar}>{x.name}</Avatar>
22
- </Tooltip>
23
- ))}
24
- </Avatar.Group>
25
- );
26
- });
1
+ import { useGetChatQuery } from '../../core';
2
+ import { Avatar, Tooltip } from 'antd';
3
+ import { customize } from '../customize';
4
+
5
+ export interface ChatHeaderMembersProps {
6
+ id: string;
7
+ }
8
+
9
+ export const ChatHeaderMembers = customize('ChatHeaderMembers', (props: ChatHeaderMembersProps) => {
10
+ const { id } = props;
11
+ const { data: chat } = useGetChatQuery({ chatId: id });
12
+
13
+ if (!chat?.members) {
14
+ return null;
15
+ }
16
+
17
+ return (
18
+ <Avatar.Group maxCount={5}>
19
+ {chat.members.map((x) => (
20
+ <Tooltip key={x.id} title={x.name}>
21
+ <Avatar src={x.avatar}>{x.name}</Avatar>
22
+ </Tooltip>
23
+ ))}
24
+ </Avatar.Group>
25
+ );
26
+ });