Middle Column: Fix closing chat by <Esc>

This commit is contained in:
Alexander Zinchuk 2021-05-09 02:00:05 +03:00
parent a17240466a
commit ac02fa4a4f
3 changed files with 9 additions and 9 deletions

View File

@ -33,7 +33,7 @@ import { pick } from '../../util/iteratees';
import buildClassName from '../../util/buildClassName';
import useCustomBackground from '../../hooks/useCustomBackground';
import useWindowSize from '../../hooks/useWindowSize';
import usePrevForAnimation from '../../hooks/usePrevForAnimation';
import usePrevDuringAnimation from '../../hooks/usePrevDuringAnimation';
import calculateMiddleFooterTransforms from './helpers/calculateMiddleFooterTransforms';
import useLang from '../../hooks/useLang';
@ -103,10 +103,10 @@ const MiddleColumn: FC<StateProps & DispatchProps> = ({
const [isFabShown, setIsFabShown] = useState(false);
const [isUnpinModalOpen, setIsUnpinModalOpen] = useState(false);
const renderingChatId = usePrevForAnimation(chatId, CLOSE_ANIMATION_DURATION);
const renderingThreadId = usePrevForAnimation(threadId, CLOSE_ANIMATION_DURATION);
const renderingMessageListType = usePrevForAnimation(messageListType, CLOSE_ANIMATION_DURATION);
const renderingCanPost = usePrevForAnimation(canPost, CLOSE_ANIMATION_DURATION);
const renderingChatId = usePrevDuringAnimation(chatId, CLOSE_ANIMATION_DURATION);
const renderingThreadId = usePrevDuringAnimation(threadId, CLOSE_ANIMATION_DURATION);
const renderingMessageListType = usePrevDuringAnimation(messageListType, CLOSE_ANIMATION_DURATION);
const renderingCanPost = usePrevDuringAnimation(canPost, CLOSE_ANIMATION_DURATION);
useEffect(() => {
return chatId

View File

@ -12,7 +12,7 @@ import { pick } from '../../../util/iteratees';
import parseMessageInput from './helpers/parseMessageInput';
import useOnChange from '../../../hooks/useOnChange';
import useShowTransition from '../../../hooks/useShowTransition';
import usePrevForAnimation from '../../../hooks/usePrevForAnimation';
import useCurrentOrPrev from '../../../hooks/useCurrentOrPrev';
import buildClassName from '../../../util/buildClassName';
import WebPage from '../message/WebPage';
@ -79,7 +79,7 @@ const WebPagePreview: FC<OwnProps & StateProps & DispatchProps> = ({
const isShown = Boolean(webPagePreview && messageText.length && !noWebPage && !disabled);
const { shouldRender, transitionClassNames } = useShowTransition(isShown);
const renderingWebPage = usePrevForAnimation(webPagePreview);
const renderingWebPage = useCurrentOrPrev(webPagePreview);
if (!shouldRender || !renderingWebPage) {
return undefined;

View File

@ -4,7 +4,7 @@ import usePrevious from './usePrevious';
import useForceUpdate from './useForceUpdate';
import useOnChange from './useOnChange';
export default function usePrevForAnimation(current: any, duration?: number) {
export default function usePrevDuringAnimation(current: any, duration?: number) {
const prev = usePrevious(current, true);
const timeoutRef = useRef<number>();
const forceUpdate = useForceUpdate();
@ -26,5 +26,5 @@ export default function usePrevForAnimation(current: any, duration?: number) {
}
}, [current]);
return isCurrentPresent || (duration && !timeoutRef.current) ? current : prev;
return !timeoutRef.current || !duration || isCurrentPresent ? current : prev;
}