listpage-next 0.0.203 → 0.0.205
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/components/InfiniteList/index.d.ts +1 -1
- package/dist/components/InfiniteList/index.js +13 -6
- package/dist/features/ChatClient/components/ChatPage/ChatPage.d.ts +3 -0
- package/dist/features/ChatClient/components/ChatPage/ChatPage.js +3 -5
- package/dist/features/ChatClient/components/HistoryConversation/index.d.ts +0 -1
- package/dist/features/ChatClient/components/HistoryConversation/index.js +8 -4
- package/dist/features/ChatClient/context/client.d.ts +2 -0
- package/dist/features/ChatClient/context/client.js +3 -0
- package/dist/features/ChatClient/context/useChatContext.d.ts +3 -1
- package/dist/features/ChatClient/context/useChatContext.js +5 -3
- package/dist/features/ChatClient/context/useConversationListRef.d.ts +1 -1
- package/dist/features/ChatClient/ui/ConversationList/index.d.ts +2 -2
- package/dist/features/ChatClient/ui/ConversationList/index.js +3 -7
- package/package.json +1 -1
|
@@ -2,8 +2,8 @@ import { Ref } from 'react';
|
|
|
2
2
|
export type RenderActions<DataType = any> = {
|
|
3
3
|
updateItem: (key: string, item: DataType) => void;
|
|
4
4
|
deleteItem: (key: string) => void;
|
|
5
|
+
appendItem: (item: DataType, index?: number) => void;
|
|
5
6
|
resetPagination: () => void;
|
|
6
|
-
refresh: () => void;
|
|
7
7
|
};
|
|
8
8
|
export interface InfiniteListProps<DataType = any> {
|
|
9
9
|
request?: (params: {
|
|
@@ -13,7 +13,7 @@ const InfiniteList = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
13
13
|
const containerRef = useRef(null);
|
|
14
14
|
const [list, setList] = useState([]);
|
|
15
15
|
const [hasMore, setHasMore] = useState(true);
|
|
16
|
-
const { loading, run: loadMoreData
|
|
16
|
+
const { loading, run: loadMoreData } = useRequest(()=>{
|
|
17
17
|
if (!request) return Promise.resolve({
|
|
18
18
|
total: 0,
|
|
19
19
|
list: [],
|
|
@@ -38,6 +38,13 @@ const InfiniteList = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
38
38
|
if (!hasMore) message.info('没有更多数据了!');
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
|
+
const appendItem = (item, index = 0)=>{
|
|
42
|
+
const newList = [
|
|
43
|
+
...list
|
|
44
|
+
];
|
|
45
|
+
newList.splice(index, 0, item);
|
|
46
|
+
setList(newList);
|
|
47
|
+
};
|
|
41
48
|
const deleteItem = (key)=>{
|
|
42
49
|
const newList = list.filter((i)=>i[rowKey] !== key);
|
|
43
50
|
setList(newList);
|
|
@@ -59,13 +66,13 @@ const InfiniteList = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
59
66
|
useImperativeHandle(ref, ()=>({
|
|
60
67
|
deleteItem,
|
|
61
68
|
updateItem,
|
|
62
|
-
|
|
63
|
-
|
|
69
|
+
appendItem,
|
|
70
|
+
resetPagination
|
|
64
71
|
}), [
|
|
65
72
|
deleteItem,
|
|
66
73
|
updateItem,
|
|
67
74
|
resetPagination,
|
|
68
|
-
|
|
75
|
+
appendItem
|
|
69
76
|
]);
|
|
70
77
|
useEffect(()=>{
|
|
71
78
|
loadMoreData();
|
|
@@ -93,8 +100,8 @@ const InfiniteList = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
93
100
|
children: (item, index)=>renderItem(item, index, {
|
|
94
101
|
deleteItem,
|
|
95
102
|
updateItem,
|
|
96
|
-
|
|
97
|
-
|
|
103
|
+
appendItem,
|
|
104
|
+
resetPagination
|
|
98
105
|
})
|
|
99
106
|
})
|
|
100
107
|
});
|
|
@@ -8,4 +8,7 @@ export interface ChatPageProps<SessionData = any, MessageInfo extends BaseMessag
|
|
|
8
8
|
request: ChatRequest<SessionData, MessageInfo>;
|
|
9
9
|
render: ChatRender<MessageInfo>;
|
|
10
10
|
}
|
|
11
|
+
export declare const ChatContentContext: (props: {
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
11
14
|
export declare const ChatPage: (props: ChatPageProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -28,14 +28,12 @@ const ChatPageComponent = (props)=>{
|
|
|
28
28
|
]
|
|
29
29
|
}),
|
|
30
30
|
/*#__PURE__*/ jsx(Content, {
|
|
31
|
-
children:
|
|
32
|
-
children: children
|
|
33
|
-
})
|
|
31
|
+
children: children
|
|
34
32
|
})
|
|
35
33
|
]
|
|
36
34
|
});
|
|
37
35
|
};
|
|
38
|
-
const
|
|
36
|
+
const ChatContentContext = (props)=>{
|
|
39
37
|
const { request, bubbleListRef } = useChatClientContext();
|
|
40
38
|
const { loading: loadingMessage, data } = useRequest(request.getMessages, {
|
|
41
39
|
ready: Boolean(request.getMessages)
|
|
@@ -62,4 +60,4 @@ const ChatPage = (props)=>/*#__PURE__*/ jsx(ChatClientProvider, {
|
|
|
62
60
|
...props
|
|
63
61
|
})
|
|
64
62
|
});
|
|
65
|
-
export { ChatPage };
|
|
63
|
+
export { ChatContentContext, ChatPage };
|
|
@@ -7,20 +7,24 @@ import { useChatClientContext } from "../../context/index.js";
|
|
|
7
7
|
import { ConversationList } from "../../ui/ConversationList/index.js";
|
|
8
8
|
import { HeaderContainer, HeaderTitle, HistoryConversationContainer } from "./styles.js";
|
|
9
9
|
const HistoryConversation = (props)=>{
|
|
10
|
-
const { rowKey = 'id'
|
|
11
|
-
const { showUpdateTitleModal, conversationListRef, action, request } = useChatClientContext();
|
|
10
|
+
const { rowKey = 'id' } = props;
|
|
11
|
+
const { showUpdateTitleModal, conversationListRef, action, request, activeConversation, setActiveConversation } = useChatClientContext();
|
|
12
12
|
const { onClickConversation, onRenameConversation, onDeleteConversation } = action ?? {};
|
|
13
13
|
return /*#__PURE__*/ jsxs(HistoryConversationContainer, {
|
|
14
14
|
children: [
|
|
15
15
|
/*#__PURE__*/ jsx(Header, {}),
|
|
16
16
|
/*#__PURE__*/ jsx(ConversationList, {
|
|
17
17
|
rowKey: rowKey,
|
|
18
|
-
|
|
18
|
+
activeKey: activeConversation,
|
|
19
19
|
request: request.getConversations,
|
|
20
20
|
ref: conversationListRef,
|
|
21
|
-
onSelectConversation: (data)=>
|
|
21
|
+
onSelectConversation: (data)=>{
|
|
22
|
+
onClickConversation?.(data[rowKey], data);
|
|
23
|
+
setActiveConversation?.(data[rowKey]);
|
|
24
|
+
},
|
|
22
25
|
onDeleteConversation: (data)=>{
|
|
23
26
|
onDeleteConversation?.(data[rowKey], data);
|
|
27
|
+
setActiveConversation?.('new');
|
|
24
28
|
},
|
|
25
29
|
onRenameConversation: (data)=>new Promise((resolve)=>{
|
|
26
30
|
showUpdateTitleModal(data.title, async (newTitle)=>{
|
|
@@ -21,6 +21,8 @@ export interface ChatClientContextProps<SessionData = any, MessageInfo extends B
|
|
|
21
21
|
request: ChatRequest<SessionData, MessageInfo>;
|
|
22
22
|
render: ChatRender<MessageInfo>;
|
|
23
23
|
action?: ChatActionEvent<SessionData>;
|
|
24
|
+
activeConversation?: string;
|
|
25
|
+
setActiveConversation?: (key?: string) => void;
|
|
24
26
|
collapsed: boolean;
|
|
25
27
|
setCollapsed: (collapsed: boolean) => void;
|
|
26
28
|
showUpdateTitleModal: (title: string, onSubmit?: (title: string) => any) => void;
|
|
@@ -9,6 +9,7 @@ const ChatClientProvider = (props)=>{
|
|
|
9
9
|
const { updateTitleModalEle, showUpdateTitleModal } = useUpdateTitleModal();
|
|
10
10
|
const [collapsed, setCollapsed] = useState(false);
|
|
11
11
|
const { conversationListRef, ...conversationActions } = useConversationListRef();
|
|
12
|
+
const [activeConversation, setActiveConversation] = useState();
|
|
12
13
|
const { bubbleListRef } = useBubbleListRef();
|
|
13
14
|
return /*#__PURE__*/ jsxs(ChatClientContext.Provider, {
|
|
14
15
|
value: {
|
|
@@ -18,6 +19,8 @@ const ChatClientProvider = (props)=>{
|
|
|
18
19
|
collapsed,
|
|
19
20
|
setCollapsed,
|
|
20
21
|
showUpdateTitleModal,
|
|
22
|
+
activeConversation,
|
|
23
|
+
setActiveConversation,
|
|
21
24
|
conversationListRef,
|
|
22
25
|
bubbleListRef,
|
|
23
26
|
conversationAction: conversationActions
|
|
@@ -3,9 +3,11 @@ export declare function useChatContext(): {
|
|
|
3
3
|
sendMessage: (info: any, callback?: ((info: any) => void) | undefined) => void;
|
|
4
4
|
appendMessage: (message: import("./types").Message<any>) => void;
|
|
5
5
|
setMessages: (messages: import("./types").Message<any>[]) => void;
|
|
6
|
+
activeConversation: string | undefined;
|
|
7
|
+
setActiveConversation: ((key?: string) => void) | undefined;
|
|
6
8
|
deleteConversation: ((key: string) => void) | undefined;
|
|
7
9
|
updateConversation: ((key: string, item: any) => void) | undefined;
|
|
8
|
-
|
|
10
|
+
appendConversation: ((item: any, index?: number) => void) | undefined;
|
|
9
11
|
scrollToBottom: () => void;
|
|
10
12
|
};
|
|
11
13
|
export type ChatInstance = ReturnType<typeof useChatContext>;
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { useChatClientContext } from "./client.js";
|
|
2
2
|
import { useMessageContext } from "./message.js";
|
|
3
3
|
function useChatContext() {
|
|
4
|
-
const { conversationAction, bubbleListRef } = useChatClientContext();
|
|
4
|
+
const { conversationAction, bubbleListRef, setActiveConversation, activeConversation } = useChatClientContext();
|
|
5
5
|
const { messages, sendMessage, appendMessage, setMessages } = useMessageContext();
|
|
6
|
-
const { deleteItem, updateItem,
|
|
6
|
+
const { deleteItem, updateItem, appendItem } = conversationAction ?? {};
|
|
7
7
|
return {
|
|
8
8
|
messages,
|
|
9
9
|
sendMessage,
|
|
10
10
|
appendMessage,
|
|
11
11
|
setMessages,
|
|
12
|
+
activeConversation,
|
|
13
|
+
setActiveConversation,
|
|
12
14
|
deleteConversation: deleteItem,
|
|
13
15
|
updateConversation: updateItem,
|
|
14
|
-
|
|
16
|
+
appendConversation: appendItem,
|
|
15
17
|
scrollToBottom: ()=>bubbleListRef.current?.scrollToBottom()
|
|
16
18
|
};
|
|
17
19
|
}
|
|
@@ -2,7 +2,7 @@ import { RenderActions } from "../../../components/InfiniteList";
|
|
|
2
2
|
export declare function useConversationListRef<DataType = any>(): {
|
|
3
3
|
updateItem?: ((key: string, item: DataType) => void) | undefined;
|
|
4
4
|
deleteItem?: ((key: string) => void) | undefined;
|
|
5
|
+
appendItem?: ((item: DataType, index?: number) => void) | undefined;
|
|
5
6
|
resetPagination?: (() => void) | undefined;
|
|
6
|
-
refresh?: (() => void) | undefined;
|
|
7
7
|
conversationListRef: import("react").RefObject<RenderActions<DataType> | null>;
|
|
8
8
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ItemType } from 'antd/es/menu/interface';
|
|
2
|
-
import { InfiniteListProps, InfiniteListRef, RenderActions } from '../../../../components
|
|
2
|
+
import { InfiniteListProps, InfiniteListRef, RenderActions } from '../../../../components';
|
|
3
3
|
export interface ConversationListProps<T = any> {
|
|
4
4
|
rowKey: string;
|
|
5
5
|
ref?: InfiniteListRef<T>;
|
|
6
|
-
|
|
6
|
+
activeKey?: string;
|
|
7
7
|
request: InfiniteListProps<T>['request'];
|
|
8
8
|
menus?: (Omit<ItemType, 'onClick'> & {
|
|
9
9
|
key?: string;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useState } from "react";
|
|
3
2
|
import { Avatar, Button, Dropdown, Typography } from "antd";
|
|
4
|
-
import { ListContainer, ListItemContainer, ListText } from "./styles.js";
|
|
5
3
|
import { MessageOutlined, MoreOutlined } from "@ant-design/icons";
|
|
6
|
-
import {
|
|
4
|
+
import { ListContainer, ListItemContainer, ListText } from "./styles.js";
|
|
5
|
+
import { InfiniteList } from "../../../../components/index.js";
|
|
7
6
|
const ConversationList = (props)=>{
|
|
8
|
-
const { ref, rowKey, request, menus = [],
|
|
9
|
-
const [activeKey, setActiveKey] = useState(defaultActiveKey);
|
|
7
|
+
const { ref, rowKey, request, menus = [], activeKey, onSelectConversation, onDeleteConversation, onRenameConversation } = props;
|
|
10
8
|
return /*#__PURE__*/ jsx(ListContainer, {
|
|
11
9
|
children: /*#__PURE__*/ jsx(InfiniteList, {
|
|
12
10
|
pageSize: 10,
|
|
@@ -35,7 +33,6 @@ const ConversationList = (props)=>{
|
|
|
35
33
|
label: '删除',
|
|
36
34
|
onClick: async ()=>{
|
|
37
35
|
await onDeleteConversation?.(item);
|
|
38
|
-
if (key === activeKey) setActiveKey('');
|
|
39
36
|
actions.deleteItem(key);
|
|
40
37
|
}
|
|
41
38
|
}
|
|
@@ -44,7 +41,6 @@ const ConversationList = (props)=>{
|
|
|
44
41
|
isHover: activeKey === key ? true : void 0,
|
|
45
42
|
onClick: ()=>{
|
|
46
43
|
if (activeKey === key) return;
|
|
47
|
-
setActiveKey?.(key);
|
|
48
44
|
onSelectConversation?.(item);
|
|
49
45
|
},
|
|
50
46
|
children: [
|