listpage-next 0.0.203 → 0.0.204

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.
@@ -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, refresh } = useRequest(()=>{
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
- resetPagination,
63
- refresh
69
+ appendItem,
70
+ resetPagination
64
71
  }), [
65
72
  deleteItem,
66
73
  updateItem,
67
74
  resetPagination,
68
- refresh
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
- resetPagination,
97
- refresh
103
+ appendItem,
104
+ resetPagination
98
105
  })
99
106
  })
100
107
  });
@@ -1,5 +1,4 @@
1
1
  export interface HistoryConversationProps {
2
2
  rowKey?: string;
3
- defaultActiveKey?: string;
4
3
  }
5
4
  export declare const HistoryConversation: (props: HistoryConversationProps) => import("react/jsx-runtime").JSX.Element;
@@ -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', defaultActiveKey } = props;
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
- defaultActiveKey: defaultActiveKey,
18
+ activeKey: activeConversation,
19
19
  request: request.getConversations,
20
20
  ref: conversationListRef,
21
- onSelectConversation: (data)=>onClickConversation?.(data[rowKey], 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
- refreshConversation: (() => void) | undefined;
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, refresh } = conversationAction ?? {};
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
- refreshConversation: refresh,
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/InfiniteList';
2
+ import { InfiniteListProps, InfiniteListRef, RenderActions } from '../../../../components';
3
3
  export interface ConversationListProps<T = any> {
4
4
  rowKey: string;
5
5
  ref?: InfiniteListRef<T>;
6
- defaultActiveKey?: string;
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 { InfiniteList } from "../../../../components/InfiniteList/index.js";
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 = [], defaultActiveKey, onSelectConversation, onDeleteConversation, onRenameConversation } = props;
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: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "listpage-next",
3
- "version": "0.0.203",
3
+ "version": "0.0.204",
4
4
  "description": "A React component library for creating filter forms with Ant Design",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",