TF-4384 Fix page not found 404 error when refreshing label views (#4390)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:core/presentation/resources/image_paths.dart';
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||
import 'package:labels/model/label.dart';
|
||||
import 'package:tmail_ui_user/features/labels/presentation/extensions/handle_label_action_type_extension.dart';
|
||||
import 'package:tmail_ui_user/features/labels/presentation/models/label_action_type.dart';
|
||||
@@ -64,4 +65,22 @@ extension HandleLabelActionTypeExtension on MailboxDashBoardController {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Label? getLabelById(Id labelId) {
|
||||
return labelController.labels
|
||||
.where((label) => label.id == labelId)
|
||||
.firstOrNull;
|
||||
}
|
||||
|
||||
void scrollToLabelListView() {
|
||||
final context = labelController.labelAppBarKey.currentContext;
|
||||
if (context == null) return;
|
||||
|
||||
Scrollable.ensureVisible(
|
||||
context,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
curve: Curves.easeOut,
|
||||
alignment: 0.5,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:get/get_rx/src/rx_workers/rx_workers.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/extensions/handle_label_action_type_extension.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/mailbox_controller.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/model/presentation_label_mailbox.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/extensions/labels/handle_logic_label_extension.dart';
|
||||
import 'package:tmail_ui_user/main/routes/app_routes.dart';
|
||||
import 'package:tmail_ui_user/main/routes/navigation_router.dart';
|
||||
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
||||
|
||||
extension HandleNavigationExtension on MailboxController {
|
||||
void handleLabelNavigation(NavigationRouter router, Id labelId) {
|
||||
if (!_isLabelCapabilityValid()) {
|
||||
_navigateToUnknown();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_isLabelsReady()) {
|
||||
_waitForLabelsLoaded(() {
|
||||
_handleLabelNavigationInternal(router, labelId);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
_handleLabelNavigationInternal(router, labelId);
|
||||
}
|
||||
|
||||
bool _isLabelCapabilityValid() {
|
||||
return mailboxDashBoardController.isLabelCapabilitySupported;
|
||||
}
|
||||
|
||||
bool _isLabelsReady() {
|
||||
return mailboxDashBoardController.labelController.isLabelsLoaded.value;
|
||||
}
|
||||
|
||||
void _waitForLabelsLoaded(VoidCallback onLoaded) {
|
||||
isLabelsLoadedWorker?.dispose();
|
||||
isLabelsLoadedWorker = null;
|
||||
|
||||
final observable = mailboxDashBoardController.labelController.isLabelsLoaded;
|
||||
|
||||
if (observable.value) {
|
||||
onLoaded();
|
||||
return;
|
||||
}
|
||||
|
||||
isLabelsLoadedWorker = ever(
|
||||
observable,
|
||||
(isLoaded) {
|
||||
try {
|
||||
if (!isLoaded) return;
|
||||
_completeLabelsLoaded(onLoaded);
|
||||
} catch (e) {
|
||||
logWarning('HandleNavigationExtension::_waitForLabelsLoaded: Exception: $e');
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _completeLabelsLoaded(VoidCallback onLoaded) {
|
||||
final worker = isLabelsLoadedWorker;
|
||||
if (worker == null) return;
|
||||
|
||||
isLabelsLoadedWorker = null;
|
||||
worker.dispose();
|
||||
|
||||
if (!isClosed) {
|
||||
onLoaded();
|
||||
}
|
||||
}
|
||||
|
||||
void _handleLabelNavigationInternal(
|
||||
NavigationRouter router,
|
||||
Id labelId,
|
||||
) {
|
||||
final matchedLabel = mailboxDashBoardController.getLabelById(labelId);
|
||||
|
||||
if (matchedLabel == null) {
|
||||
_navigateToUnknown();
|
||||
return;
|
||||
}
|
||||
|
||||
final labelMailbox = PresentationLabelMailbox.initial(matchedLabel);
|
||||
|
||||
if (router.emailId != null) {
|
||||
openEmailInsideMailboxFromLocationBar(
|
||||
labelMailbox,
|
||||
router.emailId!,
|
||||
);
|
||||
} else {
|
||||
openMailboxFromLocationBar(labelMailbox);
|
||||
}
|
||||
|
||||
mailboxDashBoardController.scrollToLabelListView();
|
||||
}
|
||||
|
||||
void _navigateToUnknown() {
|
||||
clearNavigationRouter();
|
||||
popAndPush(AppRoutes.unknownRoutePage);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
|
||||
import 'package:core/presentation/resources/image_paths.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:labels/extensions/label_extension.dart';
|
||||
import 'package:model/extensions/mailbox_id_extension.dart';
|
||||
import 'package:model/extensions/presentation_mailbox_extension.dart';
|
||||
import 'package:model/mailbox/presentation_mailbox.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/model/presentation_label_mailbox.dart';
|
||||
@@ -160,4 +163,13 @@ extension PresentationMailboxExtension on PresentationMailbox {
|
||||
bool get isCacheable => !isVirtualFolder && this is! PresentationLabelMailbox;
|
||||
|
||||
bool get isLabelMailbox => this is PresentationLabelMailbox;
|
||||
|
||||
String get browserRouteTitle => isLabelMailbox
|
||||
? 'Label-${(this as PresentationLabelMailbox).label.id?.value}'
|
||||
: 'Mailbox-${mailboxId?.asString}';
|
||||
|
||||
Id? get labelId =>
|
||||
isLabelMailbox ? (this as PresentationLabelMailbox).label.id : null;
|
||||
|
||||
MailboxId? get browserRouteMailboxId => isLabelMailbox ? null : mailboxId;
|
||||
}
|
||||
Reference in New Issue
Block a user