Alexander Zinchuk 3afcde3217 Initial commit
2021-04-09 14:11:51 +03:00

41 lines
960 B
TypeScript

import React, { FC, useCallback } from '../../lib/teact/teact';
import { withGlobal } from '../../lib/teact/teactn';
import { GlobalActions } from '../../global/types';
import { pick } from '../../util/iteratees';
import buildClassName from '../../util/buildClassName';
import Link from '../ui/Link';
type OwnProps = {
className?: string;
chatId?: number;
children: any;
};
type DispatchProps = Pick<GlobalActions, 'openChat'>;
const ChatLink: FC<OwnProps & DispatchProps> = ({
className, chatId, openChat, children,
}) => {
const handleClick = useCallback(() => {
if (chatId) {
openChat({ id: chatId });
}
}, [chatId, openChat]);
if (!chatId) {
return children;
}
return (
<Link className={buildClassName('ChatLink', className)} onClick={handleClick}>{children}</Link>
);
};
export default withGlobal<OwnProps>(
undefined,
(setGlobal, actions): DispatchProps => pick(actions, ['openChat']),
)(ChatLink);