From 6d1ae9f52603c3d3d52f726e3159fbd398e1a55e Mon Sep 17 00:00:00 2001 From: "Tindo N. Arsel" Date: Mon, 3 Apr 2023 17:33:40 +0100 Subject: [PATCH] add feature to create new chat in a given folder (#174) * add feature to create new chat in a given folder This to not have to drag and drop a chat each time in a folder * change style * fix margin * style: folder gradient * style --------- Co-authored-by: Jing Hua <59118459+ztjhz@users.noreply.github.com> --- src/components/Menu/ChatFolder.tsx | 22 ++++++++++++++++++-- src/components/Menu/ChatHistoryList.tsx | 2 +- src/components/Menu/NewChat.tsx | 27 ++++++++++++++++++------- src/constants/chat.ts | 3 ++- src/hooks/useAddChat.ts | 4 ++-- 5 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/components/Menu/ChatFolder.tsx b/src/components/Menu/ChatFolder.tsx index f140781..0178b20 100644 --- a/src/components/Menu/ChatFolder.tsx +++ b/src/components/Menu/ChatFolder.tsx @@ -10,6 +10,7 @@ import { } from '@type/chat'; import ChatHistory from './ChatHistory'; +import NewChat from './NewChat'; import EditIcon from '@icon/EditIcon'; import DeleteIcon from '@icon/DeleteIcon'; import CrossIcon from '@icon/CrossIcon'; @@ -35,6 +36,7 @@ const ChatFolder = ({ const inputRef = useRef(null); const folderRef = useRef(null); + const gradientRef = useRef(null); const [_folderName, _setFolderName] = useState(folderName); const [isEdit, setIsEdit] = useState(false); @@ -153,16 +155,18 @@ const ChatFolder = ({ style={{ background: color || '' }} className={`${ color ? '' : 'hover:bg-gray-850' - } transition-colors flex py-3 px-3 items-center gap-3 relative rounded-md break-all cursor-pointer`} + } transition-colors flex py-3 pl-3 pr-1 items-center gap-3 relative rounded-md break-all cursor-pointer`} onClick={toggleExpanded} ref={folderRef} onMouseEnter={() => { if (color && folderRef.current) folderRef.current.style.background = `${color}dd`; + if (gradientRef.current) gradientRef.current.style.width = '0px'; }} onMouseLeave={() => { if (color && folderRef.current) folderRef.current.style.background = color; + if (gradientRef.current) gradientRef.current.style.width = '1rem'; }} > @@ -182,6 +186,19 @@ const ChatFolder = ({ ) : ( _folderName )} + {isEdit || ( +
+ )}
-
+
{isExpanded && folderChats.map((chat) => ( ))} + {isExpanded && }
); diff --git a/src/components/Menu/ChatHistoryList.tsx b/src/components/Menu/ChatHistoryList.tsx index b320539..d2de9c6 100644 --- a/src/components/Menu/ChatHistoryList.tsx +++ b/src/components/Menu/ChatHistoryList.tsx @@ -156,7 +156,7 @@ const ChatHistoryList = () => { return (
{ +const NewChat = ({ folder }: { folder?: string }) => { const { t } = useTranslation(); const addChat = useAddChat(); const generating = useStore((state) => state.generating); return ( { - if (!generating) addChat(); + if (!generating) addChat(folder); }} + title={folder ? String(t('newChat')) : ''} > - {' '} - - {t('newChat')} - + {folder ? ( +
+ {t('newChat')} +
+ ) : ( + <> + + + {t('newChat')} + + + )}
); }; diff --git a/src/constants/chat.ts b/src/constants/chat.ts index 72d30d8..e994c5e 100644 --- a/src/constants/chat.ts +++ b/src/constants/chat.ts @@ -57,7 +57,7 @@ export const _defaultChatConfig: ConfigInterface = { frequency_penalty: 0, }; -export const generateDefaultChat = (title?: string): ChatInterface => ({ +export const generateDefaultChat = (title?: string, folder?: string): ChatInterface => ({ id: uuidv4(), title: title ? title : 'New Chat', messages: @@ -66,6 +66,7 @@ export const generateDefaultChat = (title?: string): ChatInterface => ({ : [], config: { ...useStore.getState().defaultChatConfig }, titleSet: false, + folder }); export const codeLanguageSubset = [ diff --git a/src/hooks/useAddChat.ts b/src/hooks/useAddChat.ts index 5382d75..17a6bbc 100644 --- a/src/hooks/useAddChat.ts +++ b/src/hooks/useAddChat.ts @@ -7,7 +7,7 @@ const useAddChat = () => { const setChats = useStore((state) => state.setChats); const setCurrentChatIndex = useStore((state) => state.setCurrentChatIndex); - const addChat = () => { + const addChat = (folder?:string) => { const chats = useStore.getState().chats; if (chats) { const updatedChats: ChatInterface[] = JSON.parse(JSON.stringify(chats)); @@ -19,7 +19,7 @@ const useAddChat = () => { title = `New Chat ${titleIndex}`; } - updatedChats.unshift(generateDefaultChat(title)); + updatedChats.unshift(generateDefaultChat(title, folder)); setChats(updatedChats); setCurrentChatIndex(0); }