Skip to content

Commit

Permalink
refactor: Improve delete device UX flow
Browse files Browse the repository at this point in the history
  • Loading branch information
krille-chan committed Oct 13, 2024
1 parent 38283d2 commit d14698e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 33 deletions.
24 changes: 6 additions & 18 deletions lib/pages/device_settings/device_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:matrix/matrix.dart';

import 'package:fluffychat/pages/device_settings/device_settings_view.dart';
import 'package:fluffychat/pages/key_verification/key_verification_dialog.dart';
import 'package:fluffychat/utils/localized_exception_extension.dart';
import '../../widgets/matrix.dart';

class DevicesSettings extends StatefulWidget {
Expand All @@ -29,9 +28,6 @@ class DevicesSettingsController extends State<DevicesSettings> {

void reload() => setState(() => devices = null);

bool loadingDeletingDevices = false;
String? errorDeletingDevices;

bool? chatBackupEnabled;

@override
Expand Down Expand Up @@ -69,24 +65,16 @@ class DevicesSettingsController extends State<DevicesSettings> {
deviceIds.add(userDevice.deviceId);
}

try {
setState(() {
loadingDeletingDevices = true;
errorDeletingDevices = null;
});
await matrix.client.uiaRequestBackground(
await showFutureLoadingDialog(
context: context,
future: () => matrix.client.uiaRequestBackground(
(auth) => matrix.client.deleteDevices(
deviceIds,
auth: auth,
),
);
reload();
} catch (e, s) {
Logs().w('Error while deleting devices', e, s);
setState(() => errorDeletingDevices = e.toLocalizedString(context));
} finally {
setState(() => loadingDeletingDevices = false);
}
),
);
reload();
}

void renameDeviceAction(Device device) async {
Expand Down
17 changes: 5 additions & 12 deletions lib/pages/device_settings/device_settings_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,18 @@ class DevicesSettingsView extends StatelessWidget {
width: double.infinity,
child: TextButton.icon(
label: Text(
controller.errorDeletingDevices ??
L10n.of(context).removeAllOtherDevices,
L10n.of(context).removeAllOtherDevices,
),
style: TextButton.styleFrom(
foregroundColor:
theme.colorScheme.onErrorContainer,
backgroundColor:
theme.colorScheme.errorContainer,
),
icon: controller.loadingDeletingDevices
? const CircularProgressIndicator.adaptive(
strokeWidth: 2,
)
: const Icon(Icons.delete_outline),
onPressed: controller.loadingDeletingDevices
? null
: () => controller.removeDevicesAction(
controller.notThisDevice,
),
icon: const Icon(Icons.delete_outline),
onPressed: () => controller.removeDevicesAction(
controller.notThisDevice,
),
),
),
)
Expand Down
10 changes: 7 additions & 3 deletions lib/utils/uia_request_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:matrix/matrix.dart';
import 'package:url_launcher/url_launcher_string.dart';

import 'package:fluffychat/widgets/fluffy_chat_app.dart';
import 'package:fluffychat/widgets/matrix.dart';

extension UiaRequestManager on MatrixState {
Future uiaRequestHandler(UiaRequest uiaRequest) async {
final l10n = L10n.of(context);
final navigatorContext =
FluffyChatApp.router.routerDelegate.navigatorKey.currentContext ??
context;
try {
if (uiaRequest.state != UiaRequestState.waitForUser ||
uiaRequest.nextStages.isEmpty) {
Expand All @@ -22,7 +26,7 @@ extension UiaRequestManager on MatrixState {
case AuthenticationTypes.password:
final input = cachedPassword ??
(await showTextInputDialog(
context: context,
context: navigatorContext,
title: l10n.pleaseEnterYourPassword,
okLabel: l10n.ok,
cancelLabel: l10n.cancel,
Expand Down Expand Up @@ -63,7 +67,7 @@ extension UiaRequestManager on MatrixState {
if (OkCancelResult.ok ==
await showOkCancelAlertDialog(
useRootNavigator: false,
context: context,
context: navigatorContext,
title: l10n.weSentYouAnEmail,
message: l10n.pleaseClickOnLink,
okLabel: l10n.iHaveClickedOnLink,
Expand All @@ -88,7 +92,7 @@ extension UiaRequestManager on MatrixState {
await showOkCancelAlertDialog(
useRootNavigator: false,
message: l10n.pleaseFollowInstructionsOnWeb,
context: context,
context: navigatorContext,
okLabel: l10n.next,
cancelLabel: l10n.cancel,
)) {
Expand Down

0 comments on commit d14698e

Please sign in to comment.