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.
		
		
		
		
		
			
		
			
				
	
	
		
			141 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			TypeScript
		
	
			
		
		
	
	
			141 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			TypeScript
		
	
import React from 'react';
 | 
						|
import { useDispatch, useSelector } from 'react-redux';
 | 
						|
import styled from 'styled-components';
 | 
						|
import { recoveryPhraseModal } from '../../state/ducks/modalDialog';
 | 
						|
import { SectionType } from '../../state/ducks/section';
 | 
						|
import { disableRecoveryPhrasePrompt } from '../../state/ducks/userConfig';
 | 
						|
import { getFocusedSection, getIsMessageRequestOverlayShown } from '../../state/selectors/section';
 | 
						|
import { getShowRecoveryPhrasePrompt } from '../../state/selectors/userConfig';
 | 
						|
import { isSignWithRecoveryPhrase } from '../../util/storage';
 | 
						|
import { Flex } from '../basic/Flex';
 | 
						|
import { SessionButton } from '../basic/SessionButton';
 | 
						|
import { MenuButton } from '../buttons';
 | 
						|
 | 
						|
const SectionTitle = styled.h1`
 | 
						|
  padding-top: var(--margins-xs);
 | 
						|
  padding-left: var(--margins-sm);
 | 
						|
  flex-grow: 1;
 | 
						|
  color: var(--text-primary-color);
 | 
						|
`;
 | 
						|
 | 
						|
const StyledProgressBarContainer = styled.div`
 | 
						|
  width: 100%;
 | 
						|
  height: 5px;
 | 
						|
  flex-direction: row;
 | 
						|
  background: var(--border-color);
 | 
						|
`;
 | 
						|
 | 
						|
const StyledProgressBarInner = styled.div`
 | 
						|
  background: var(--primary-color);
 | 
						|
  width: 90%;
 | 
						|
  transition: width 0.5s ease-in;
 | 
						|
  height: 100%;
 | 
						|
`;
 | 
						|
 | 
						|
export const StyledBannerTitle = styled.div`
 | 
						|
  line-height: 1.3;
 | 
						|
  font-size: var(--font-size-md);
 | 
						|
  font-weight: bold;
 | 
						|
  margin: var(--margins-sm) var(--margins-sm) 0 var(--margins-sm);
 | 
						|
 | 
						|
  span {
 | 
						|
    color: var(--primary-color);
 | 
						|
  }
 | 
						|
`;
 | 
						|
 | 
						|
export const StyledLeftPaneBanner = styled.div`
 | 
						|
  background: var(--background-primary-color);
 | 
						|
  display: flex;
 | 
						|
  flex-direction: column;
 | 
						|
  border-bottom: 1px solid var(--border-color);
 | 
						|
`;
 | 
						|
 | 
						|
const StyledBannerInner = styled.div`
 | 
						|
  p {
 | 
						|
    margin: 0;
 | 
						|
  }
 | 
						|
 | 
						|
  .left-pane-banner___phrase {
 | 
						|
    margin-top: var(--margins-md);
 | 
						|
  }
 | 
						|
 | 
						|
  .session-button {
 | 
						|
    margin-top: var(--margins-md);
 | 
						|
  }
 | 
						|
`;
 | 
						|
 | 
						|
const BannerInner = () => {
 | 
						|
  const dispatch = useDispatch();
 | 
						|
 | 
						|
  const showRecoveryPhraseModal = () => {
 | 
						|
    dispatch(disableRecoveryPhrasePrompt());
 | 
						|
    dispatch(recoveryPhraseModal({}));
 | 
						|
  };
 | 
						|
 | 
						|
  return (
 | 
						|
    <StyledBannerInner>
 | 
						|
      <p>{window.i18n('recoveryPhraseRevealMessage')}</p>
 | 
						|
      <SessionButton
 | 
						|
        text={window.i18n('recoveryPhraseRevealButtonText')}
 | 
						|
        onClick={showRecoveryPhraseModal}
 | 
						|
        dataTestId="reveal-recovery-phrase"
 | 
						|
      />
 | 
						|
    </StyledBannerInner>
 | 
						|
  );
 | 
						|
};
 | 
						|
 | 
						|
export const LeftPaneBanner = () => {
 | 
						|
  const section = useSelector(getFocusedSection);
 | 
						|
  const isSignInWithRecoveryPhrase = isSignWithRecoveryPhrase();
 | 
						|
 | 
						|
  if (section !== SectionType.Message || isSignInWithRecoveryPhrase) {
 | 
						|
    return null;
 | 
						|
  }
 | 
						|
 | 
						|
  return (
 | 
						|
    <StyledLeftPaneBanner>
 | 
						|
      <StyledProgressBarContainer>
 | 
						|
        <StyledProgressBarInner />
 | 
						|
      </StyledProgressBarContainer>
 | 
						|
      <StyledBannerTitle>
 | 
						|
        {window.i18n('recoveryPhraseSecureTitle')} <span>90%</span>
 | 
						|
      </StyledBannerTitle>
 | 
						|
      <Flex flexDirection="column" justifyContent="space-between" padding={'var(--margins-sm)'}>
 | 
						|
        <BannerInner />
 | 
						|
      </Flex>
 | 
						|
    </StyledLeftPaneBanner>
 | 
						|
  );
 | 
						|
};
 | 
						|
 | 
						|
export const LeftPaneSectionHeader = () => {
 | 
						|
  const showRecoveryPhrasePrompt = useSelector(getShowRecoveryPhrasePrompt);
 | 
						|
  const focusedSection = useSelector(getFocusedSection);
 | 
						|
  const isMessageRequestOverlayShown = useSelector(getIsMessageRequestOverlayShown);
 | 
						|
 | 
						|
  let label: string | undefined;
 | 
						|
 | 
						|
  const isMessageSection = focusedSection === SectionType.Message;
 | 
						|
 | 
						|
  switch (focusedSection) {
 | 
						|
    case SectionType.Settings:
 | 
						|
      label = window.i18n('settingsHeader');
 | 
						|
      break;
 | 
						|
    case SectionType.Message:
 | 
						|
      label = isMessageRequestOverlayShown
 | 
						|
        ? window.i18n('messageRequests')
 | 
						|
        : window.i18n('messagesHeader');
 | 
						|
      break;
 | 
						|
    default:
 | 
						|
  }
 | 
						|
 | 
						|
  return (
 | 
						|
    <Flex flexDirection="column">
 | 
						|
      <div className="module-left-pane__header">
 | 
						|
        <SectionTitle>{label}</SectionTitle>
 | 
						|
        {isMessageSection && <MenuButton />}
 | 
						|
      </div>
 | 
						|
      {showRecoveryPhrasePrompt && <LeftPaneBanner />}
 | 
						|
    </Flex>
 | 
						|
  );
 | 
						|
};
 |