import * as React from 'react'; import { Component, Styles, View } from 'reactxp'; import styled from 'styled-components'; import { colors } from '../../config.json'; import { TunnelState } from '../../shared/daemon-rpc-types'; import { messages } from '../../shared/gettext'; import ConnectionPanelContainer from '../containers/ConnectionPanelContainer'; import * as AppButton from './AppButton'; import ImageView from './ImageView'; import Marquee from './Marquee'; import { MultiButton } from './MultiButton'; import SecuredLabel, { SecuredDisplayStyle } from './SecuredLabel'; interface ITunnelControlProps { tunnelState: TunnelState; blockWhenDisconnected: boolean; selectedRelayName: string; city?: string; country?: string; onConnect: () => void; onDisconnect: () => void; onReconnect: () => void; onSelectLocation: () => void; } const SwitchLocationButton = styled(AppButton.TransparentButton)({ marginBottom: 16, }); const styles = { footer: Styles.createViewStyle({ flex: 0, paddingBottom: 16, paddingLeft: 24, paddingRight: 24, }), status_security: Styles.createTextStyle({ fontFamily: 'Open Sans', fontSize: 16, fontWeight: '800', lineHeight: 22, marginBottom: 2, }), }; const Body = styled.div({ display: 'flex', flexDirection: 'column', padding: '0 24px', marginTop: '176px', flex: 1, }); const Wrapper = styled.div({ display: 'flex', flexDirection: 'column', flex: 1, }); const Location = styled.div({ display: 'flex', flexDirection: 'column', marginBottom: 2, }); const StyledMarquee = styled(Marquee)({ fontFamily: 'DINPro', fontSize: '34px', lineHeight: '38px', fontWeight: 900, overflow: 'hidden', letterSpacing: -0.9, color: colors.white, }); export default class TunnelControl extends Component { public render() { const SwitchLocation = () => { return ( {messages.pgettext('tunnel-control', 'Switch location')} ); }; const SelectedLocation = () => ( {this.props.selectedRelayName} ); const Connect = () => ( {messages.pgettext('tunnel-control', 'Secure my connection')} ); const Disconnect = (props: React.ComponentProps) => ( {messages.pgettext('tunnel-control', 'Disconnect')} ); const Cancel = (props: React.ComponentProps) => ( {messages.pgettext('tunnel-control', 'Cancel')} ); const Dismiss = (props: React.ComponentProps) => ( {messages.pgettext('tunnel-control', 'Dismiss')} ); const Reconnect = (props: React.ComponentProps) => ( ); const Secured = ({ displayStyle }: { displayStyle: SecuredDisplayStyle }) => ( ); const Footer = ({ children }: { children: React.ReactNode }) => ( {children} ); let state = this.props.tunnelState.state; switch (this.props.tunnelState.state) { case 'disconnecting': switch (this.props.tunnelState.details) { case 'block': state = 'error'; break; case 'reconnect': state = 'connecting'; break; default: state = 'disconnecting'; break; } break; } switch (state) { case 'connecting': return ( {this.renderCity()} {this.renderCountry()}
); case 'connected': return ( {this.renderCity()} {this.renderCountry()}
); case 'error': if ( this.props.tunnelState.state === 'error' && !this.props.tunnelState.details.isBlocking ) { return (
); } else { return (
); } case 'disconnecting': return ( {this.renderCountry()}
); case 'disconnected': { const displayStyle = this.props.blockWhenDisconnected ? SecuredDisplayStyle.blocked : SecuredDisplayStyle.unsecured; return ( {this.renderCountry()}
); } default: throw new Error(`Unknown TunnelState: ${this.props.tunnelState}`); } } private renderCity() { return {this.props.city}; } private renderCountry() { return {this.props.country}; } }