refactor: Improve delete device UX flow
This commit is contained in:
parent
38283d2b27
commit
d14698ee94
3 changed files with 18 additions and 33 deletions
|
|
@ -9,7 +9,6 @@ import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/pages/device_settings/device_settings_view.dart';
|
import 'package:fluffychat/pages/device_settings/device_settings_view.dart';
|
||||||
import 'package:fluffychat/pages/key_verification/key_verification_dialog.dart';
|
import 'package:fluffychat/pages/key_verification/key_verification_dialog.dart';
|
||||||
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
|
||||||
import '../../widgets/matrix.dart';
|
import '../../widgets/matrix.dart';
|
||||||
|
|
||||||
class DevicesSettings extends StatefulWidget {
|
class DevicesSettings extends StatefulWidget {
|
||||||
|
|
@ -29,9 +28,6 @@ class DevicesSettingsController extends State<DevicesSettings> {
|
||||||
|
|
||||||
void reload() => setState(() => devices = null);
|
void reload() => setState(() => devices = null);
|
||||||
|
|
||||||
bool loadingDeletingDevices = false;
|
|
||||||
String? errorDeletingDevices;
|
|
||||||
|
|
||||||
bool? chatBackupEnabled;
|
bool? chatBackupEnabled;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -69,24 +65,16 @@ class DevicesSettingsController extends State<DevicesSettings> {
|
||||||
deviceIds.add(userDevice.deviceId);
|
deviceIds.add(userDevice.deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
await showFutureLoadingDialog(
|
||||||
setState(() {
|
context: context,
|
||||||
loadingDeletingDevices = true;
|
future: () => matrix.client.uiaRequestBackground(
|
||||||
errorDeletingDevices = null;
|
|
||||||
});
|
|
||||||
await matrix.client.uiaRequestBackground(
|
|
||||||
(auth) => matrix.client.deleteDevices(
|
(auth) => matrix.client.deleteDevices(
|
||||||
deviceIds,
|
deviceIds,
|
||||||
auth: auth,
|
auth: auth,
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
reload();
|
);
|
||||||
} catch (e, s) {
|
reload();
|
||||||
Logs().w('Error while deleting devices', e, s);
|
|
||||||
setState(() => errorDeletingDevices = e.toLocalizedString(context));
|
|
||||||
} finally {
|
|
||||||
setState(() => loadingDeletingDevices = false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void renameDeviceAction(Device device) async {
|
void renameDeviceAction(Device device) async {
|
||||||
|
|
|
||||||
|
|
@ -96,8 +96,7 @@ class DevicesSettingsView extends StatelessWidget {
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
child: TextButton.icon(
|
child: TextButton.icon(
|
||||||
label: Text(
|
label: Text(
|
||||||
controller.errorDeletingDevices ??
|
L10n.of(context).removeAllOtherDevices,
|
||||||
L10n.of(context).removeAllOtherDevices,
|
|
||||||
),
|
),
|
||||||
style: TextButton.styleFrom(
|
style: TextButton.styleFrom(
|
||||||
foregroundColor:
|
foregroundColor:
|
||||||
|
|
@ -105,16 +104,10 @@ class DevicesSettingsView extends StatelessWidget {
|
||||||
backgroundColor:
|
backgroundColor:
|
||||||
theme.colorScheme.errorContainer,
|
theme.colorScheme.errorContainer,
|
||||||
),
|
),
|
||||||
icon: controller.loadingDeletingDevices
|
icon: const Icon(Icons.delete_outline),
|
||||||
? const CircularProgressIndicator.adaptive(
|
onPressed: () => controller.removeDevicesAction(
|
||||||
strokeWidth: 2,
|
controller.notThisDevice,
|
||||||
)
|
),
|
||||||
: const Icon(Icons.delete_outline),
|
|
||||||
onPressed: controller.loadingDeletingDevices
|
|
||||||
? null
|
|
||||||
: () => controller.removeDevicesAction(
|
|
||||||
controller.notThisDevice,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,15 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
import 'package:url_launcher/url_launcher_string.dart';
|
||||||
|
|
||||||
|
import 'package:fluffychat/widgets/fluffy_chat_app.dart';
|
||||||
import 'package:fluffychat/widgets/matrix.dart';
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
|
|
||||||
extension UiaRequestManager on MatrixState {
|
extension UiaRequestManager on MatrixState {
|
||||||
Future uiaRequestHandler(UiaRequest uiaRequest) async {
|
Future uiaRequestHandler(UiaRequest uiaRequest) async {
|
||||||
final l10n = L10n.of(context);
|
final l10n = L10n.of(context);
|
||||||
|
final navigatorContext =
|
||||||
|
FluffyChatApp.router.routerDelegate.navigatorKey.currentContext ??
|
||||||
|
context;
|
||||||
try {
|
try {
|
||||||
if (uiaRequest.state != UiaRequestState.waitForUser ||
|
if (uiaRequest.state != UiaRequestState.waitForUser ||
|
||||||
uiaRequest.nextStages.isEmpty) {
|
uiaRequest.nextStages.isEmpty) {
|
||||||
|
|
@ -22,7 +26,7 @@ extension UiaRequestManager on MatrixState {
|
||||||
case AuthenticationTypes.password:
|
case AuthenticationTypes.password:
|
||||||
final input = cachedPassword ??
|
final input = cachedPassword ??
|
||||||
(await showTextInputDialog(
|
(await showTextInputDialog(
|
||||||
context: context,
|
context: navigatorContext,
|
||||||
title: l10n.pleaseEnterYourPassword,
|
title: l10n.pleaseEnterYourPassword,
|
||||||
okLabel: l10n.ok,
|
okLabel: l10n.ok,
|
||||||
cancelLabel: l10n.cancel,
|
cancelLabel: l10n.cancel,
|
||||||
|
|
@ -63,7 +67,7 @@ extension UiaRequestManager on MatrixState {
|
||||||
if (OkCancelResult.ok ==
|
if (OkCancelResult.ok ==
|
||||||
await showOkCancelAlertDialog(
|
await showOkCancelAlertDialog(
|
||||||
useRootNavigator: false,
|
useRootNavigator: false,
|
||||||
context: context,
|
context: navigatorContext,
|
||||||
title: l10n.weSentYouAnEmail,
|
title: l10n.weSentYouAnEmail,
|
||||||
message: l10n.pleaseClickOnLink,
|
message: l10n.pleaseClickOnLink,
|
||||||
okLabel: l10n.iHaveClickedOnLink,
|
okLabel: l10n.iHaveClickedOnLink,
|
||||||
|
|
@ -88,7 +92,7 @@ extension UiaRequestManager on MatrixState {
|
||||||
await showOkCancelAlertDialog(
|
await showOkCancelAlertDialog(
|
||||||
useRootNavigator: false,
|
useRootNavigator: false,
|
||||||
message: l10n.pleaseFollowInstructionsOnWeb,
|
message: l10n.pleaseFollowInstructionsOnWeb,
|
||||||
context: context,
|
context: navigatorContext,
|
||||||
okLabel: l10n.next,
|
okLabel: l10n.next,
|
||||||
cancelLabel: l10n.cancel,
|
cancelLabel: l10n.cancel,
|
||||||
)) {
|
)) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue