From 64e893bc09bcfa5b62bad46fa241a488cbd8dcf1 Mon Sep 17 00:00:00 2001 From: xcatliu Date: Tue, 14 Nov 2023 18:27:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20--env=20=E6=94=AF=E6=8C=81=20gpt-4-visi?= =?UTF-8?q?on-preview?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/components/AttachImage.tsx | 32 +++++ app/components/History.tsx | 6 +- app/components/Menu.tsx | 2 +- app/components/Message.tsx | 118 ++++++++++++++++-- app/components/MessageDetail.tsx | 4 +- app/components/Settings.tsx | 4 +- app/components/TextareaForm.tsx | 39 +++--- app/components/buttons/AttachImageButton.tsx | 50 ++++++++ .../buttons/DeleteHistoryButton.tsx | 2 +- app/components/buttons/LoginButton.tsx | 2 +- app/components/buttons/MenuEntryButton.tsx | 2 + app/context/ChatContext.tsx | 86 ++++++++++++- app/context/SettingsContext.tsx | 8 +- app/globals.css | 19 ++- app/utils/constants.ts | 62 +++++---- app/utils/image.ts | 110 ++++++++++++++++ app/utils/message.ts | 30 ++++- 17 files changed, 499 insertions(+), 77 deletions(-) create mode 100644 app/components/AttachImage.tsx create mode 100644 app/components/buttons/AttachImageButton.tsx create mode 100644 app/utils/image.ts diff --git a/app/components/AttachImage.tsx b/app/components/AttachImage.tsx new file mode 100644 index 00000000..4be9ed05 --- /dev/null +++ b/app/components/AttachImage.tsx @@ -0,0 +1,32 @@ +'use client'; + +import { XMarkIcon } from '@heroicons/react/24/outline'; +import Image from 'next/image'; +import type { FC } from 'react'; +import { useContext } from 'react'; + +import { ChatContext } from '@/context/ChatContext'; + +import { AttachImageButton } from './buttons/AttachImageButton'; + +export const AttachImage: FC = () => { + const { images, deleteImage } = useContext(ChatContext)!; + + return ( +
+ + {[...images].reverse().map((imageProp, index) => ( +
+ { + // 因为前面将 images revert 了,所以这里需要计算真正的 index + deleteImage(images.length - 1 - index); + }} + /> + 图片 +
+ ))} +
+ ); +}; diff --git a/app/components/History.tsx b/app/components/History.tsx index d88b39da..d646ad48 100644 --- a/app/components/History.tsx +++ b/app/components/History.tsx @@ -11,7 +11,7 @@ import { SettingsContext } from '@/context/SettingsContext'; import { FULL_SPACE } from '@/utils/constants'; import { exportJSON } from '@/utils/export'; import { last } from '@/utils/last'; -import { getContent } from '@/utils/message'; +import { getContentText } from '@/utils/message'; import { DeleteHistoryButton } from './buttons/DeleteHistoryButton'; @@ -65,13 +65,13 @@ export const HistoryItemComp: FC<{ historyIndex: 'current' | number; isActive: b })} onClick={() => historyIndex !== 'current' && loadHistory(historyIndex)} > -

{getContent(historyItem.messages[0])}

+

{getContentText(historyItem.messages[0])}

- {historyItem.messages.length > 1 ? getContent(last(historyItem.messages)) : FULL_SPACE} + {historyItem.messages.length > 1 ? getContentText(last(historyItem.messages)) : FULL_SPACE}

{isActive && } diff --git a/app/components/Menu.tsx b/app/components/Menu.tsx index 803eed93..262231d9 100644 --- a/app/components/Menu.tsx +++ b/app/components/Menu.tsx @@ -107,7 +107,7 @@ const MenuTabs = () => { return (