Skip to content

Commit

Permalink
ui: remove random names
Browse files Browse the repository at this point in the history
  • Loading branch information
jjanku committed May 29, 2022
1 parent 1529d3e commit c202b1e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 99 deletions.
80 changes: 0 additions & 80 deletions lib/util/rnd_name_generator.dart

This file was deleted.

2 changes: 0 additions & 2 deletions lib/widget/new_group_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import '../card/card.dart';
import '../routes.dart';
import '../model/mpc_model.dart';
import '../util/chars.dart';
import '../util/rnd_name_generator.dart';

class NewGroupPage extends StatefulWidget {
const NewGroupPage({Key? key}) : super(key: key);
Expand All @@ -28,7 +27,6 @@ class _NewGroupPageState extends State<NewGroupPage> {
void initState() {
super.initState();
_members.add(MpcModel.thisDevice);
_nameController.text = RndNameGenerator().next();
_nameController.addListener(() {
if (_nameErr != null) {
setState(() {
Expand Down
47 changes: 30 additions & 17 deletions lib/widget/registration_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:provider/provider.dart';
import '../model/mpc_model.dart';
import '../routes.dart';
import '../util/chars.dart';
import '../util/rnd_name_generator.dart';

class RegistrationPage extends StatefulWidget {
const RegistrationPage({Key? key}) : super(key: key);
Expand All @@ -16,26 +15,29 @@ class RegistrationPage extends StatefulWidget {
}

class _RegistrationPageState extends State<RegistrationPage> {
final _nameController = TextEditingController(
text: RndNameGenerator().next(),
);
final _nameController = TextEditingController();
final _hostController = TextEditingController(
text: 'meesign.local',
);

bool _working = false;
Exception? _error;
// FIXME: use form?
TextEditingController? _errorField;

@override
void initState() {
super.initState();
_hostController.addListener(() {
if (_error != null) {
setState(() {
_error = null;
});
}
});

void Function() makeListener(TextEditingController controller) => () {
if (_errorField == controller) {
setState(() {
_errorField = null;
});
}
};

_nameController.addListener(makeListener(_nameController));
_hostController.addListener(makeListener(_hostController));
}

@override
Expand All @@ -46,9 +48,16 @@ class _RegistrationPageState extends State<RegistrationPage> {
}

Future<void> _register() async {
if (_nameController.text.isEmpty) {
setState(() {
_errorField = _nameController;
});
return;
}

setState(() {
_working = true;
_error = null;
_errorField = null;
});

MpcModel model = context.read<MpcModel>();
Expand All @@ -61,7 +70,7 @@ class _RegistrationPageState extends State<RegistrationPage> {
} catch (e) {
setState(() {
_working = false;
_error = e as Exception?;
_errorField = _hostController;
});
}
}
Expand Down Expand Up @@ -99,9 +108,11 @@ class _RegistrationPageState extends State<RegistrationPage> {
),
TextField(
controller: _nameController,
decoration: const InputDecoration(
decoration: InputDecoration(
labelText: 'Name',
border: OutlineInputBorder(),
border: const OutlineInputBorder(),
errorText:
_errorField == _nameController ? 'Invalid name' : null,
),
textInputAction: TextInputAction.next,
enabled: !_working,
Expand All @@ -120,7 +131,9 @@ class _RegistrationPageState extends State<RegistrationPage> {
decoration: InputDecoration(
labelText: 'Coordinator address',
border: const OutlineInputBorder(),
errorText: _error == null ? null : 'Failed to register',
errorText: _errorField == _hostController
? 'Failed to register'
: null,
),
enabled: !_working,
onSubmitted: (_) => _register(),
Expand Down

0 comments on commit c202b1e

Please sign in to comment.