TelegramPWA/src/components/common/GroupCallLink.tsx
2023-01-28 02:21:33 +01:00

38 lines
960 B
TypeScript

import type { FC } from '../../lib/teact/teact';
import React, { useCallback } from '../../lib/teact/teact';
import type { ApiGroupCall } from '../../api/types';
import buildClassName from '../../util/buildClassName';
import Link from '../ui/Link';
import { getActions } from '../../global';
type OwnProps = {
className?: string;
groupCall?: Partial<ApiGroupCall>;
children: React.ReactNode;
};
const GroupCallLink: FC<OwnProps> = ({
className, groupCall, children,
}) => {
const { requestMasterAndJoinGroupCall } = getActions();
const handleClick = useCallback(() => {
if (groupCall) {
requestMasterAndJoinGroupCall({ id: groupCall.id, accessHash: groupCall.accessHash });
}
}, [groupCall, requestMasterAndJoinGroupCall]);
if (!groupCall) {
return children;
}
return (
<Link className={buildClassName('GroupCallLink', className)} onClick={handleClick}>{children}</Link>
);
};
export default GroupCallLink;