@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.
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/core/action.d.ts +10 -4
- package/dist/esm/types/core/state.d.ts +2 -1
- package/dist/esm/types/core/useGetAccountsQuery.d.ts +3 -1
- package/dist/esm/types/core/useGetChatListQuery.d.ts +3 -1
- package/dist/esm/types/core/useGetChatQuery.d.ts +3 -1
- package/dist/esm/types/ui/Icon.d.ts +8 -8
- package/dist/index.d.ts +21 -14
- package/package.json +92 -92
- package/src/ChatifyContext.tsx +41 -41
- package/src/core/action.tsx +421 -405
- package/src/core/client.ts +143 -143
- package/src/core/index.ts +17 -17
- package/src/core/models.tsx +82 -82
- package/src/core/reducer.tsx +87 -87
- package/src/core/state.ts +93 -92
- package/src/core/useAddChatMutation.tsx +22 -22
- package/src/core/useAddMemberMutation.tsx +25 -25
- package/src/core/useFetchNextMutation.tsx +28 -28
- package/src/core/useGetAccountsQuery.tsx +30 -33
- package/src/core/useGetChatListQuery.tsx +30 -33
- package/src/core/useGetChatQuery.tsx +31 -34
- package/src/core/useGetMessagesQuery.tsx +35 -35
- package/src/core/useReadMonitor.tsx +32 -32
- package/src/core/useRemoveMemberMutation.tsx +23 -23
- package/src/core/useSendMutation.tsx +24 -24
- package/src/core/useSignalRMonitor.tsx +66 -66
- package/src/core/useUpdateChatNameMutation.tsx +23 -23
- package/src/index.ts +3 -3
- package/src/styles/aside.scss +94 -94
- package/src/styles/chat.scss +222 -222
- package/src/styles/index.scss +79 -79
- package/src/styles/keyframes.scss +14 -14
- package/src/styles/mixins.scss +20 -20
- package/src/styles/settings.scss +5 -5
- package/src/styles/variables.scss +10 -10
- package/src/ui/AddChatButton.tsx +15 -15
- package/src/ui/Avatar.tsx +18 -18
- package/src/ui/ChatList/ChatList.tsx +42 -42
- package/src/ui/ChatList/ChatListItemBox.tsx +22 -22
- package/src/ui/ChatList/ChatListItemLastMessage.tsx +13 -13
- package/src/ui/ChatList/ChatListItemLastMessageAuthor.tsx +20 -20
- package/src/ui/ChatList/ChatListItemLastMessageContent.tsx +21 -21
- package/src/ui/ChatList/ChatListItemName.tsx +13 -13
- package/src/ui/ChatList/ChatListItemUnreadCount.tsx +12 -12
- package/src/ui/ChatList/index.ts +7 -7
- package/src/ui/ChatName.tsx +10 -10
- package/src/ui/ChatPanel/ChatBody.tsx +44 -44
- package/src/ui/ChatPanel/ChatHeader.tsx +33 -33
- package/src/ui/ChatPanel/ChatHeaderMembers.tsx +26 -26
- package/src/ui/ChatPanel/ChatHeaderName.tsx +67 -67
- package/src/ui/ChatPanel/ChatMembersButton.tsx +21 -21
- package/src/ui/ChatPanel/ChatMembersPanel.tsx +117 -117
- package/src/ui/ChatPanel/ChatPanel.tsx +27 -27
- package/src/ui/ChatPanel/index.ts +6 -6
- package/src/ui/Chatify.tsx +148 -148
- package/src/ui/CreateChatPanel/CreateChatForm.tsx +36 -36
- package/src/ui/CreateChatPanel/CreateChatMemberInput.tsx +66 -66
- package/src/ui/CreateChatPanel/CreateChatNameInput.tsx +25 -25
- package/src/ui/CreateChatPanel/CreateChatPanel.tsx +33 -33
- package/src/ui/CreateChatPanel/index.ts +4 -4
- package/src/ui/Icon.tsx +33 -33
- package/src/ui/InputBox/InputBox.tsx +38 -38
- package/src/ui/InputBox/InputFilesBox.tsx +9 -9
- package/src/ui/InputBox/InputSubmitButtonBox.tsx +17 -17
- package/src/ui/InputBox/InputTextBox.tsx +50 -50
- package/src/ui/InputBox/index.ts +4 -4
- package/src/ui/Layout/Aside.tsx +10 -10
- package/src/ui/Layout/Body.tsx +10 -10
- package/src/ui/Layout/Footer.tsx +3 -3
- package/src/ui/Layout/Header.tsx +10 -10
- package/src/ui/Layout/Main.tsx +15 -15
- package/src/ui/Layout/index.ts +5 -5
- package/src/ui/Message/MessageAuthor.tsx +13 -13
- package/src/ui/Message/MessageBox.tsx +20 -20
- package/src/ui/Message/MessageContent.tsx +13 -13
- package/src/ui/Message/MessageInfoBox.tsx +25 -25
- package/src/ui/Message/MessageRow.tsx +24 -24
- package/src/ui/Message/MessageText.tsx +7 -7
- package/src/ui/Message/index.ts +6 -6
- package/src/ui/MessageReadObserver.tsx +45 -45
- package/src/ui/MessageSkeleton.tsx +19 -19
- package/src/ui/Next.tsx +48 -48
- package/src/ui/SendingMessage/SendingMessageBox.tsx +16 -16
- package/src/ui/SendingMessage/SendingMessageContent.tsx +13 -13
- package/src/ui/SendingMessage/SendingMessageInfoBox.tsx +13 -13
- package/src/ui/SendingMessage/SendingMessageText.tsx +7 -7
- package/src/ui/SendingMessage/index.ts +4 -4
- package/src/ui/SystemMessage/SystemMessageBox.tsx +20 -20
- package/src/ui/SystemMessage/SystemMessageRow.tsx +43 -43
- package/src/ui/SystemMessage/index.ts +2 -2
- package/src/ui/customize.tsx +45 -45
- package/src/ui/index.ts +11 -11
- package/src/ui/localizer.tsx +80 -80
- package/src/util/index.ts +2 -2
- package/src/util/uniqBy.tsx +17 -17
- package/src/util/uniqId.tsx +3 -3
package/src/ui/Message/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from './MessageAuthor';
|
|
2
|
-
export * from './MessageBox';
|
|
3
|
-
export * from './MessageContent';
|
|
4
|
-
export * from './MessageInfoBox';
|
|
5
|
-
export * from './MessageRow';
|
|
6
|
-
export * from './MessageText';
|
|
1
|
+
export * from './MessageAuthor';
|
|
2
|
+
export * from './MessageBox';
|
|
3
|
+
export * from './MessageContent';
|
|
4
|
+
export * from './MessageInfoBox';
|
|
5
|
+
export * from './MessageRow';
|
|
6
|
+
export * from './MessageText';
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { FC, RefObject, useEffect, useMemo, useRef } from 'react';
|
|
2
|
-
import { useDispatch, useSelect } from '../core';
|
|
3
|
-
import { customize } from './customize';
|
|
4
|
-
import { MessageBoxProps } from './Message/MessageBox';
|
|
5
|
-
|
|
6
|
-
export interface MessageReadObserverProps extends MessageBoxProps {
|
|
7
|
-
messageRef: RefObject<HTMLDivElement | null>;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const MessageReadObserver = customize<FC<MessageReadObserverProps>>('MessageReadObserver', (props) => {
|
|
11
|
-
const { message, messageRef } = props;
|
|
12
|
-
const dispatch = useDispatch();
|
|
13
|
-
const isRead = useSelect((x) => {
|
|
14
|
-
const lastReadMessageId = x.query.chatList.data!.find((x) => x.id === message.chatId)!.lastReadMessageId;
|
|
15
|
-
return lastReadMessageId != null && message.id.localeCompare(lastReadMessageId) <= 0;
|
|
16
|
-
}, []);
|
|
17
|
-
|
|
18
|
-
const readRef = useRef(isRead);
|
|
19
|
-
|
|
20
|
-
useEffect(() => {
|
|
21
|
-
readRef.current = readRef.current || isRead;
|
|
22
|
-
}, [isRead]);
|
|
23
|
-
|
|
24
|
-
const observer = useMemo(
|
|
25
|
-
() =>
|
|
26
|
-
new IntersectionObserver(([entry]) => {
|
|
27
|
-
if (entry.isIntersecting && !readRef.current) {
|
|
28
|
-
readRef.current = true;
|
|
29
|
-
dispatch({ type: 'read', data: { id: message.id, timestamp: new Date().getTime() } });
|
|
30
|
-
}
|
|
31
|
-
}),
|
|
32
|
-
|
|
33
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
34
|
-
[],
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
useEffect(() => {
|
|
38
|
-
observer.observe(messageRef.current!);
|
|
39
|
-
return () => observer.disconnect();
|
|
40
|
-
|
|
41
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
42
|
-
}, [observer]);
|
|
43
|
-
|
|
44
|
-
return <></>;
|
|
45
|
-
});
|
|
1
|
+
import { FC, RefObject, useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
import { useDispatch, useSelect } from '../core';
|
|
3
|
+
import { customize } from './customize';
|
|
4
|
+
import { MessageBoxProps } from './Message/MessageBox';
|
|
5
|
+
|
|
6
|
+
export interface MessageReadObserverProps extends MessageBoxProps {
|
|
7
|
+
messageRef: RefObject<HTMLDivElement | null>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const MessageReadObserver = customize<FC<MessageReadObserverProps>>('MessageReadObserver', (props) => {
|
|
11
|
+
const { message, messageRef } = props;
|
|
12
|
+
const dispatch = useDispatch();
|
|
13
|
+
const isRead = useSelect((x) => {
|
|
14
|
+
const lastReadMessageId = x.query.chatList.data!.find((x) => x.id === message.chatId)!.lastReadMessageId;
|
|
15
|
+
return lastReadMessageId != null && message.id.localeCompare(lastReadMessageId) <= 0;
|
|
16
|
+
}, []);
|
|
17
|
+
|
|
18
|
+
const readRef = useRef(isRead);
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
readRef.current = readRef.current || isRead;
|
|
22
|
+
}, [isRead]);
|
|
23
|
+
|
|
24
|
+
const observer = useMemo(
|
|
25
|
+
() =>
|
|
26
|
+
new IntersectionObserver(([entry]) => {
|
|
27
|
+
if (entry.isIntersecting && !readRef.current) {
|
|
28
|
+
readRef.current = true;
|
|
29
|
+
dispatch({ type: 'read', data: { id: message.id, timestamp: new Date().getTime() } });
|
|
30
|
+
}
|
|
31
|
+
}),
|
|
32
|
+
|
|
33
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
34
|
+
[],
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
observer.observe(messageRef.current!);
|
|
39
|
+
return () => observer.disconnect();
|
|
40
|
+
|
|
41
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
42
|
+
}, [observer]);
|
|
43
|
+
|
|
44
|
+
return <></>;
|
|
45
|
+
});
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { Skeleton } from 'antd';
|
|
2
|
-
|
|
3
|
-
export interface MessageSkeletonProps {
|
|
4
|
-
count?: number;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function MessageSkeleton(props: MessageSkeletonProps) {
|
|
8
|
-
const { count = 1 } = props;
|
|
9
|
-
return (
|
|
10
|
-
<>
|
|
11
|
-
{Array.from(Array(count)).map((_, index) => (
|
|
12
|
-
<div className="wxchtf-message-skeleton" key={index}>
|
|
13
|
-
<Skeleton.Avatar className="wxchtf-avatar" active />
|
|
14
|
-
<Skeleton.Button active className="wxchtf-content" />
|
|
15
|
-
</div>
|
|
16
|
-
))}
|
|
17
|
-
</>
|
|
18
|
-
);
|
|
19
|
-
}
|
|
1
|
+
import { Skeleton } from 'antd';
|
|
2
|
+
|
|
3
|
+
export interface MessageSkeletonProps {
|
|
4
|
+
count?: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function MessageSkeleton(props: MessageSkeletonProps) {
|
|
8
|
+
const { count = 1 } = props;
|
|
9
|
+
return (
|
|
10
|
+
<>
|
|
11
|
+
{Array.from(Array(count)).map((_, index) => (
|
|
12
|
+
<div className="wxchtf-message-skeleton" key={index}>
|
|
13
|
+
<Skeleton.Avatar className="wxchtf-avatar" active />
|
|
14
|
+
<Skeleton.Button active className="wxchtf-content" />
|
|
15
|
+
</div>
|
|
16
|
+
))}
|
|
17
|
+
</>
|
|
18
|
+
);
|
|
19
|
+
}
|
package/src/ui/Next.tsx
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
-
import { useFetchNextMutation } from '../core';
|
|
3
|
-
import { MessageSkeleton } from './MessageSkeleton';
|
|
4
|
-
|
|
5
|
-
export interface NextProps {
|
|
6
|
-
chatId: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function Next(props: NextProps) {
|
|
10
|
-
const { chatId } = props;
|
|
11
|
-
const [fetchNext, { isFetching }] = useFetchNextMutation({ chatId });
|
|
12
|
-
const [intersecting, setIntersecting] = useState(false);
|
|
13
|
-
const ref = useRef<HTMLDivElement | null>(null);
|
|
14
|
-
const timerRef = useRef<NodeJS.Timer>();
|
|
15
|
-
|
|
16
|
-
const observer = useMemo(
|
|
17
|
-
() =>
|
|
18
|
-
new IntersectionObserver(([entry]) => {
|
|
19
|
-
if (entry.isIntersecting) {
|
|
20
|
-
timerRef.current = setTimeout(() => setIntersecting(true), 200);
|
|
21
|
-
} else {
|
|
22
|
-
clearTimeout(timerRef.current!);
|
|
23
|
-
}
|
|
24
|
-
}),
|
|
25
|
-
[],
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
observer.observe(ref.current!);
|
|
30
|
-
return () => observer.disconnect();
|
|
31
|
-
}, [observer]);
|
|
32
|
-
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
if (!intersecting) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
fetchNext();
|
|
39
|
-
|
|
40
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
41
|
-
}, [intersecting]);
|
|
42
|
-
|
|
43
|
-
if (isFetching || intersecting) {
|
|
44
|
-
return <MessageSkeleton count={4} />;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return <div className="wxchtf-next" ref={ref}></div>;
|
|
48
|
-
}
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { useFetchNextMutation } from '../core';
|
|
3
|
+
import { MessageSkeleton } from './MessageSkeleton';
|
|
4
|
+
|
|
5
|
+
export interface NextProps {
|
|
6
|
+
chatId: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function Next(props: NextProps) {
|
|
10
|
+
const { chatId } = props;
|
|
11
|
+
const [fetchNext, { isFetching }] = useFetchNextMutation({ chatId });
|
|
12
|
+
const [intersecting, setIntersecting] = useState(false);
|
|
13
|
+
const ref = useRef<HTMLDivElement | null>(null);
|
|
14
|
+
const timerRef = useRef<NodeJS.Timer>();
|
|
15
|
+
|
|
16
|
+
const observer = useMemo(
|
|
17
|
+
() =>
|
|
18
|
+
new IntersectionObserver(([entry]) => {
|
|
19
|
+
if (entry.isIntersecting) {
|
|
20
|
+
timerRef.current = setTimeout(() => setIntersecting(true), 200);
|
|
21
|
+
} else {
|
|
22
|
+
clearTimeout(timerRef.current!);
|
|
23
|
+
}
|
|
24
|
+
}),
|
|
25
|
+
[],
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
observer.observe(ref.current!);
|
|
30
|
+
return () => observer.disconnect();
|
|
31
|
+
}, [observer]);
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (!intersecting) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
fetchNext();
|
|
39
|
+
|
|
40
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
41
|
+
}, [intersecting]);
|
|
42
|
+
|
|
43
|
+
if (isFetching || intersecting) {
|
|
44
|
+
return <MessageSkeleton count={4} />;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return <div className="wxchtf-next" ref={ref}></div>;
|
|
48
|
+
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { File } from '../../core';
|
|
2
|
-
import { customize } from '../customize';
|
|
3
|
-
import { SendingMessageContent } from './SendingMessageContent';
|
|
4
|
-
|
|
5
|
-
export interface SendingMessageBoxProps {
|
|
6
|
-
text: string;
|
|
7
|
-
files: File[];
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const SendingMessageBox = customize('SendingMessageBox', (props: SendingMessageBoxProps) => {
|
|
11
|
-
return (
|
|
12
|
-
<div className="wxchtf-sending-message">
|
|
13
|
-
<SendingMessageContent {...props} />
|
|
14
|
-
</div>
|
|
15
|
-
);
|
|
16
|
-
});
|
|
1
|
+
import { File } from '../../core';
|
|
2
|
+
import { customize } from '../customize';
|
|
3
|
+
import { SendingMessageContent } from './SendingMessageContent';
|
|
4
|
+
|
|
5
|
+
export interface SendingMessageBoxProps {
|
|
6
|
+
text: string;
|
|
7
|
+
files: File[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const SendingMessageBox = customize('SendingMessageBox', (props: SendingMessageBoxProps) => {
|
|
11
|
+
return (
|
|
12
|
+
<div className="wxchtf-sending-message">
|
|
13
|
+
<SendingMessageContent {...props} />
|
|
14
|
+
</div>
|
|
15
|
+
);
|
|
16
|
+
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { customize } from '../customize';
|
|
2
|
-
import { SendingMessageText } from './SendingMessageText';
|
|
3
|
-
import { SendingMessageInfoBox } from './SendingMessageInfoBox';
|
|
4
|
-
import type { SendingMessageBoxProps } from './SendingMessageBox';
|
|
5
|
-
|
|
6
|
-
export const SendingMessageContent = customize('SendingMessageContent', (props: SendingMessageBoxProps) => {
|
|
7
|
-
return (
|
|
8
|
-
<div className="wxchtf-sending-message-content">
|
|
9
|
-
<SendingMessageText {...props} />
|
|
10
|
-
<SendingMessageInfoBox {...props} />
|
|
11
|
-
</div>
|
|
12
|
-
);
|
|
13
|
-
});
|
|
1
|
+
import { customize } from '../customize';
|
|
2
|
+
import { SendingMessageText } from './SendingMessageText';
|
|
3
|
+
import { SendingMessageInfoBox } from './SendingMessageInfoBox';
|
|
4
|
+
import type { SendingMessageBoxProps } from './SendingMessageBox';
|
|
5
|
+
|
|
6
|
+
export const SendingMessageContent = customize('SendingMessageContent', (props: SendingMessageBoxProps) => {
|
|
7
|
+
return (
|
|
8
|
+
<div className="wxchtf-sending-message-content">
|
|
9
|
+
<SendingMessageText {...props} />
|
|
10
|
+
<SendingMessageInfoBox {...props} />
|
|
11
|
+
</div>
|
|
12
|
+
);
|
|
13
|
+
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { customize } from '../customize';
|
|
2
|
-
import { useLocalizer } from '../localizer';
|
|
3
|
-
import type { SendingMessageBoxProps } from './SendingMessageBox';
|
|
4
|
-
|
|
5
|
-
export const SendingMessageInfoBox = customize('SendingMessageInfoBox', (_: SendingMessageBoxProps) => {
|
|
6
|
-
const localizer = useLocalizer();
|
|
7
|
-
|
|
8
|
-
return (
|
|
9
|
-
<div className="wxchtf-sending-message-info-box">
|
|
10
|
-
<div className="wxchtf-sending-message-sending-box">{localizer.message.sending()}</div>
|
|
11
|
-
</div>
|
|
12
|
-
);
|
|
13
|
-
});
|
|
1
|
+
import { customize } from '../customize';
|
|
2
|
+
import { useLocalizer } from '../localizer';
|
|
3
|
+
import type { SendingMessageBoxProps } from './SendingMessageBox';
|
|
4
|
+
|
|
5
|
+
export const SendingMessageInfoBox = customize('SendingMessageInfoBox', (_: SendingMessageBoxProps) => {
|
|
6
|
+
const localizer = useLocalizer();
|
|
7
|
+
|
|
8
|
+
return (
|
|
9
|
+
<div className="wxchtf-sending-message-info-box">
|
|
10
|
+
<div className="wxchtf-sending-message-sending-box">{localizer.message.sending()}</div>
|
|
11
|
+
</div>
|
|
12
|
+
);
|
|
13
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { customize } from '../customize';
|
|
2
|
-
import type { SendingMessageBoxProps } from './SendingMessageBox';
|
|
3
|
-
|
|
4
|
-
export const SendingMessageText = customize('SendingMessageText', (props: SendingMessageBoxProps) => {
|
|
5
|
-
const { text } = props;
|
|
6
|
-
return <div className="wxchtf-sending-message-text">{text}</div>;
|
|
7
|
-
});
|
|
1
|
+
import { customize } from '../customize';
|
|
2
|
+
import type { SendingMessageBoxProps } from './SendingMessageBox';
|
|
3
|
+
|
|
4
|
+
export const SendingMessageText = customize('SendingMessageText', (props: SendingMessageBoxProps) => {
|
|
5
|
+
const { text } = props;
|
|
6
|
+
return <div className="wxchtf-sending-message-text">{text}</div>;
|
|
7
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './SendingMessageBox';
|
|
2
|
-
export * from './SendingMessageContent';
|
|
3
|
-
export * from './SendingMessageInfoBox';
|
|
4
|
-
export * from './SendingMessageText';
|
|
1
|
+
export * from './SendingMessageBox';
|
|
2
|
+
export * from './SendingMessageContent';
|
|
3
|
+
export * from './SendingMessageInfoBox';
|
|
4
|
+
export * from './SendingMessageText';
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { useRef } from 'react';
|
|
2
|
-
import { customize } from '../customize';
|
|
3
|
-
import { Message } from '../../core';
|
|
4
|
-
import { MessageReadObserver } from '../MessageReadObserver';
|
|
5
|
-
import { SystemMessageRow } from './SystemMessageRow';
|
|
6
|
-
|
|
7
|
-
export interface SystemMessageBoxProps {
|
|
8
|
-
message: Message;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const SystemMessageBox = customize('SystemMessageBox', (props: SystemMessageBoxProps) => {
|
|
12
|
-
const ref = useRef<HTMLDivElement | null>(null);
|
|
13
|
-
|
|
14
|
-
return (
|
|
15
|
-
<>
|
|
16
|
-
<MessageReadObserver messageRef={ref} {...props} />
|
|
17
|
-
<SystemMessageRow containerRef={ref} {...props} />
|
|
18
|
-
</>
|
|
19
|
-
);
|
|
20
|
-
});
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
import { customize } from '../customize';
|
|
3
|
+
import { Message } from '../../core';
|
|
4
|
+
import { MessageReadObserver } from '../MessageReadObserver';
|
|
5
|
+
import { SystemMessageRow } from './SystemMessageRow';
|
|
6
|
+
|
|
7
|
+
export interface SystemMessageBoxProps {
|
|
8
|
+
message: Message;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const SystemMessageBox = customize('SystemMessageBox', (props: SystemMessageBoxProps) => {
|
|
12
|
+
const ref = useRef<HTMLDivElement | null>(null);
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<>
|
|
16
|
+
<MessageReadObserver messageRef={ref} {...props} />
|
|
17
|
+
<SystemMessageRow containerRef={ref} {...props} />
|
|
18
|
+
</>
|
|
19
|
+
);
|
|
20
|
+
});
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import { Ref } from 'react';
|
|
2
|
-
import { customize } from '../customize';
|
|
3
|
-
import { Localizer, useLocalizer } from '../localizer';
|
|
4
|
-
import { Message } from '../../core';
|
|
5
|
-
|
|
6
|
-
export interface SystemMessageRowProps {
|
|
7
|
-
message: Message;
|
|
8
|
-
containerRef?: Ref<HTMLDivElement>;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function formatSystemMessage(localizer: Localizer, text: string): React.ReactNode {
|
|
12
|
-
if (text === 'chatify://chat-created') {
|
|
13
|
-
return localizer.system.chatCreated();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (text.startsWith('chatify://member-added')) {
|
|
17
|
-
return localizer.system.memberAdded();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (text.startsWith('chatify://member-removed')) {
|
|
21
|
-
return localizer.system.memberRemoved();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (text.startsWith('chatify://chat-name-changed::')) {
|
|
25
|
-
const data = JSON.parse(text.substring('chatify://chat-name-changed::'.length));
|
|
26
|
-
return localizer.system.chatNameChanged(data.newName);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return text;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const SystemMessageRow = customize('SystemMessageRow', (props: SystemMessageRowProps) => {
|
|
33
|
-
const { message, containerRef } = props;
|
|
34
|
-
const { text, sentAt } = message;
|
|
35
|
-
const localizer = useLocalizer();
|
|
36
|
-
|
|
37
|
-
return (
|
|
38
|
-
<div ref={containerRef} className="wxchtf-system-message">
|
|
39
|
-
<div className="wxchtf-text">{formatSystemMessage(localizer, text)}</div>
|
|
40
|
-
<div className="wxchtf-timestamp">{localizer.timestamp(sentAt)}</div>
|
|
41
|
-
</div>
|
|
42
|
-
);
|
|
43
|
-
});
|
|
1
|
+
import { Ref } from 'react';
|
|
2
|
+
import { customize } from '../customize';
|
|
3
|
+
import { Localizer, useLocalizer } from '../localizer';
|
|
4
|
+
import { Message } from '../../core';
|
|
5
|
+
|
|
6
|
+
export interface SystemMessageRowProps {
|
|
7
|
+
message: Message;
|
|
8
|
+
containerRef?: Ref<HTMLDivElement>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function formatSystemMessage(localizer: Localizer, text: string): React.ReactNode {
|
|
12
|
+
if (text === 'chatify://chat-created') {
|
|
13
|
+
return localizer.system.chatCreated();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (text.startsWith('chatify://member-added')) {
|
|
17
|
+
return localizer.system.memberAdded();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (text.startsWith('chatify://member-removed')) {
|
|
21
|
+
return localizer.system.memberRemoved();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (text.startsWith('chatify://chat-name-changed::')) {
|
|
25
|
+
const data = JSON.parse(text.substring('chatify://chat-name-changed::'.length));
|
|
26
|
+
return localizer.system.chatNameChanged(data.newName);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return text;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const SystemMessageRow = customize('SystemMessageRow', (props: SystemMessageRowProps) => {
|
|
33
|
+
const { message, containerRef } = props;
|
|
34
|
+
const { text, sentAt } = message;
|
|
35
|
+
const localizer = useLocalizer();
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<div ref={containerRef} className="wxchtf-system-message">
|
|
39
|
+
<div className="wxchtf-text">{formatSystemMessage(localizer, text)}</div>
|
|
40
|
+
<div className="wxchtf-timestamp">{localizer.timestamp(sentAt)}</div>
|
|
41
|
+
</div>
|
|
42
|
+
);
|
|
43
|
+
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './SystemMessageBox';
|
|
2
|
-
export * from './SystemMessageRow';
|
|
1
|
+
export * from './SystemMessageBox';
|
|
2
|
+
export * from './SystemMessageRow';
|
package/src/ui/customize.tsx
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import React, { FC, PropsWithChildren, useContext } from 'react';
|
|
2
|
-
|
|
3
|
-
export type Customizable<TComponent extends React.ComponentType<any>> = TComponent & {
|
|
4
|
-
Component: TComponent;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
const CustomizeContext = React.createContext<CustomizeProviderValue>(null!);
|
|
8
|
-
|
|
9
|
-
export interface CustomizeProviderValue {
|
|
10
|
-
[key: string]: React.ComponentType<any> | null;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function CustomizeProvider(props: PropsWithChildren<{ value: CustomizeProviderValue }>) {
|
|
14
|
-
const { children, value } = props;
|
|
15
|
-
return <CustomizeContext.Provider value={value}>{children}</CustomizeContext.Provider>;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function useCustom<TComponent extends React.ComponentType>(key: string): TComponent | undefined | null {
|
|
19
|
-
const value = useContext(CustomizeContext);
|
|
20
|
-
return value[key] as TComponent | null | undefined;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function customize<TComponent extends React.ComponentType<any>>(
|
|
24
|
-
key: string,
|
|
25
|
-
Component: TComponent,
|
|
26
|
-
): TComponent extends React.ComponentType<infer X> ? Customizable<React.ComponentType<X>> : never {
|
|
27
|
-
const Result: FC<any> = React.forwardRef<TComponent, any>((props: any, forwardRef) => {
|
|
28
|
-
const Custom = useCustom(key);
|
|
29
|
-
|
|
30
|
-
if (Custom === null) {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (Custom) {
|
|
35
|
-
return <Custom {...props} ref={forwardRef} />;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return <Component {...props} ref={forwardRef} />;
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
Component.displayName = Component.displayName || key;
|
|
42
|
-
Result.displayName = 'Customizable.' + Component.displayName;
|
|
43
|
-
|
|
44
|
-
return Object.assign(Result, { key, Component }) as any;
|
|
45
|
-
}
|
|
1
|
+
import React, { FC, PropsWithChildren, useContext } from 'react';
|
|
2
|
+
|
|
3
|
+
export type Customizable<TComponent extends React.ComponentType<any>> = TComponent & {
|
|
4
|
+
Component: TComponent;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const CustomizeContext = React.createContext<CustomizeProviderValue>(null!);
|
|
8
|
+
|
|
9
|
+
export interface CustomizeProviderValue {
|
|
10
|
+
[key: string]: React.ComponentType<any> | null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function CustomizeProvider(props: PropsWithChildren<{ value: CustomizeProviderValue }>) {
|
|
14
|
+
const { children, value } = props;
|
|
15
|
+
return <CustomizeContext.Provider value={value}>{children}</CustomizeContext.Provider>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function useCustom<TComponent extends React.ComponentType>(key: string): TComponent | undefined | null {
|
|
19
|
+
const value = useContext(CustomizeContext);
|
|
20
|
+
return value[key] as TComponent | null | undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function customize<TComponent extends React.ComponentType<any>>(
|
|
24
|
+
key: string,
|
|
25
|
+
Component: TComponent,
|
|
26
|
+
): TComponent extends React.ComponentType<infer X> ? Customizable<React.ComponentType<X>> : never {
|
|
27
|
+
const Result: FC<any> = React.forwardRef<TComponent, any>((props: any, forwardRef) => {
|
|
28
|
+
const Custom = useCustom(key);
|
|
29
|
+
|
|
30
|
+
if (Custom === null) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (Custom) {
|
|
35
|
+
return <Custom {...props} ref={forwardRef} />;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return <Component {...props} ref={forwardRef} />;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
Component.displayName = Component.displayName || key;
|
|
42
|
+
Result.displayName = 'Customizable.' + Component.displayName;
|
|
43
|
+
|
|
44
|
+
return Object.assign(Result, { key, Component }) as any;
|
|
45
|
+
}
|
package/src/ui/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export * from './Chatify';
|
|
2
|
-
export * from './Avatar';
|
|
3
|
-
export * from './localizer';
|
|
4
|
-
export * from './AddChatButton';
|
|
5
|
-
export * from './Layout/Header';
|
|
6
|
-
export * from './ChatPanel/ChatHeader';
|
|
7
|
-
export * from './ChatPanel/ChatHeaderMembers';
|
|
8
|
-
export * from './ChatList/ChatListItemBox';
|
|
9
|
-
export * from './Message/MessageBox';
|
|
10
|
-
export * from './SystemMessage/SystemMessageBox';
|
|
11
|
-
export * from './Icon';
|
|
1
|
+
export * from './Chatify';
|
|
2
|
+
export * from './Avatar';
|
|
3
|
+
export * from './localizer';
|
|
4
|
+
export * from './AddChatButton';
|
|
5
|
+
export * from './Layout/Header';
|
|
6
|
+
export * from './ChatPanel/ChatHeader';
|
|
7
|
+
export * from './ChatPanel/ChatHeaderMembers';
|
|
8
|
+
export * from './ChatList/ChatListItemBox';
|
|
9
|
+
export * from './Message/MessageBox';
|
|
10
|
+
export * from './SystemMessage/SystemMessageBox';
|
|
11
|
+
export * from './Icon';
|