mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 00:40:14 +01:00
19 lines
735 B
TypeScript
19 lines
735 B
TypeScript
|
|
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]);
|
||
|
|
}
|