From 0a689b0ab8ad7e631e6604e975db8fe01257c446 Mon Sep 17 00:00:00 2001 From: archer <545436317@qq.com> Date: Fri, 28 Jul 2023 15:56:50 +0800 Subject: [PATCH] fix: save chat and hook --- client/src/pages/api/admin/initv4.ts | 4 +- client/src/pages/chat/components/ToolMenu.tsx | 58 ++++++++++--------- client/src/service/events/pushBill.ts | 2 +- client/src/service/utils/auth.ts | 4 +- client/src/service/utils/chat/saveChat.ts | 58 +++++++++++-------- 5 files changed, 71 insertions(+), 55 deletions(-) diff --git a/client/src/pages/api/admin/initv4.ts b/client/src/pages/api/admin/initv4.ts index ef7d67096..213a00d6c 100644 --- a/client/src/pages/api/admin/initv4.ts +++ b/client/src/pages/api/admin/initv4.ts @@ -385,8 +385,8 @@ async function init(limit: number, skip: number) { // 遍历 app const apps = await App.find( { - chat: { $ne: null } - // modules: { $exists: false }, + chat: { $ne: null }, + modules: { $exists: false } // userId: '63f9a14228d2a688d8dc9e1b' }, '_id chat' diff --git a/client/src/pages/chat/components/ToolMenu.tsx b/client/src/pages/chat/components/ToolMenu.tsx index f241cd5cb..706b5cdd7 100644 --- a/client/src/pages/chat/components/ToolMenu.tsx +++ b/client/src/pages/chat/components/ToolMenu.tsx @@ -1,4 +1,4 @@ -import React, { useRef } from 'react'; +import React, { useMemo } from 'react'; import { useChatBox } from '@/components/ChatBox'; import { ChatItemType } from '@/types/chat'; import { Menu, MenuButton, MenuList, MenuItem, Box } from '@chakra-ui/react'; @@ -8,30 +8,36 @@ import { useRouter } from 'next/router'; const ToolMenu = ({ history }: { history: ChatItemType[] }) => { const { onExportChat } = useChatBox(); const router = useRouter(); - const menuList = useRef([ - { - icon: 'chat', - label: '新对话', - onClick: () => { - router.push({ - query: { - appId: router.query?.appId - } - }); - } - }, - { - icon: 'apiLight', - label: 'HTML导出', - onClick: () => onExportChat({ type: 'html', history }) - }, - { - icon: 'markdown', - label: 'Markdown导出', - onClick: () => onExportChat({ type: 'md', history }) - }, - { icon: 'pdf', label: 'PDF导出', onClick: () => onExportChat({ type: 'pdf', history }) } - ]); + const { appId } = router.query; + + const menuList = useMemo( + () => [ + { + icon: 'chat', + label: '新对话', + onClick: () => { + router.push({ + query: { + appId + } + }); + } + }, + { + icon: 'apiLight', + label: 'HTML导出', + onClick: () => onExportChat({ type: 'html', history }) + }, + { + icon: 'markdown', + label: 'Markdown导出', + onClick: () => onExportChat({ type: 'md', history }) + }, + { icon: 'pdf', label: 'PDF导出', onClick: () => onExportChat({ type: 'pdf', history }) } + ], + [appId, history, onExportChat, router] + ); + return history.length > 0 ? (