Skip to content

Commit

Permalink
remove useless code
Browse files Browse the repository at this point in the history
  • Loading branch information
greywen committed Dec 27, 2024
1 parent 527c8b1 commit 7604efa
Show file tree
Hide file tree
Showing 16 changed files with 17 additions and 303 deletions.
12 changes: 0 additions & 12 deletions src/FE/pages/home/_actions/chat.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,11 @@ export const setChangeSelectedChatSpan = (
};
};

export const setChatStatus = (status: SetChatStatusType): ChatAction => ({
type: ChatActionTypes.SET_CHAT_STATUS,
payload: status,
});

export const setChatPaging = (paging: SetChatPagingType): ChatAction => ({
type: ChatActionTypes.SET_CHAT_PAGING,
payload: paging,
});

export const setMessageIsStreaming = (
paging: SetMessageIsStreamingType,
): ChatAction => ({
type: ChatActionTypes.SET_MESSAGE_IS_STREAMING,
payload: paging,
});

export const setIsChatsLoading = (
isChatsLoading: SetIsChatsLoadingType,
): ChatAction => ({
Expand Down
24 changes: 0 additions & 24 deletions src/FE/pages/home/_actions/message.actions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import {
MessageAction,
MessageActionTypes,
SetCurrentMessageIdType,
SetCurrentMessagesType,
SetLastMessageIdType,
SetMessagesType,
SetSelectedMessagesType,
} from '../_reducers/message.reducer';
Expand All @@ -20,25 +17,4 @@ export const setSelectedMessages = (
payload: selectedMessages,
});

export const setCurrentMessages = (
currentMessages: SetCurrentMessagesType,
): MessageAction => ({
type: MessageActionTypes.SET_CURRENT_MESSAGES,
payload: currentMessages,
});

export const setLastMessageId = (
lastMessageId: SetLastMessageIdType,
): MessageAction => ({
type: MessageActionTypes.SET_LAST_MESSAGE_ID,
payload: lastMessageId,
});

export const setCurrentMessageId = (
currentMessageId: SetCurrentMessageIdType,
): MessageAction => ({
type: MessageActionTypes.SET_CURRENT_MESSAGE_ID,
payload: currentMessageId,
});

export default function () {}
17 changes: 0 additions & 17 deletions src/FE/pages/home/_actions/model.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,14 @@ import { AdminModelDto } from '@/types/adminApis';
import {
ModelAction,
ModelActionTypes,
SetModelMapType,
SetModelsType,
SetSelectModelType,
SetSelectModelsType,
} from '../_reducers/model.reducer';

export const setModels = (models: SetModelsType): ModelAction => ({
type: ModelActionTypes.SET_MODELS,
payload: models,
});

export const setSelectedModel = (
selectedModel: SetSelectModelType,
): ModelAction => ({
type: ModelActionTypes.SET_SELECTED_MODEL,
payload: selectedModel,
});

export const setSelectedModels = (
selectedModels: SetSelectModelsType,
): ModelAction => ({
type: ModelActionTypes.SET_SELECTED_MODELS,
payload: selectedModels,
});

export const setModelMap = (models: SetModelsType): ModelAction => {
const modelMap: Record<string, AdminModelDto> = {};
models.forEach((x) => {
Expand Down
36 changes: 0 additions & 36 deletions src/FE/pages/home/_actions/userModelConfig.actions.ts

This file was deleted.

10 changes: 3 additions & 7 deletions src/FE/pages/home/_components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import {
setMessages,
setSelectedMessages,
} from '../../_actions/message.actions';
import { setTemperature } from '../../_actions/userModelConfig.actions';
import HomeContext from '../../_contexts/home.context';
import ChatHeader from './ChatHeader';
import ChatInput from './ChatInput';
Expand Down Expand Up @@ -73,7 +72,6 @@ const Chat = memo(() => {
hasModel,
chatDispatch,
messageDispatch,
userModelConfigDispatch,
} = useContext(HomeContext);
const [autoScrollEnabled, setAutoScrollEnabled] = useState<boolean>(true);
const [showScrollDownButton, setShowScrollDownButton] =
Expand Down Expand Up @@ -394,10 +392,8 @@ const Chat = memo(() => {
throttledScrollDown();
}, [selectedMessages, throttledScrollDown]);

const onChangePrompt = (prompt: Prompt) => {
if (prompt.temperature !== null) {
userModelConfigDispatch(setTemperature(prompt.temperature));
}
const handleChangePrompt = (prompt: Prompt) => {
// to do
};

const handleChangeChatLeafMessageId = (messageId: string) => {
Expand Down Expand Up @@ -443,7 +439,7 @@ const Chat = memo(() => {
}}
onScrollDownClick={handleScrollDown}
showScrollDownButton={showScrollDownButton}
onChangePrompt={onChangePrompt}
onChangePrompt={handleChangePrompt}
/>
)}
{!hasModel() && !selectedChat?.id && <NoModel />}
Expand Down
27 changes: 0 additions & 27 deletions src/FE/pages/home/_components/Chat/ChatButtonTooltip.tsx

This file was deleted.

4 changes: 1 addition & 3 deletions src/FE/pages/home/_components/Chat/ChatModelInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { useContext, useEffect, useState } from 'react';
import { useEffect, useState } from 'react';

import useTranslation from '@/hooks/useTranslation';

import { formatNumberAsMoney } from '@/utils/common';

import { ModelUsageDto } from '@/types/clientApis';

import HomeContext from '../../_contexts/home.context';

import { getModelUsage } from '@/apis/clientApis';

const ChatModelInfo = (props: { modelId: number; modelName: string }) => {
Expand Down
10 changes: 1 addition & 9 deletions src/FE/pages/home/_components/Chat/ChatModelSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,7 @@ import { cn } from '@/lib/utils';
const ChatModelSetting = () => {
const { t } = useTranslation();
const {
state: {
defaultPrompt,

selectedChat,

modelMap,

prompts,
},
state: { defaultPrompt, selectedChat, modelMap, prompts },
hasModel,
chatDispatch,
} = useContext(HomeContext);
Expand Down
10 changes: 4 additions & 6 deletions src/FE/pages/home/_components/Chatbar/Chatbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useContext, useEffect, useState } from 'react';
import { useCreateReducer } from '@/hooks/useCreateReducer';
import useTranslation from '@/hooks/useTranslation';

import { ChatStatus } from '@/types/chat';
import { ChatResult } from '@/types/clientApis';

import { setShowChatBar } from '../../_actions/setting.actions';
Expand All @@ -21,9 +22,9 @@ const Chatbar = () => {
});

const {
state: { chats, showChatBar, messageIsStreaming, isChatsLoading },
state: { chats, showChatBar, selectedChat, isChatsLoading },
settingDispatch,
handleDeleteChat: homeHandleDeleteChat,
handleDeleteChat,
handleNewChat,
hasModel,
getChats,
Expand All @@ -34,9 +35,6 @@ const Chatbar = () => {
dispatch,
} = chatBarContextValue;
const [searchTerm, setSearchTerm] = useState('');
const handleDeleteChat = (chatId: string) => {
homeHandleDeleteChat(chatId);
};

const handleToggleChatbar = () => {
settingDispatch(setShowChatBar(!showChatBar));
Expand Down Expand Up @@ -68,7 +66,7 @@ const Chatbar = () => {
>
<Sidebar<ChatResult>
isLoading={isChatsLoading}
messageIsStreaming={messageIsStreaming}
messageIsStreaming={selectedChat.status === ChatStatus.Chatting}
side={'left'}
isOpen={showChatBar}
addItemButtonTitle={t('New chat')}
Expand Down
13 changes: 7 additions & 6 deletions src/FE/pages/home/_components/Chatbar/Conversation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import toast from 'react-hot-toast';

import useTranslation from '@/hooks/useTranslation';

import { IChat } from '@/types/chat';
import { ChatStatus, IChat } from '@/types/chat';

import SidebarActionButton from '@/components/Button/SidebarActionButton';
import ChatIcon from '@/components/ChatIcon/ChatIcon';
Expand Down Expand Up @@ -43,14 +43,15 @@ const ConversationComponent = ({ chat }: Props) => {
const { t } = useTranslation();
const {
state: {
selectedChat: { id: selectChatId } = { id: undefined },
messageIsStreaming,
selectedChat: { id: selectChatId, status },
chats,
},
handleSelectChat,
handleUpdateChat,
} = useContext(HomeContext);

const chatting = status === ChatStatus.Chatting;

const { handleDeleteChat } = useContext(ChatbarContext);

const [isDeleting, setIsDeleting] = useState(false);
Expand Down Expand Up @@ -138,10 +139,10 @@ const ConversationComponent = ({ chat }: Props) => {
) : (
<button
className={`flex w-full cursor-pointer items-center gap-2 rounded-lg p-3 text-sm transition-colors duration-200 hover:bg-muted ${
messageIsStreaming ? 'disabled:cursor-not-allowed' : ''
chatting ? 'disabled:cursor-not-allowed' : ''
} ${selectChatId === chat.id ? 'bg-muted' : ''}`}
onClick={() => handleSelectChat(chat)}
disabled={messageIsStreaming}
disabled={chatting}
>
<div
className={cn(
Expand Down Expand Up @@ -184,7 +185,7 @@ const ConversationComponent = ({ chat }: Props) => {
<div className="absolute right-[0.6rem] z-10 flex text-gray-300">
<DropdownMenu>
<DropdownMenuTrigger
disabled={messageIsStreaming}
disabled={chatting}
className="focus:outline-none p-[6px]"
>
<IconDots className="hover:opacity-50" size={16} />
Expand Down
13 changes: 1 addition & 12 deletions src/FE/pages/home/_components/Home/HomeContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import Spinner from '@/components/Spinner/Spinner';

import {
setChatPaging,
setChatStatus,
setChats,
setIsChatsLoading,
setSelectedChat,
Expand Down Expand Up @@ -49,9 +48,6 @@ import promptReducer, {
import settingReducer, {
settingInitialState,
} from '../../_reducers/setting.reducer';
import userModelConfigReducer, {
userModelConfigInitialState,
} from '../../_reducers/userModelConfig.reducer';
import Chat from '../Chat/Chat';
import Chatbar from '../Chatbar/Chatbar';
import PromptBar from '../Promptbar/Promptbar';
Expand All @@ -78,10 +74,6 @@ const HomeContent = () => {
modelReducer,
modelInitialState,
);
const [userModelConfigState, userModelConfigDispatch] = useReducer(
userModelConfigReducer,
userModelConfigInitialState,
);
const [settingState, settingDispatch] = useReducer(
settingReducer,
settingInitialState,
Expand All @@ -91,7 +83,7 @@ const HomeContent = () => {
promptInitialState,
);

const { chats, stopIds } = chatState;
const { chats, stopIds, selectedChat } = chatState;
const { models } = modelState;
const { showPromptBar } = settingState;
const [isPageLoading, setIsPageLoading] = useState(true);
Expand Down Expand Up @@ -206,7 +198,6 @@ const HomeContent = () => {
p.push(stopChat(id));
});
Promise.all(p).then(() => {
chatDispatch(setChatStatus(false));
chatDispatch(setStopIds([]));
});
};
Expand Down Expand Up @@ -289,14 +280,12 @@ const HomeContent = () => {
...chatState,
...messageState,
...modelState,
...userModelConfigState,
...settingState,
...promptState,
},
chatDispatch: chatDispatch,
messageDispatch: messageDispatch,
modelDispatch: modelDispatch,
userModelConfigDispatch: userModelConfigDispatch,
settingDispatch: settingDispatch,
promptDispatch: promptDispatch,

Expand Down
Loading

0 comments on commit 7604efa

Please sign in to comment.