summaryrefslogtreecommitdiffhomepage
path: root/app/components/AdvancedSettings.js
blob: b4306b81c81d922936154adb8b6e959855bb89d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// @flow

import React from 'react';
import { Layout, Container, Header } from './Layout';
import CustomScrollbars from './CustomScrollbars';

export class AdvancedSettings extends React.Component {

  props: {
    protocol: string,
    port: string | number,
    onUpdate: (protocol: string, port: string | number) => void,
    onClose: () => void,
  };

  render() {
    let portSelector = null;
    let protocol = this.props.protocol.toUpperCase();

    if (protocol === 'AUTOMATIC') {
      protocol = 'Automatic';
    } else {
      portSelector = this._createPortSelector();
    }

    return <BaseLayout onClose={ this.props.onClose }>

      <Selector
        title={ 'Network protocols' }
        values={ ['Automatic', 'UDP', 'TCP'] }
        value={ protocol }
        onSelect={ protocol => {
          this.props.onUpdate(protocol, 'Automatic');
        }}/>

      <div className="settings__cell-spacer"></div>

      { portSelector }

    </BaseLayout>;
  }

  _createPortSelector() {
    const protocol = this.props.protocol.toUpperCase();
    const ports = protocol === 'TCP'
      ? ['Automatic', 80, 443]
      : ['Automatic', 1194, 1195, 1196, 1197, 1300, 1301, 1302];

    return <Selector
      title={ protocol + ' port' }
      values={ ports }
      value={ this.props.port }
      onSelect={ port => {
        this.props.onUpdate(protocol, port);
      }} />;
  }
}


class Selector extends React.Component {

  props: {
    title: string,
    values: Array<*>,
    value: *,
    onSelect: (*) => void,
  }

  render() {
    return <div>
      <div className="settings__cell">
        <div className="settings__cell-label">{ this.props.title }</div>
      </div>

      { this.props.values.map(value => this._renderCell(value)) }
    </div>;
  }

  _renderCell(value) {
    const selected = value === this.props.value;
    if (selected) {
      return this._renderSelectedCell(value);
    } else {
      return this._renderUnselectedCell(value);
    }
  }

  _renderSelectedCell(value) {
    const onCellClick = () => this.props.onSelect(value);

    return <div
      key={ value }
      className={ 'settings__cell--selected settings__cell' }
      onClick={ onCellClick } >
      <div className="settings__cell-label">
        <div className={ 'settings__sub-cell--label' }>
          <img src='./assets/images/icon-tick.svg' />
          { value }
        </div>
      </div>
    </div>;
  }

  _renderUnselectedCell(value) {
    const onCellClick = () => this.props.onSelect(value);

    return <div
      key={ value }
      className={ 'settings__cell settings__sub-cell' }
      onClick={ onCellClick } >
      <div className="settings__cell-label">
        <div className="settings__sub-cell--label">{ value }</div>
      </div>
    </div>;
  }
}

function BaseLayout(props) {
  return <Layout>
    <Header hidden={ true } style={ 'defaultDark' } />
    <Container>
      <div className="settings">
        <div className="support__close" onClick={ props.onClose }>
          <img className="support__close-icon" src="./assets/images/icon-back.svg" />
          <span className="support__close-title">Settings</span>
        </div>
        <div className="settings__container">
          <div className="settings__header">
            <h2 className="settings__title">Advanced</h2>
          </div>
          <CustomScrollbars autoHide={ true }>
            <div className="settings__content">
              <div className="settings__main">
                <div className="settings__advanced">
                  { props.children }
                </div>
              </div>
            </div>
          </CustomScrollbars>
        </div>
      </div>
    </Container>
  </Layout>;
}