This commit is contained in:
archer
2023-07-18 11:50:16 +08:00
parent f9d83c481f
commit 505aff3dbf
26 changed files with 216 additions and 210 deletions

View File

@@ -20,12 +20,12 @@ import { getErrText } from '@/utils/tools';
import { QuoteItemType } from '@/pages/api/app/modules/kb/search';
const QuoteModal = ({
historyId,
chatId,
contentId,
rawSearch = [],
onClose
}: {
historyId?: string;
chatId?: string;
contentId?: string;
rawSearch?: QuoteItemType[];
onClose: () => void;
@@ -45,8 +45,8 @@ const QuoteModal = ({
refetch,
isLoading
} = useQuery(['getHistoryQuote'], () => {
if (historyId && contentId) {
return getHistoryQuote({ historyId, contentId });
if (chatId && contentId) {
return getHistoryQuote({ chatId, contentId });
}
if (rawSearch.length > 0) {
return rawSearch;
@@ -59,12 +59,12 @@ const QuoteModal = ({
*/
const updateQuoteStatus = useCallback(
async (quoteId: string, sourceText: string) => {
if (!historyId || !contentId) return;
if (!chatId || !contentId) return;
setIsLoading(true);
try {
await updateHistoryQuote({
contentId,
historyId,
chatId,
quoteId,
sourceText
});
@@ -78,7 +78,7 @@ const QuoteModal = ({
}
setIsLoading(false);
},
[contentId, historyId, refetch, setIsLoading, toast]
[contentId, chatId, refetch, setIsLoading, toast]
);
/**

View File

@@ -49,7 +49,7 @@ export type StartChatFnProps = {
export type ComponentRef = {
getChatHistory: () => ChatSiteItemType[];
resetVariables: (data?: Record<string, any>) => void;
resetHistory: (history: ChatSiteItemType[]) => void;
resetHistory: (chatId: ChatSiteItemType[]) => void;
scrollToBottom: (behavior?: 'smooth' | 'auto') => void;
};
@@ -76,11 +76,10 @@ const Empty = () => {
return (
<Box
minH={'100%'}
pt={[6, 0]}
w={'85%'}
maxW={'600px'}
m={'auto'}
py={'5vh'}
alignItems={'center'}
justifyContent={'center'}
>
@@ -110,7 +109,7 @@ const ChatAvatar = ({
const ChatBox = (
{
showEmptyIntro = false,
historyId,
chatId,
appAvatar,
variableModules,
welcomeText,
@@ -119,7 +118,7 @@ const ChatBox = (
onDelMessage
}: {
showEmptyIntro?: boolean;
historyId?: string;
chatId?: string;
appAvatar: string;
variableModules?: VariableItemType[];
welcomeText?: string;
@@ -389,14 +388,16 @@ const ChatBox = (
};
const showEmpty = useMemo(
() => showEmptyIntro && chatHistory.length === 0 && !(variableModules || welcomeText),
() => showEmptyIntro && chatHistory.length === 0 && !variableModules?.length && !welcomeText,
[chatHistory.length, showEmptyIntro, variableModules, welcomeText]
);
return (
<Flex flexDirection={'column'} h={'100%'}>
<Box ref={ChatBoxRef} flex={'1 0 0'} h={0} overflow={'overlay'} px={[2, 5, 7]} py={[0, 5]}>
<Box ref={ChatBoxRef} flex={'1 0 0'} h={0} overflow={'overlay'} px={[2, 5, 7]} pt={[0, 5]}>
<Box maxW={['100%', '1000px', '1200px']} h={'100%'} mx={'auto'}>
{showEmpty && <Empty />}
{!!welcomeText && (
<Flex alignItems={'flex-start'} py={2}>
{/* avatar */}
@@ -410,7 +411,7 @@ const ChatBox = (
</Flex>
)}
{/* variable input */}
{variableModules && (
{!!variableModules?.length && (
<Flex alignItems={'flex-start'} py={2}>
{/* avatar */}
<ChatAvatar src={appAvatar} order={1} mr={['6px', 2]} />
@@ -467,7 +468,7 @@ const ChatBox = (
)}
{/* chat history */}
<Box id={'history'} pb={[8, 2]}>
<Box id={'history'} pb={8}>
{chatHistory.map((item, index) => (
<Flex
key={item._id}
@@ -606,13 +607,11 @@ const ChatBox = (
</Flex>
))}
</Box>
{showEmpty && <Empty />}
</Box>
</Box>
{/* input */}
{variableIsFinish ? (
<Box m={['0 auto', '20px auto']} w={'100%'} maxW={['auto', 'min(750px, 100%)']} px={[0, 5]}>
<Box m={['0 auto', '10px auto']} w={'100%'} maxW={['auto', 'min(750px, 100%)']} px={[0, 5]}>
<Box
py={'18px'}
position={'relative'}
@@ -696,12 +695,11 @@ const ChatBox = (
{/* quote modal */}
{!!quoteModalData && (
<QuoteModal
historyId={historyId}
chatId={chatId}
{...quoteModalData}
onClose={() => setQuoteModalData(undefined)}
/>
)}
{/* quote modal */}
</Flex>
);
};

View File

@@ -17,14 +17,14 @@ export enum NavbarTypeEnum {
const Navbar = ({ unread }: { unread: number }) => {
const router = useRouter();
const { userInfo } = useUserStore();
const { lastChatAppId, lastHistoryId } = useChatStore();
const { lastChatAppId, lastChatId } = useChatStore();
const navbarList = useMemo(
() => [
{
label: '聊天',
icon: 'chatLight',
activeIcon: 'chatFill',
link: `/chat?appId=${lastChatAppId}&historyId=${lastHistoryId}`,
link: `/chat?appId=${lastChatAppId}&chatId=${lastChatId}`,
activeLink: ['/chat']
},
{
@@ -56,7 +56,7 @@ const Navbar = ({ unread }: { unread: number }) => {
activeLink: ['/number']
}
],
[lastHistoryId, lastChatAppId]
[lastChatId, lastChatAppId]
);
const itemStyles: any = {

View File

@@ -7,13 +7,13 @@ import Badge from '../Badge';
const NavbarPhone = ({ unread }: { unread: number }) => {
const router = useRouter();
const { lastChatAppId, lastHistoryId } = useChatStore();
const { lastChatAppId, lastChatId } = useChatStore();
const navbarList = useMemo(
() => [
{
label: '聊天',
icon: 'chatLight',
link: `/chat?appId=${lastChatAppId}&historyId=${lastHistoryId}`,
link: `/chat?appId=${lastChatAppId}&chatId=${lastChatId}`,
activeLink: ['/chat'],
unread: 0
},
@@ -39,7 +39,7 @@ const NavbarPhone = ({ unread }: { unread: number }) => {
unread
}
],
[lastHistoryId, lastChatAppId, unread]
[lastChatId, lastChatAppId, unread]
);
return (

View File

@@ -43,6 +43,7 @@ const Markdown = ({ source, isChatting = false }: { source: string; isChatting?:
a: Link,
img: Image,
pre: 'div',
p: 'div',
code: Code
}}
>