You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			105 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			TypeScript
		
	
			
		
		
	
	
			105 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			TypeScript
		
	
import { useCallback, useEffect } from 'react';
 | 
						|
 | 
						|
import { isEmpty, isString } from 'lodash';
 | 
						|
import { useDispatch } from 'react-redux';
 | 
						|
import useKey from 'react-use/lib/useKey';
 | 
						|
import { resetLeftOverlayMode, setLeftOverlayMode } from '../../../../state/ducks/section';
 | 
						|
import { SpacerSM } from '../../../basic/Text';
 | 
						|
import { StyledLeftPaneOverlay } from '../OverlayMessage';
 | 
						|
import { ActionRow, StyledActionRowContainer } from './ActionRow';
 | 
						|
import { ContactsListWithBreaks } from './ContactsListWithBreaks';
 | 
						|
 | 
						|
export const OverlayChooseAction = () => {
 | 
						|
  const dispatch = useDispatch();
 | 
						|
  function closeOverlay() {
 | 
						|
    dispatch(resetLeftOverlayMode());
 | 
						|
  }
 | 
						|
 | 
						|
  const openNewMessage = useCallback(() => {
 | 
						|
    dispatch(setLeftOverlayMode('message'));
 | 
						|
  }, [dispatch]);
 | 
						|
 | 
						|
  const openCreateGroup = useCallback(() => {
 | 
						|
    dispatch(setLeftOverlayMode('closed-group'));
 | 
						|
  }, [dispatch]);
 | 
						|
 | 
						|
  const openJoinCommunity = useCallback(() => {
 | 
						|
    dispatch(setLeftOverlayMode('open-group'));
 | 
						|
  }, [dispatch]);
 | 
						|
 | 
						|
  const inviteAFriend = useCallback(() => {
 | 
						|
    dispatch(setLeftOverlayMode('invite-a-friend'));
 | 
						|
  }, [dispatch]);
 | 
						|
 | 
						|
  useKey('Escape', closeOverlay);
 | 
						|
 | 
						|
  useEffect(() => {
 | 
						|
    function handlePaste(event: ClipboardEvent) {
 | 
						|
      event.preventDefault();
 | 
						|
 | 
						|
      const pasted = event.clipboardData?.getData('text');
 | 
						|
 | 
						|
      if (pasted && isString(pasted) && !isEmpty(pasted)) {
 | 
						|
        if (pasted.startsWith('http') || pasted.startsWith('https')) {
 | 
						|
          openJoinCommunity();
 | 
						|
        } else if (pasted.startsWith('05')) {
 | 
						|
          openNewMessage();
 | 
						|
        }
 | 
						|
      }
 | 
						|
    }
 | 
						|
    document?.addEventListener('paste', handlePaste);
 | 
						|
 | 
						|
    return () => {
 | 
						|
      document?.removeEventListener('paste', handlePaste);
 | 
						|
    };
 | 
						|
  }, [openJoinCommunity, openNewMessage]);
 | 
						|
 | 
						|
  return (
 | 
						|
    <StyledLeftPaneOverlay
 | 
						|
      container={true}
 | 
						|
      flexDirection={'column'}
 | 
						|
      flexGrow={1}
 | 
						|
      alignItems={'center'}
 | 
						|
    >
 | 
						|
      <StyledActionRowContainer
 | 
						|
        container={true}
 | 
						|
        flexDirection={'column'}
 | 
						|
        justifyContent={'flex-start'}
 | 
						|
        alignItems={'flex-start'}
 | 
						|
      >
 | 
						|
        <ActionRow
 | 
						|
          title={window.i18n('newMessage')}
 | 
						|
          ariaLabel={'New message button'}
 | 
						|
          iconType={'chatBubble'}
 | 
						|
          onClick={openNewMessage}
 | 
						|
          dataTestId="chooser-new-conversation-button"
 | 
						|
        />
 | 
						|
        <ActionRow
 | 
						|
          title={window.i18n('createGroup')}
 | 
						|
          ariaLabel={'Create a group button'}
 | 
						|
          iconType={'group'}
 | 
						|
          iconSize={36}
 | 
						|
          onClick={openCreateGroup}
 | 
						|
          dataTestId="chooser-new-group"
 | 
						|
        />
 | 
						|
        <ActionRow
 | 
						|
          title={window.i18n('joinOpenGroup')}
 | 
						|
          ariaLabel={'Join a community button'}
 | 
						|
          iconType={'communities'}
 | 
						|
          onClick={openJoinCommunity}
 | 
						|
          dataTestId="chooser-new-community"
 | 
						|
        />
 | 
						|
        <ActionRow
 | 
						|
          title={window.i18n('sessionInviteAFriend')}
 | 
						|
          ariaLabel={'Invite a friend button'}
 | 
						|
          iconType={'addUser'}
 | 
						|
          onClick={inviteAFriend}
 | 
						|
          dataTestId="chooser-invite-friend"
 | 
						|
        />
 | 
						|
      </StyledActionRowContainer>
 | 
						|
      <SpacerSM />
 | 
						|
      <ContactsListWithBreaks />
 | 
						|
    </StyledLeftPaneOverlay>
 | 
						|
  );
 | 
						|
};
 |