Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit da6f1e5

Browse files
authored
Merge pull request #5634 from jaiwanth-v/add-loading-TextInputDialog
Added loading and disabled the button while searching for server
2 parents 7865f15 + 20dc8db commit da6f1e5

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/components/views/dialogs/TextInputDialog.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import React, {createRef} from 'react';
1818
import PropTypes from 'prop-types';
1919
import * as sdk from '../../../index';
2020
import Field from "../elements/Field";
21+
import { _t, _td } from '../../../languageHandler';
2122

2223
export default class TextInputDialog extends React.Component {
2324
static propTypes = {
@@ -29,6 +30,7 @@ export default class TextInputDialog extends React.Component {
2930
value: PropTypes.string,
3031
placeholder: PropTypes.string,
3132
button: PropTypes.string,
33+
busyMessage: PropTypes.string, // pass _td string
3234
focus: PropTypes.bool,
3335
onFinished: PropTypes.func.isRequired,
3436
hasCancel: PropTypes.bool,
@@ -40,6 +42,7 @@ export default class TextInputDialog extends React.Component {
4042
title: "",
4143
value: "",
4244
description: "",
45+
busyMessage: _td("Loading..."),
4346
focus: true,
4447
hasCancel: true,
4548
};
@@ -51,6 +54,7 @@ export default class TextInputDialog extends React.Component {
5154

5255
this.state = {
5356
value: this.props.value,
57+
busy: false,
5458
valid: false,
5559
};
5660
}
@@ -66,11 +70,13 @@ export default class TextInputDialog extends React.Component {
6670
onOk = async ev => {
6771
ev.preventDefault();
6872
if (this.props.validator) {
73+
this.setState({ busy: true });
6974
await this._field.current.validate({ allowEmpty: false });
7075

7176
if (!this._field.current.state.valid) {
7277
this._field.current.focus();
7378
this._field.current.validate({ allowEmpty: false, focused: true });
79+
this.setState({ busy: false });
7480
return;
7581
}
7682
}
@@ -125,7 +131,8 @@ export default class TextInputDialog extends React.Component {
125131
</div>
126132
</form>
127133
<DialogButtons
128-
primaryButton={this.props.button}
134+
primaryButton={this.state.busy ? _t(this.props.busyMessage) : this.props.button}
135+
disabled={this.state.busy}
129136
onPrimaryButtonClick={this.onOk}
130137
onCancel={this.onCancel}
131138
hasCancel={this.props.hasCancel}

0 commit comments

Comments
 (0)