Use string port

This commit is contained in:
Ken-Håvard Lieng 2020-05-10 02:53:39 +02:00
parent eb7545455c
commit 8fa91ac470
6 changed files with 84 additions and 93 deletions

File diff suppressed because one or more lines are too long

View File

@ -41,10 +41,10 @@ class Connect extends Component {
handleSSLChange = e => {
const { values, setFieldValue } = this.props;
if (e.target.checked && values.port === 6667) {
setFieldValue('port', 6697, false);
} else if (!e.target.checked && values.port === 6697) {
setFieldValue('port', 6667, false);
if (e.target.checked && values.port === '6667') {
setFieldValue('port', '6697', false);
} else if (!e.target.checked && values.port === '6697') {
setFieldValue('port', '6667', false);
}
};
@ -66,7 +66,7 @@ class Connect extends Component {
transformPort = port => {
if (!port) {
return this.props.values.tls ? 6697 : 6667;
return this.props.values.tls ? '6697' : '6667';
}
return port;
};

View File

@ -4,24 +4,6 @@ import classnames from 'classnames';
import capitalize from 'lodash/capitalize';
import Error from 'components/ui/formik/Error';
const getValue = (e, trim) => {
let v = e.target.value;
if (trim) {
v = v.trim();
}
if (e.target.type === 'number') {
v = parseFloat(v);
/* eslint-disable-next-line no-self-compare */
if (v !== v) {
v = '';
}
}
return v;
};
export default class TextInput extends PureComponent {
constructor(props) {
super(props);
@ -85,7 +67,12 @@ export default class TextInput extends PureComponent {
{...field}
{...props}
onChange={e => {
let v = getValue(e, !noTrim);
let v = e.target.value;
if (!noTrim) {
v = v.trim();
}
if (transform) {
v = transform(v);
}
@ -99,18 +86,18 @@ export default class TextInput extends PureComponent {
}
}}
onBlur={e => {
if (blurTransform) {
const v = blurTransform(getValue(e));
if (v && v !== field.value) {
form.setFieldValue(name, v, false);
}
}
field.onBlur(e);
if (props.onBlur) {
props.onBlur(e);
}
if (blurTransform) {
const v = blurTransform(e.target.value);
if (v && v !== field.value) {
form.setFieldValue(name, v);
}
}
}}
/>
<span

View File

@ -121,6 +121,10 @@ export function isValidUsername(username) {
}
export function isInt(i, min, max) {
if (typeof i === 'string') {
i = parseInt(i, 10);
}
if (i < min || i > max || Math.floor(i) !== i) {
return false;
}

View File

@ -24,7 +24,7 @@ type Config struct {
type Defaults struct {
Name string
Host string
Port int
Port string
Channels []string
Password string
SSL bool

View File

@ -560,7 +560,7 @@ func easyjson7e607aefDecodeGithubComKhliengDispatchServer2(in *jlexer.Lexer, out
case "host":
out.Host = string(in.String())
case "port":
out.Port = int(in.Int())
out.Port = string(in.String())
case "channels":
if in.IsNull() {
in.Skip()
@ -630,7 +630,7 @@ func easyjson7e607aefEncodeGithubComKhliengDispatchServer2(out *jwriter.Writer,
}
out.String(string(in.Host))
}
if in.Port != 0 {
if in.Port != "" {
const prefix string = ",\"port\":"
if first {
first = false
@ -638,7 +638,7 @@ func easyjson7e607aefEncodeGithubComKhliengDispatchServer2(out *jwriter.Writer,
} else {
out.RawString(prefix)
}
out.Int(int(in.Port))
out.String(string(in.Port))
}
if len(in.Channels) != 0 {
const prefix string = ",\"channels\":"