// @flow
import moment from 'moment';
import React, { Component } from 'react';
import { If, Then } from 'react-if';
import { Layout, Container, Header } from './Layout';
import { BackendError } from '../lib/backend';
import ExternalLinkSVG from '../assets/images/icon-extLink.svg';
import type { ServerInfo } from '../lib/backend';
import type { HeaderBarStyle } from './HeaderBar';
import type { ConnectionReduxState } from '../redux/connection/reducers';
import type { RelayEndpoint } from '../lib/ipc-facade';
export type ConnectProps = {
accountExpiry: string,
connection: ConnectionReduxState,
preferredServer: string,
onSettings: () => void,
onSelectLocation: () => void,
onConnect: (relayEndpoint: RelayEndpoint) => void,
onCopyIP: () => void,
onDisconnect: () => void,
onExternalLink: (type: string) => void,
getServerInfo: (identifier: string) => ?ServerInfo
};
export default class Connect extends Component {
props: ConnectProps;
state = {
isFirstPass: true,
showCopyIPMessage: false
};
_copyTimer: ?number;
componentDidMount() {
this.setState({ isFirstPass: false });
}
componentWillUnmount() {
if(this._copyTimer) {
clearTimeout(this._copyTimer);
this._copyTimer = null;
}
this.setState({
isFirstPass: true,
showCopyIPMessage: false
});
}
render(): React.Element<*> {
const error = this.displayError();
const child = error ? this.renderError(error) : this.renderMap();
return (
{ child }
);
}
renderError(error: BackendError): React.Element<*> {
return (
{ error.title }
{ error.message }
);
}
renderMap(): React.Element<*> {
const preferredServer = this.props.preferredServer;
const serverInfo = this.props.getServerInfo(preferredServer);
if(!serverInfo) {
throw new Error('Server info cannot be null.');
}
let isConnecting = false;
let isConnected = false;
let isDisconnected = false;
switch(this.props.connection.status) {
case 'connecting': isConnecting = true; break;
case 'connected': isConnected = true; break;
case 'disconnected': isDisconnected = true; break;
}
const { city, country } = isConnecting || isConnected
? serverInfo
: { city: '\u2003', country: '\u2002' };
const ip = isConnected
? '185.65.132.102'
: '78.65.17.155'; //this.props.connection.clientIp;
// We decided to not include the map in the first beta release to customers
// but it MUST be included in the following releases. Therefore we choose
// to just comment it out
const map = undefined;
/*
const altitude = (isConnecting ? 300 : 100) * 1000;
const { location } = this.props.connection;
const map =
*/
let ipComponent = undefined;
if (isConnected || isDisconnected) {
if (this.state.showCopyIPMessage) {
ipComponent = { 'IP copied to clipboard!' };
} else {
ipComponent = { ip };
}
}
return (