listpage-next 0.0.201 → 0.0.203
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/features/ChatClient/components/ChatContent/index.d.ts +1 -2
- package/dist/features/ChatClient/components/ChatContent/index.js +1 -26
- package/dist/features/ChatClient/components/ChatPage/ChatPage.js +26 -2
- package/dist/features/ChatClient/context/useChatContext.d.ts +1 -0
- package/dist/features/ChatClient/context/useChatContext.js +2 -1
- package/package.json +1 -1
|
@@ -8,8 +8,7 @@ export interface ClientContentProps {
|
|
|
8
8
|
title?: string;
|
|
9
9
|
onTitleChange?: (title: string) => void;
|
|
10
10
|
onClickNewConversation?: () => void;
|
|
11
|
-
loading?: boolean;
|
|
12
11
|
senderProps?: ClientContentBodyProps['senderProps'];
|
|
13
12
|
bubbleProps?: ChatBubbleListProps;
|
|
14
13
|
}
|
|
15
|
-
export declare const ClientContent: (
|
|
14
|
+
export declare const ClientContent: (props: ClientContentProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect } from "react";
|
|
3
|
-
import { useRequest } from "ahooks";
|
|
4
2
|
import { styled } from "styled-components";
|
|
5
3
|
import { ClientContentBody } from "./ClientContentBody.js";
|
|
6
4
|
import { ClientContentHeader } from "./ClientContentHeader.js";
|
|
7
|
-
|
|
8
|
-
import { PageLoading } from "../../../../components/PageLayout/index.js";
|
|
9
|
-
const ClientContentComponent = (props)=>{
|
|
5
|
+
const ClientContent = (props)=>{
|
|
10
6
|
const { extra, style, className, title, onTitleChange, onClickNewConversation, senderProps, bubbleProps } = props;
|
|
11
7
|
return /*#__PURE__*/ jsxs(Container, {
|
|
12
8
|
style: style,
|
|
@@ -25,27 +21,6 @@ const ClientContentComponent = (props)=>{
|
|
|
25
21
|
]
|
|
26
22
|
});
|
|
27
23
|
};
|
|
28
|
-
const ClientContent = ({ loading, ...props })=>{
|
|
29
|
-
const { request, bubbleListRef } = useChatClientContext();
|
|
30
|
-
const { loading: loadingMessage, data } = useRequest(request.getMessages, {
|
|
31
|
-
ready: !loading && Boolean(request.getMessages)
|
|
32
|
-
});
|
|
33
|
-
useEffect(()=>{
|
|
34
|
-
if (!loadingMessage) setTimeout(()=>{
|
|
35
|
-
bubbleListRef.current?.scrollToBottom();
|
|
36
|
-
}, 500);
|
|
37
|
-
}, [
|
|
38
|
-
loadingMessage
|
|
39
|
-
]);
|
|
40
|
-
if (loading || loadingMessage) return /*#__PURE__*/ jsx(PageLoading, {});
|
|
41
|
-
return /*#__PURE__*/ jsx(MessageProvider, {
|
|
42
|
-
request: request.chat,
|
|
43
|
-
initialMessages: data || [],
|
|
44
|
-
children: /*#__PURE__*/ jsx(ClientContentComponent, {
|
|
45
|
-
...props
|
|
46
|
-
})
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
24
|
const Container = styled.div`
|
|
50
25
|
display: flex;
|
|
51
26
|
flex-direction: column;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
import { useRequest } from "ahooks";
|
|
4
|
+
import { PageLoading } from "../../../../components/index.js";
|
|
2
5
|
import { Sider } from "./Sider.js";
|
|
3
6
|
import { Logo } from "../Logo/index.js";
|
|
4
7
|
import { HistoryConversation } from "../HistoryConversation/index.js";
|
|
5
8
|
import { NewConversationButton } from "../NewConversationButton/index.js";
|
|
6
|
-
import { ChatClientProvider } from "../../context/index.js";
|
|
9
|
+
import { ChatClientProvider, MessageProvider, useChatClientContext } from "../../context/index.js";
|
|
7
10
|
import { Content, Layout } from "./styles.js";
|
|
8
11
|
const ChatPageComponent = (props)=>{
|
|
9
12
|
const { logo, title, children, action } = props;
|
|
@@ -25,11 +28,32 @@ const ChatPageComponent = (props)=>{
|
|
|
25
28
|
]
|
|
26
29
|
}),
|
|
27
30
|
/*#__PURE__*/ jsx(Content, {
|
|
28
|
-
children:
|
|
31
|
+
children: /*#__PURE__*/ jsx(ChatContentContainer, {
|
|
32
|
+
children: children
|
|
33
|
+
})
|
|
29
34
|
})
|
|
30
35
|
]
|
|
31
36
|
});
|
|
32
37
|
};
|
|
38
|
+
const ChatContentContainer = (props)=>{
|
|
39
|
+
const { request, bubbleListRef } = useChatClientContext();
|
|
40
|
+
const { loading: loadingMessage, data } = useRequest(request.getMessages, {
|
|
41
|
+
ready: Boolean(request.getMessages)
|
|
42
|
+
});
|
|
43
|
+
useEffect(()=>{
|
|
44
|
+
if (!loadingMessage) setTimeout(()=>{
|
|
45
|
+
bubbleListRef.current?.scrollToBottom();
|
|
46
|
+
}, 500);
|
|
47
|
+
}, [
|
|
48
|
+
loadingMessage
|
|
49
|
+
]);
|
|
50
|
+
if (loadingMessage) return /*#__PURE__*/ jsx(PageLoading, {});
|
|
51
|
+
return /*#__PURE__*/ jsx(MessageProvider, {
|
|
52
|
+
request: request.chat,
|
|
53
|
+
initialMessages: data || [],
|
|
54
|
+
children: props.children
|
|
55
|
+
});
|
|
56
|
+
};
|
|
33
57
|
const ChatPage = (props)=>/*#__PURE__*/ jsx(ChatClientProvider, {
|
|
34
58
|
request: props.request,
|
|
35
59
|
render: props.render,
|
|
@@ -5,6 +5,7 @@ export declare function useChatContext(): {
|
|
|
5
5
|
setMessages: (messages: import("./types").Message<any>[]) => void;
|
|
6
6
|
deleteConversation: ((key: string) => void) | undefined;
|
|
7
7
|
updateConversation: ((key: string, item: any) => void) | undefined;
|
|
8
|
+
refreshConversation: (() => void) | undefined;
|
|
8
9
|
scrollToBottom: () => void;
|
|
9
10
|
};
|
|
10
11
|
export type ChatInstance = ReturnType<typeof useChatContext>;
|
|
@@ -3,7 +3,7 @@ import { useMessageContext } from "./message.js";
|
|
|
3
3
|
function useChatContext() {
|
|
4
4
|
const { conversationAction, bubbleListRef } = useChatClientContext();
|
|
5
5
|
const { messages, sendMessage, appendMessage, setMessages } = useMessageContext();
|
|
6
|
-
const { deleteItem, updateItem } = conversationAction ?? {};
|
|
6
|
+
const { deleteItem, updateItem, refresh } = conversationAction ?? {};
|
|
7
7
|
return {
|
|
8
8
|
messages,
|
|
9
9
|
sendMessage,
|
|
@@ -11,6 +11,7 @@ function useChatContext() {
|
|
|
11
11
|
setMessages,
|
|
12
12
|
deleteConversation: deleteItem,
|
|
13
13
|
updateConversation: updateItem,
|
|
14
|
+
refreshConversation: refresh,
|
|
14
15
|
scrollToBottom: ()=>bubbleListRef.current?.scrollToBottom()
|
|
15
16
|
};
|
|
16
17
|
}
|