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

View File

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

View File

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

View File

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

View File

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