listpage-next 0.0.92 → 0.0.94
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/ClientContent/BubbleList.js +1 -1
- package/dist/features/ChatClient/components/ClientContent/index.d.ts +6 -3
- package/dist/features/ChatClient/components/ClientContent/index.js +12 -12
- package/dist/features/ChatClient/context/message.js +9 -7
- package/package.json +1 -1
|
@@ -16,7 +16,7 @@ const BubbleList = (props)=>{
|
|
|
16
16
|
const scrollToBottomWhenAtBottom = (behavior = "instant")=>{
|
|
17
17
|
const ele = containerRef.current;
|
|
18
18
|
if (ele) {
|
|
19
|
-
if (Math.abs(ele.scrollHeight - ele.scrollTop - ele.clientHeight) <
|
|
19
|
+
if (Math.abs(ele.scrollHeight - ele.scrollTop - ele.clientHeight) < 200) scrollToBottom(behavior);
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
useImperativeHandle(bubbleListRef, ()=>({
|
|
@@ -2,10 +2,13 @@ import { FooterProps } from "./Footer";
|
|
|
2
2
|
import { HeaderProps } from "./Header";
|
|
3
3
|
import { BubbleListProps } from "./BubbleList";
|
|
4
4
|
export interface ClientContentProps {
|
|
5
|
-
className?: string;
|
|
6
5
|
style?: React.CSSProperties;
|
|
7
|
-
|
|
6
|
+
className?: string;
|
|
7
|
+
title?: string;
|
|
8
|
+
onTitleChange?: (title: string) => void;
|
|
9
|
+
loading?: boolean;
|
|
10
|
+
headerProps?: Omit<HeaderProps, 'defaultTitle' | 'onTitleChange'>;
|
|
8
11
|
footerProps?: FooterProps;
|
|
9
12
|
bubbleProps?: BubbleListProps;
|
|
10
13
|
}
|
|
11
|
-
export declare const ClientContent: (props: ClientContentProps) => import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export declare const ClientContent: ({ loading, ...props }: ClientContentProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect } from "react";
|
|
2
3
|
import { useRequest } from "ahooks";
|
|
3
4
|
import { Footer } from "./Footer.js";
|
|
4
5
|
import { Header } from "./Header.js";
|
|
@@ -6,14 +7,15 @@ import { BubbleList } from "./BubbleList.js";
|
|
|
6
7
|
import { MessageProvider, useChatClientContext } from "../../context/index.js";
|
|
7
8
|
import { PageLoading } from "../../../../components/Page/components/Loading/index.js";
|
|
8
9
|
import { Container } from "./styles.js";
|
|
9
|
-
import { useEffect } from "react";
|
|
10
10
|
const ClientContentComponent = (props)=>{
|
|
11
|
-
const { style, className, headerProps, footerProps, bubbleProps } = props;
|
|
11
|
+
const { style, className, title, onTitleChange, headerProps, footerProps, bubbleProps } = props;
|
|
12
12
|
return /*#__PURE__*/ jsxs(Container, {
|
|
13
13
|
style: style,
|
|
14
14
|
className: className,
|
|
15
15
|
children: [
|
|
16
16
|
/*#__PURE__*/ jsx(Header, {
|
|
17
|
+
defaultTitle: title,
|
|
18
|
+
onTitleChange: onTitleChange,
|
|
17
19
|
...headerProps
|
|
18
20
|
}),
|
|
19
21
|
/*#__PURE__*/ jsx(BubbleList, {
|
|
@@ -25,21 +27,19 @@ const ClientContentComponent = (props)=>{
|
|
|
25
27
|
]
|
|
26
28
|
});
|
|
27
29
|
};
|
|
28
|
-
const ClientContent = (props)=>{
|
|
30
|
+
const ClientContent = ({ loading, ...props })=>{
|
|
29
31
|
const { request, bubbleListRef } = useChatClientContext();
|
|
30
|
-
const { loading, data } = useRequest(request.getMessages
|
|
32
|
+
const { loading: loadingMessage, data } = useRequest(request.getMessages, {
|
|
33
|
+
ready: loading
|
|
34
|
+
});
|
|
31
35
|
useEffect(()=>{
|
|
32
|
-
if (
|
|
36
|
+
if (!loadingMessage) setTimeout(()=>{
|
|
33
37
|
bubbleListRef.current?.scrollToBottom();
|
|
34
|
-
},
|
|
38
|
+
}, 500);
|
|
35
39
|
}, [
|
|
36
|
-
|
|
40
|
+
loadingMessage
|
|
37
41
|
]);
|
|
38
|
-
if (loading) return /*#__PURE__*/ jsx(
|
|
39
|
-
style: props.style,
|
|
40
|
-
className: props.className,
|
|
41
|
-
children: /*#__PURE__*/ jsx(PageLoading, {})
|
|
42
|
-
});
|
|
42
|
+
if (loading || loadingMessage) return /*#__PURE__*/ jsx(PageLoading, {});
|
|
43
43
|
return /*#__PURE__*/ jsx(MessageProvider, {
|
|
44
44
|
request: request.chat,
|
|
45
45
|
initialMessages: data || [],
|
|
@@ -48,11 +48,11 @@ const MessageProvider = ({ initialMessages, children, request })=>{
|
|
|
48
48
|
message.id = info.id;
|
|
49
49
|
}
|
|
50
50
|
}, []);
|
|
51
|
-
const completeAssistantMessage = useCallback((id, info)=>{
|
|
51
|
+
const completeAssistantMessage = useCallback((id, info, status)=>{
|
|
52
52
|
const index = messagesRef.current.findIndex((msg)=>msg.id === id);
|
|
53
53
|
if (-1 !== index) {
|
|
54
54
|
const message = messagesRef.current[index];
|
|
55
|
-
message.status = 'success';
|
|
55
|
+
message.status = status || 'success';
|
|
56
56
|
message.info = info;
|
|
57
57
|
message.id = info.id;
|
|
58
58
|
}
|
|
@@ -77,9 +77,6 @@ const MessageProvider = ({ initialMessages, children, request })=>{
|
|
|
77
77
|
onCreated: (info)=>{
|
|
78
78
|
completeUserMessage(info);
|
|
79
79
|
createAssistantMessage();
|
|
80
|
-
console.log([
|
|
81
|
-
...messagesRef.current
|
|
82
|
-
]);
|
|
83
80
|
setMessages([
|
|
84
81
|
...messagesRef.current
|
|
85
82
|
]);
|
|
@@ -96,12 +93,16 @@ const MessageProvider = ({ initialMessages, children, request })=>{
|
|
|
96
93
|
setMessages([
|
|
97
94
|
...messagesRef.current
|
|
98
95
|
]);
|
|
96
|
+
setIsRequesting(false);
|
|
97
|
+
onUpdate?.(info);
|
|
99
98
|
},
|
|
100
99
|
onError: (id, info)=>{
|
|
101
|
-
completeAssistantMessage(id, info);
|
|
100
|
+
completeAssistantMessage(id, info, 'failed');
|
|
102
101
|
setMessages([
|
|
103
102
|
...messagesRef.current
|
|
104
103
|
]);
|
|
104
|
+
setIsRequesting(false);
|
|
105
|
+
onUpdate?.(info);
|
|
105
106
|
}
|
|
106
107
|
});
|
|
107
108
|
}, [
|
|
@@ -111,7 +112,8 @@ const MessageProvider = ({ initialMessages, children, request })=>{
|
|
|
111
112
|
createUserMessage,
|
|
112
113
|
request,
|
|
113
114
|
updateMessage,
|
|
114
|
-
setMessages
|
|
115
|
+
setMessages,
|
|
116
|
+
setIsRequesting
|
|
115
117
|
]);
|
|
116
118
|
return /*#__PURE__*/ jsx(MessageContext.Provider, {
|
|
117
119
|
value: {
|