session-desktop/ts/components/session/LeftPaneSectionHeader.tsx

157 lines
4.0 KiB
TypeScript
Raw Normal View History

2021-08-19 04:10:11 +02:00
import React from 'react';
import classNames from 'classnames';
import { SessionIcon, SessionIconType } from './icon';
import styled from 'styled-components';
import { SessionButton, SessionButtonType } from './SessionButton';
2021-08-05 05:15:03 +02:00
import { useDispatch, useSelector } from 'react-redux';
import { disableRecoveryPhrasePrompt } from '../../state/ducks/userConfig';
import { getShowRecoveryPhrasePrompt } from '../../state/selectors/userConfig';
import { recoveryPhraseModal } from '../../state/ducks/modalDialog';
import { Flex } from '../basic/Flex';
import { getFocusedSection } from '../../state/selectors/section';
import { SectionType } from '../../state/ducks/section';
import { UserUtils } from '../../session/utils';
const Tab = ({
isSelected,
label,
onSelect,
type,
}: {
isSelected: boolean;
label: string;
onSelect?: (event: number) => void;
type: number;
}) => {
const handleClick = onSelect
? () => {
2021-08-12 01:07:54 +02:00
onSelect(type);
}
: undefined;
return (
<h1
2021-04-22 10:03:58 +02:00
className={classNames('module-left-pane__title', isSelected ? 'active' : null)}
onClick={handleClick}
role="button"
>
{label}
</h1>
);
};
2020-12-15 01:03:21 +01:00
type Props = {
label?: string;
2020-05-07 05:46:36 +02:00
buttonIcon?: SessionIconType;
buttonClicked?: any;
2020-12-15 01:03:21 +01:00
};
export const LeftPaneSectionHeader = (props: Props) => {
const { label, buttonIcon, buttonClicked } = props;
2021-08-05 05:15:03 +02:00
const showRecoveryPhrasePrompt = useSelector(getShowRecoveryPhrasePrompt);
return (
2021-08-19 04:10:11 +02:00
<Flex flexDirection="column">
2021-08-05 05:15:03 +02:00
<div className="module-left-pane__header">
{label && <Tab label={label} type={0} isSelected={true} key={label} />}
{buttonIcon && (
2021-08-19 04:10:11 +02:00
<SessionButton onClick={buttonClicked} key="compose">
<SessionIcon iconType={buttonIcon} iconSize="small" iconColor="white" />
2021-08-05 05:15:03 +02:00
</SessionButton>
)}
</div>
{showRecoveryPhrasePrompt && <LeftPaneBanner />}
</Flex>
);
};
2021-08-05 05:15:03 +02:00
const BannerInner = () => {
const dispatch = useDispatch();
const showRecoveryPhraseModal = () => {
dispatch(disableRecoveryPhrasePrompt());
dispatch(recoveryPhraseModal({}));
2021-08-12 01:07:54 +02:00
};
2021-08-05 05:15:03 +02:00
return (
<StyledBannerInner>
<p>{window.i18n('recoveryPhraseRevealMessage')}</p>
<SessionButton
buttonType={SessionButtonType.Default}
text={window.i18n('recoveryPhraseRevealButtonText')}
onClick={showRecoveryPhraseModal}
dataTestId="reveal-recovery-phrase"
/>
</StyledBannerInner>
);
};
export const LeftPaneBanner = () => {
const section = useSelector(getFocusedSection);
const isSignInWithRecoveryPhrase = UserUtils.isSignWithRecoveryPhrase();
if (section !== SectionType.Message || isSignInWithRecoveryPhrase) {
return null;
}
2021-08-05 05:15:03 +02:00
return (
2021-08-19 04:10:11 +02:00
<StyledLeftPaneBanner>
2021-08-05 05:15:03 +02:00
<StyledProgressBarContainer>
2021-08-19 04:10:11 +02:00
<StyledProgressBarInner />
2021-08-05 05:15:03 +02:00
</StyledProgressBarContainer>
2021-08-19 04:10:11 +02:00
<StyledBannerTitle>
{window.i18n('recoveryPhraseSecureTitle')} <span>90%</span>
2021-08-05 05:15:03 +02:00
</StyledBannerTitle>
<Flex flexDirection="column" justifyContent="space-between" padding={'var(--margins-sm)'}>
2021-08-05 05:15:03 +02:00
<BannerInner />
</Flex>
2021-08-05 05:15:03 +02:00
</StyledLeftPaneBanner>
2021-08-12 01:07:54 +02:00
);
};
2021-08-05 05:15:03 +02:00
const StyledProgressBarContainer = styled.div`
width: 100%;
height: 5px;
flex-direction: row;
background: var(--color-session-border);
2021-08-05 05:15:03 +02:00
`;
const StyledProgressBarInner = styled.div`
background: var(--color-accent);
2021-08-19 04:10:11 +02:00
width: 90%;
2021-08-05 05:15:03 +02:00
transition: width 0.5s ease-in;
height: 100%;
`;
export const StyledBannerTitle = styled.div`
line-height: 1.3;
font-size: var(--font-size-md);
2021-08-05 05:15:03 +02:00
font-weight: bold;
margin: var(--margins-sm) var(--margins-sm) 0 var(--margins-sm);
2021-08-05 05:15:03 +02:00
span {
color: var(--color-text-accent);
2021-08-12 01:07:54 +02:00
}
2021-08-05 05:15:03 +02:00
`;
export const StyledLeftPaneBanner = styled.div`
background: var(--color-recovery-phrase-banner-background);
2021-08-05 05:15:03 +02:00
display: flex;
flex-direction: column;
border-bottom: var(--session-border);
2021-08-05 05:15:03 +02:00
`;
const StyledBannerInner = styled.div`
p {
margin: 0;
}
.left-pane-banner___phrase {
margin-top: var(--margins-md);
2021-08-05 05:15:03 +02:00
}
.session-button {
margin-top: var(--margins-sm);
2021-08-05 05:15:03 +02:00
}
`;