Commit b6fdd6f4 authored by Wilko Manger's avatar Wilko Manger

Fix no errors shown when necessary on UsernamePage

Also fix loading spinner showing too soon if the
request was not the first one.
parent 7d6b3b8a
......@@ -15,6 +15,9 @@
// You should have received a copy of the GNU Affero General Public License
// along with Pattle. If not, see <https://www.gnu.org/licenses/>.
import 'dart:async';
import 'package:async/async.dart';
import 'package:matrix_sdk/matrix_sdk.dart';
import 'package:pattle/src/di.dart' as di;
import 'package:rxdart/rxdart.dart';
......@@ -56,25 +59,30 @@ class StartBloc {
Observable<UsernameAvailableState> get isUsernameAvailable
=> _isUsernameAvailableSubj.stream.distinct();
void checkUsernameAvailability(String username) {
StreamSubscription stillCheckingSubscription;
Future<void> checkUsernameAvailability(String username) async {
if (username == null) {
return;
}
await stillCheckingSubscription?.cancel();
_isUsernameAvailableSubj.add(UsernameAvailableState.checking);
// If after three seconds it's still checking, change state to
// 'stillChecking'.
Future.delayed(loadingTime).then((_) {
_isUsernameAvailableSubj.stream.listen((state) {
if (state == UsernameAvailableState.checking) {
_isUsernameAvailableSubj.add(UsernameAvailableState.stillChecking);
}
});
Future.delayed(loadingTime).then((_) async {
await stillCheckingSubscription?.cancel();
stillCheckingSubscription = _isUsernameAvailableSubj.stream.listen((state) {
if (state == UsernameAvailableState.checking) {
_isUsernameAvailableSubj.add(UsernameAvailableState.stillChecking);
}
},
);
});
var addError = (error) {
_isUsernameAvailableSubj.addError(error);
final addError = (error) {
stillCheckingSubscription?.cancel();
_isUsernameAvailableSubj.add(UsernameAvailableState.none);
_isUsernameAvailableSubj.addError(error);
};
var user;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment