From 48e347ea5e88686bbf34261afef59204f10b2ea8 Mon Sep 17 00:00:00 2001 From: gray Date: Tue, 10 Dec 2024 17:23:33 +0800 Subject: [PATCH] optimize structure --- .../components/Chat/MemoizedChatMessage.tsx | 9 --- src/FE/components/Search/index.ts | 1 - src/FE/components/Spinner/index.ts | 1 - src/FE/pages/_app.tsx | 5 +- .../_components/ChangeModel}/ChangeModel.tsx | 7 +-- .../_components/ChatError}/ChatError.tsx | 1 - .../_components}/ChatIcon/ChatIcon.tsx | 5 +- .../ChatMessage/ChangeModelAction.tsx | 4 +- .../_components}/ChatMessage/ChatMessage.tsx | 25 +++++--- .../_components}/ChatMessage/CopyAction.tsx | 2 +- .../_components}/ChatMessage/EditAction.tsx | 3 +- .../ChatMessage/GenerateInformationAction.tsx | 33 ++++++---- .../ChatMessage/PaginationAction.tsx | 0 .../ChatMessage/RegenerateAction.tsx | 2 +- .../ChatMessage/ResponseMessage.tsx | 18 ++---- .../ChatMessage/ResponseMessageActions.tsx | 18 ++---- .../_components}/ChatMessage/UserMessage.tsx | 15 ++--- .../_components}/ChatMessage/index.ts | 0 .../_components}/Markdown/CodeBlock.tsx | 0 .../Markdown/MemoizedReactMarkdown.tsx | 0 .../_components}/Search/Search.tsx | 2 +- .../_components}/Tips/Tips.tsx | 0 .../_components}/Files/FileServiceModal.tsx | 0 .../GlobalConfigs/GlobalConfigsModal.tsx | 0 .../InvitationCode/InvitationCodeModal.tsx | 0 .../LoginService/LoginServiceModal.tsx | 0 .../_components}/Messages/ChatMessage.tsx | 63 ++++++++----------- .../ModelKeys/ConfigModelModal.tsx | 4 +- .../_components}/ModelKeys/ModelKeysModal.tsx | 9 +-- .../_components}/Models/AddModelModal.tsx | 0 .../_components}/Models/EditModelModal.tsx | 0 .../admin/_components}/Nav/Nav.tsx | 0 .../_components}/Pagiation/Pagiation.tsx | 0 .../PayService/PayServiceModal.tsx | 0 .../RequestLogs/RequestLogDetailsModal.tsx | 0 .../Users/EditUserBalanceModel.tsx | 0 .../_components}/Users/EditUserModelModal.tsx | 0 .../Users/UserInitialConfigModal.tsx | 0 .../admin/_components}/Users/UserModal.tsx | 0 src/FE/pages/admin/file-service/index.tsx | 2 +- src/FE/pages/admin/global-configs/index.tsx | 2 +- src/FE/pages/admin/invitation-code/index.tsx | 2 +- src/FE/pages/admin/layout/index.tsx | 2 +- src/FE/pages/admin/login-service/index.tsx | 2 +- src/FE/pages/admin/messages/index.tsx | 2 +- src/FE/pages/admin/model-keys/index.tsx | 4 +- src/FE/pages/admin/models/index.tsx | 4 +- src/FE/pages/admin/pay-service/index.tsx | 2 +- src/FE/pages/admin/request-logs/index.tsx | 4 +- src/FE/pages/admin/user-config/index.tsx | 2 +- src/FE/pages/admin/users/index.tsx | 8 +-- .../home/_components}/Button/CopyButton.tsx | 0 .../Button/SidebarActionButton.tsx | 0 .../home/_components}/Button/UploadButton.tsx | 2 +- .../home/_components}/Chat/AccountBalance.tsx | 2 +- .../home/_components}/Chat/Chat.tsx | 12 +++- .../_components}/Chat/ChatButtonTooltip.tsx | 0 .../home/_components}/Chat/ChatInput.tsx | 8 +-- .../home/_components}/Chat/ChatLoader.tsx | 0 .../_components}/Chat/EnableNetworkSearch.tsx | 0 .../_components/Chat/MemoizedChatMessage.tsx | 10 +++ .../home/_components}/Chat/ModelSelect.tsx | 4 +- .../home/_components}/Chat/NoModel.tsx | 2 +- .../home/_components}/Chat/PromptList.tsx | 0 .../_components}/Chat/SharedMessageModal.tsx | 0 .../home/_components}/Chat/SystemPrompt.tsx | 0 .../home/_components}/Chat/Temperature.tsx | 2 +- .../home/_components}/Chat/VariableModal.tsx | 0 .../ChatSettings/ChatSettings.tsx | 0 .../ChatSettings/ChatSettingsBar.tsx | 4 +- .../ChatSettings/SliderSetting.tsx | 0 .../_components}/Chatbar/Chatbar.context.tsx | 0 .../_components}/Chatbar/Chatbar.state.tsx | 0 .../home/_components}/Chatbar/Chatbar.tsx | 4 +- .../_components}/Chatbar/ChatbarSettings.tsx | 10 +-- .../Chatbar/ClearConversations.tsx | 2 +- .../_components}/Chatbar/Conversation.tsx | 10 +-- .../_components}/Chatbar/Conversations.tsx | 2 +- .../_components}/HomeContent/HomeContent.tsx | 15 +++-- .../Modal/ChangePasswordModal.tsx | 0 .../_components}/Modal/UserBalanceModal.tsx | 0 .../_components}/ModeToggle/ModeTooggle.tsx | 0 .../PageNotFound/PageNotFound.tsx | 0 .../_components}/PasteUpload/PasteUpload.tsx | 0 .../_components}/Popover/DateTimePopover.tsx | 0 .../_components}/Popover/DeletePopover.tsx | 0 .../Promptbar/PromptBar.context.tsx | 0 .../Promptbar/Promptbar.state.tsx | 0 .../home/_components}/Promptbar/Promptbar.tsx | 4 +- .../Promptbar/components/Prompt.tsx | 2 +- .../Promptbar/components/PromptModal.tsx | 6 +- .../components/PromptbarSettings.tsx | 0 .../Promptbar/components/Prompts.tsx | 0 .../home/_components}/Promptbar/index.ts | 0 .../Settings/ApiKeyTabContent.tsx | 6 +- .../_components}/Settings/SettingModal.tsx | 0 .../_components}/Sidebar/OpenCloseButton.tsx | 0 .../home/_components}/Sidebar/Sidebar.tsx | 4 +- .../_components}/Sidebar/SidebarButton.tsx | 0 .../home/_components}/Sidebar/index.ts | 0 .../home/_components}/Spinner/Spinner.tsx | 0 .../home/_contents}/Home.context.ts | 0 src/FE/pages/home/index.tsx | 2 +- .../login/_components}/AccountLoginCard.tsx | 0 .../login/_components}/KeyCloakLogin.tsx | 0 .../login/_components}/PhoneLoginCard.tsx | 0 .../login/_components}/PhoneRegisterCard.tsx | 0 .../login/_components}/WeChatLogin.tsx | 0 .../login/_components}/WeChatLoginModal.tsx | 2 +- src/FE/pages/login/_components/index.ts | 13 ++++ src/FE/pages/login/index.tsx | 13 ++-- src/FE/pages/message/[id].tsx | 3 +- src/FE/pages/share/[id].tsx | 12 ++-- .../Theme => providers}/ThemeProvider.tsx | 0 114 files changed, 208 insertions(+), 211 deletions(-) delete mode 100644 src/FE/components/Chat/MemoizedChatMessage.tsx delete mode 100644 src/FE/components/Search/index.ts delete mode 100644 src/FE/components/Spinner/index.ts rename src/FE/{components/Chat => pages/_components/ChangeModel}/ChangeModel.tsx (94%) rename src/FE/{components/Chat => pages/_components/ChatError}/ChatError.tsx (94%) rename src/FE/{components => pages/_components}/ChatIcon/ChatIcon.tsx (99%) rename src/FE/{components/Chat => pages/_components}/ChatMessage/ChangeModelAction.tsx (86%) rename src/FE/{components/Chat => pages/_components}/ChatMessage/ChatMessage.tsx (85%) rename src/FE/{components/Chat => pages/_components}/ChatMessage/CopyAction.tsx (96%) rename src/FE/{components/Chat => pages/_components}/ChatMessage/EditAction.tsx (93%) rename src/FE/{components/Chat => pages/_components}/ChatMessage/GenerateInformationAction.tsx (78%) rename src/FE/{components/Chat => pages/_components}/ChatMessage/PaginationAction.tsx (100%) rename src/FE/{components/Chat => pages/_components}/ChatMessage/RegenerateAction.tsx (94%) rename src/FE/{components/Chat => pages/_components}/ChatMessage/ResponseMessage.tsx (87%) rename src/FE/{components/Chat => pages/_components}/ChatMessage/ResponseMessageActions.tsx (91%) rename src/FE/{components/Chat => pages/_components}/ChatMessage/UserMessage.tsx (95%) rename src/FE/{components/Chat => pages/_components}/ChatMessage/index.ts (100%) rename src/FE/{components => pages/_components}/Markdown/CodeBlock.tsx (100%) rename src/FE/{components => pages/_components}/Markdown/MemoizedReactMarkdown.tsx (100%) rename src/FE/{components => pages/_components}/Search/Search.tsx (96%) rename src/FE/{components => pages/_components}/Tips/Tips.tsx (100%) rename src/FE/{components/Admin => pages/admin/_components}/Files/FileServiceModal.tsx (100%) rename src/FE/{components/Admin => pages/admin/_components}/GlobalConfigs/GlobalConfigsModal.tsx (100%) rename src/FE/{components/Admin => pages/admin/_components}/InvitationCode/InvitationCodeModal.tsx (100%) rename src/FE/{components/Admin => pages/admin/_components}/LoginService/LoginServiceModal.tsx (100%) rename src/FE/{components/Admin => pages/admin/_components}/Messages/ChatMessage.tsx (85%) rename src/FE/{components/Admin => pages/admin/_components}/ModelKeys/ConfigModelModal.tsx (98%) rename src/FE/{components/Admin => pages/admin/_components}/ModelKeys/ModelKeysModal.tsx (96%) rename src/FE/{components/Admin => pages/admin/_components}/Models/AddModelModal.tsx (100%) rename src/FE/{components/Admin => pages/admin/_components}/Models/EditModelModal.tsx (100%) rename src/FE/{components/Admin => pages/admin/_components}/Nav/Nav.tsx (100%) rename src/FE/{components/Admin => pages/admin/_components}/Pagiation/Pagiation.tsx (100%) rename src/FE/{components/Admin => pages/admin/_components}/PayService/PayServiceModal.tsx (100%) rename src/FE/{components/Admin => pages/admin/_components}/RequestLogs/RequestLogDetailsModal.tsx (100%) rename src/FE/{components/Admin => pages/admin/_components}/Users/EditUserBalanceModel.tsx (100%) rename src/FE/{components/Admin => pages/admin/_components}/Users/EditUserModelModal.tsx (100%) rename src/FE/{components/Admin => pages/admin/_components}/Users/UserInitialConfigModal.tsx (100%) rename src/FE/{components/Admin => pages/admin/_components}/Users/UserModal.tsx (100%) rename src/FE/{components => pages/home/_components}/Button/CopyButton.tsx (100%) rename src/FE/{components => pages/home/_components}/Button/SidebarActionButton.tsx (100%) rename src/FE/{components => pages/home/_components}/Button/UploadButton.tsx (96%) rename src/FE/{components => pages/home/_components}/Chat/AccountBalance.tsx (92%) rename src/FE/{components => pages/home/_components}/Chat/Chat.tsx (97%) rename src/FE/{components => pages/home/_components}/Chat/ChatButtonTooltip.tsx (100%) rename src/FE/{components => pages/home/_components}/Chat/ChatInput.tsx (97%) rename src/FE/{components => pages/home/_components}/Chat/ChatLoader.tsx (100%) rename src/FE/{components => pages/home/_components}/Chat/EnableNetworkSearch.tsx (100%) create mode 100644 src/FE/pages/home/_components/Chat/MemoizedChatMessage.tsx rename src/FE/{components => pages/home/_components}/Chat/ModelSelect.tsx (97%) rename src/FE/{components => pages/home/_components}/Chat/NoModel.tsx (91%) rename src/FE/{components => pages/home/_components}/Chat/PromptList.tsx (100%) rename src/FE/{components => pages/home/_components}/Chat/SharedMessageModal.tsx (100%) rename src/FE/{components => pages/home/_components}/Chat/SystemPrompt.tsx (100%) rename src/FE/{components => pages/home/_components}/Chat/Temperature.tsx (97%) rename src/FE/{components => pages/home/_components}/Chat/VariableModal.tsx (100%) rename src/FE/{components => pages/home/_components}/ChatSettings/ChatSettings.tsx (100%) rename src/FE/{components => pages/home/_components}/ChatSettings/ChatSettingsBar.tsx (92%) rename src/FE/{components => pages/home/_components}/ChatSettings/SliderSetting.tsx (100%) rename src/FE/{components => pages/home/_components}/Chatbar/Chatbar.context.tsx (100%) rename src/FE/{components => pages/home/_components}/Chatbar/Chatbar.state.tsx (100%) rename src/FE/{components => pages/home/_components}/Chatbar/Chatbar.tsx (95%) rename src/FE/{components => pages/home/_components}/Chatbar/ChatbarSettings.tsx (91%) rename src/FE/{components => pages/home/_components}/Chatbar/ClearConversations.tsx (94%) rename src/FE/{components => pages/home/_components}/Chatbar/Conversation.tsx (94%) rename src/FE/{components => pages/home/_components}/Chatbar/Conversations.tsx (94%) rename src/FE/{components => pages/home/_components}/HomeContent/HomeContent.tsx (96%) rename src/FE/{components => pages/home/_components}/Modal/ChangePasswordModal.tsx (100%) rename src/FE/{components => pages/home/_components}/Modal/UserBalanceModal.tsx (100%) rename src/FE/{components => pages/home/_components}/ModeToggle/ModeTooggle.tsx (100%) rename src/FE/{components => pages/home/_components}/PageNotFound/PageNotFound.tsx (100%) rename src/FE/{components => pages/home/_components}/PasteUpload/PasteUpload.tsx (100%) rename src/FE/{components => pages/home/_components}/Popover/DateTimePopover.tsx (100%) rename src/FE/{components => pages/home/_components}/Popover/DeletePopover.tsx (100%) rename src/FE/{components => pages/home/_components}/Promptbar/PromptBar.context.tsx (100%) rename src/FE/{components => pages/home/_components}/Promptbar/Promptbar.state.tsx (100%) rename src/FE/{components => pages/home/_components}/Promptbar/Promptbar.tsx (96%) rename src/FE/{components => pages/home/_components}/Promptbar/components/Prompt.tsx (97%) rename src/FE/{components => pages/home/_components}/Promptbar/components/PromptModal.tsx (97%) rename src/FE/{components => pages/home/_components}/Promptbar/components/PromptbarSettings.tsx (100%) rename src/FE/{components => pages/home/_components}/Promptbar/components/Prompts.tsx (100%) rename src/FE/{components => pages/home/_components}/Promptbar/index.ts (100%) rename src/FE/{components => pages/home/_components}/Settings/ApiKeyTabContent.tsx (95%) rename src/FE/{components => pages/home/_components}/Settings/SettingModal.tsx (100%) rename src/FE/{components => pages/home/_components}/Sidebar/OpenCloseButton.tsx (100%) rename src/FE/{components => pages/home/_components}/Sidebar/Sidebar.tsx (97%) rename src/FE/{components => pages/home/_components}/Sidebar/SidebarButton.tsx (100%) rename src/FE/{components => pages/home/_components}/Sidebar/index.ts (100%) rename src/FE/{components => pages/home/_components}/Spinner/Spinner.tsx (100%) rename src/FE/{contexts => pages/home/_contents}/Home.context.ts (100%) rename src/FE/{components/Login => pages/login/_components}/AccountLoginCard.tsx (100%) rename src/FE/{components/Login => pages/login/_components}/KeyCloakLogin.tsx (100%) rename src/FE/{components/Login => pages/login/_components}/PhoneLoginCard.tsx (100%) rename src/FE/{components/Login => pages/login/_components}/PhoneRegisterCard.tsx (100%) rename src/FE/{components/Login => pages/login/_components}/WeChatLogin.tsx (100%) rename src/FE/{components/Login => pages/login/_components}/WeChatLoginModal.tsx (95%) create mode 100644 src/FE/pages/login/_components/index.ts rename src/FE/{components/Theme => providers}/ThemeProvider.tsx (100%) diff --git a/src/FE/components/Chat/MemoizedChatMessage.tsx b/src/FE/components/Chat/MemoizedChatMessage.tsx deleted file mode 100644 index 8a95fd75..00000000 --- a/src/FE/components/Chat/MemoizedChatMessage.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import { FC, memo } from 'react'; - -import { ChatMessage, Props } from './ChatMessage'; - -export const MemoizedChatMessage: FC = memo( - ChatMessage, - (prevProps, nextProps) => - prevProps.message.content === nextProps.message.content, -); diff --git a/src/FE/components/Search/index.ts b/src/FE/components/Search/index.ts deleted file mode 100644 index 85bb434b..00000000 --- a/src/FE/components/Search/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default } from './Search'; diff --git a/src/FE/components/Spinner/index.ts b/src/FE/components/Spinner/index.ts deleted file mode 100644 index f90663a5..00000000 --- a/src/FE/components/Spinner/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default } from './Spinner'; diff --git a/src/FE/pages/_app.tsx b/src/FE/pages/_app.tsx index 8c25e65d..04203d68 100644 --- a/src/FE/pages/_app.tsx +++ b/src/FE/pages/_app.tsx @@ -9,12 +9,11 @@ import { getUserInfo } from '@/utils/user'; import { UserRole } from '@/types/adminApis'; -import { ThemeProvider } from '@/components/Theme/ThemeProvider'; - import ErrorPage from './_error'; import AdminLayout from './admin/layout'; import './globals.css'; +import { ThemeProvider } from '@/providers/ThemeProvider'; import 'katex/dist/katex.min.css'; function App({ Component, pageProps }: AppProps<{}> | any) { @@ -25,7 +24,7 @@ function App({ Component, pageProps }: AppProps<{}> | any) { useEffect(() => { setIsClient(true); - document.title = "Chats"; + document.title = 'Chats'; }, []); const isAdmin = () => { diff --git a/src/FE/components/Chat/ChangeModel.tsx b/src/FE/pages/_components/ChangeModel/ChangeModel.tsx similarity index 94% rename from src/FE/components/Chat/ChangeModel.tsx rename to src/FE/pages/_components/ChangeModel/ChangeModel.tsx index 1e142c7e..71022853 100644 --- a/src/FE/components/Chat/ChangeModel.tsx +++ b/src/FE/pages/_components/ChangeModel/ChangeModel.tsx @@ -5,10 +5,9 @@ import useTranslation from '@/hooks/useTranslation'; import { AdminModelDto } from '@/types/adminApis'; import { feModelProviders } from '@/types/model'; -import ChatIcon from '@/components/ChatIcon/ChatIcon'; +import ChatIcon from '@/pages/_components/ChatIcon/ChatIcon'; import { IconChevronDown } from '@/components/Icons'; -import Search from '@/components/Search'; -import { Button } from '@/components/ui/button'; +import Search from '@/pages/_components/Search/Search'; import { DropdownMenu, DropdownMenuContent, @@ -21,7 +20,7 @@ import { DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; -import { HomeContext } from '@/contexts/Home.context'; +import { HomeContext } from '@/pages/home/_contents/Home.context'; import { cn } from '@/lib/utils'; const ChangeModel = ({ diff --git a/src/FE/components/Chat/ChatError.tsx b/src/FE/pages/_components/ChatError/ChatError.tsx similarity index 94% rename from src/FE/components/Chat/ChatError.tsx rename to src/FE/pages/_components/ChatError/ChatError.tsx index d6f42778..0bde22cf 100644 --- a/src/FE/components/Chat/ChatError.tsx +++ b/src/FE/pages/_components/ChatError/ChatError.tsx @@ -1,6 +1,5 @@ import useTranslation from '@/hooks/useTranslation'; -import { IconError } from '@/components/Icons'; import { Alert, AlertDescription } from '@/components/ui/alert'; interface Props { diff --git a/src/FE/components/ChatIcon/ChatIcon.tsx b/src/FE/pages/_components/ChatIcon/ChatIcon.tsx similarity index 99% rename from src/FE/components/ChatIcon/ChatIcon.tsx rename to src/FE/pages/_components/ChatIcon/ChatIcon.tsx index cf12780b..5d3f3ba5 100644 --- a/src/FE/components/ChatIcon/ChatIcon.tsx +++ b/src/FE/pages/_components/ChatIcon/ChatIcon.tsx @@ -1,9 +1,10 @@ +import useTranslation from '@/hooks/useTranslation'; + +import { feModelProviders } from '@/types/model'; import { IconShare } from '@/components/Icons'; -import useTranslation from '@/hooks/useTranslation'; import { cn } from '@/lib/utils'; -import { feModelProviders } from '@/types/model'; interface Props { providerId: number; diff --git a/src/FE/components/Chat/ChatMessage/ChangeModelAction.tsx b/src/FE/pages/_components/ChatMessage/ChangeModelAction.tsx similarity index 86% rename from src/FE/components/Chat/ChatMessage/ChangeModelAction.tsx rename to src/FE/pages/_components/ChatMessage/ChangeModelAction.tsx index a23d0a5f..f6be5937 100644 --- a/src/FE/components/Chat/ChatMessage/ChangeModelAction.tsx +++ b/src/FE/pages/_components/ChatMessage/ChangeModelAction.tsx @@ -1,7 +1,7 @@ import useTranslation from '@/hooks/useTranslation'; -import ChangeModel from '@/components/Chat/ChangeModel'; -import Tips from '@/components/Tips/Tips'; +import ChangeModel from '@/pages/_components/ChangeModel/ChangeModel'; +import Tips from '@/pages/_components/Tips/Tips'; interface Props { hidden?: boolean; diff --git a/src/FE/components/Chat/ChatMessage/ChatMessage.tsx b/src/FE/pages/_components/ChatMessage/ChatMessage.tsx similarity index 85% rename from src/FE/components/Chat/ChatMessage/ChatMessage.tsx rename to src/FE/pages/_components/ChatMessage/ChatMessage.tsx index bcf04a90..41672bdd 100644 --- a/src/FE/components/Chat/ChatMessage/ChatMessage.tsx +++ b/src/FE/pages/_components/ChatMessage/ChatMessage.tsx @@ -1,13 +1,11 @@ -import { FC, memo, useContext } from 'react'; +import { FC, memo } from 'react'; -import { Message } from '@/types/chat'; +import { IChat, Message } from '@/types/chat'; import { PropsMessage } from '@/types/components/chat'; -import { HomeContext } from '@/contexts/Home.context'; - import { IconRobot } from '@/components/Icons/index'; -import ChatError from '../ChatError'; +import ChatError from '../ChatError/ChatError'; import ResponseMessage from './ResponseMessage'; import ResponseMessageActions from './ResponseMessageActions'; import UserMessage from './UserMessage'; @@ -23,7 +21,11 @@ export interface Props { modelName?: string; modelId?: number; lastMessageId: string; + currentChatMessageId: string; message: PropsMessage; + messageIsStreaming: boolean; + chatError: boolean; + selectChat: IChat; onChangeMessage?: (messageId: string) => void; onEdit?: (editedMessage: Message, parentId: string | null) => void; onRegenerate?: (modelId?: number) => void; @@ -41,14 +43,14 @@ export const ChatMessage: FC = memo( modelId, lastMessageId, message, + messageIsStreaming, + currentChatMessageId, + chatError, + selectChat, onEdit, onChangeMessage, onRegenerate, }) => { - const { - state: { messageIsStreaming, currentChatMessageId, chatError }, - } = useContext(HomeContext); - return (
@@ -59,6 +61,8 @@ export const ChatMessage: FC = memo(
{message.role === 'user' && ( = memo( {message.role === 'assistant' && ( = memo( {message.role === 'assistant' && (