mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
🪶 refactor: Chat Input Focus for Conversation Navigations & ChatForm Optimizations (#7100)
* refactor: improve ChatView layout by keeping ChatForm mounted * feat: implement focusChat functionality for new conversations and navigations * refactor: reset artifacts when navigating to prevent any from rendering in a conversation when none exist; edge case, artifacts get created by search route (TODO: use a different artifact renderer for Search markdown)
This commit is contained in:
parent
6826c0ed43
commit
fc30482f65
8 changed files with 68 additions and 41 deletions
18
client/src/hooks/Chat/useFocusChatEffect.ts
Normal file
18
client/src/hooks/Chat/useFocusChatEffect.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { useEffect } from 'react';
|
||||
import { useLocation, useNavigate } from 'react-router-dom';
|
||||
import { logger } from '~/utils';
|
||||
|
||||
export default function useFocusChatEffect(textAreaRef: React.RefObject<HTMLTextAreaElement>) {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
useEffect(() => {
|
||||
if (textAreaRef?.current && location.state?.focusChat) {
|
||||
logger.log(
|
||||
'conversation',
|
||||
`Focusing textarea on location state change: ${location.pathname}`,
|
||||
);
|
||||
textAreaRef.current?.focus();
|
||||
navigate(`${location.pathname}${location.search ?? ''}`, { replace: true, state: {} });
|
||||
}
|
||||
}, [navigate, textAreaRef, location.pathname, location.state?.focusChat, location.search]);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue