TF-4384 Fix page not found 404 error when refreshing label views (#4390)
This commit is contained in:
@@ -368,6 +368,7 @@ abstract class BaseMailboxView extends GetWidget<MailboxController>
|
||||
final countLabels = labelController.labels.length;
|
||||
|
||||
return LabelsBarWidget(
|
||||
key: labelController.labelAppBarKey,
|
||||
imagePaths: controller.imagePaths,
|
||||
isDesktop: isDesktop,
|
||||
height: isDesktop ? 48 : 40,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -70,6 +70,7 @@ import 'package:tmail_ui_user/features/mailbox/domain/usecases/subscribe_mailbox
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/usecases/subscribe_multiple_mailbox_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/action/mailbox_ui_action.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/extensions/handle_action_required_tab_extension.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/extensions/handle_navigation_extension.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/extensions/presentation_mailbox_extension.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/mixin/mailbox_widget_mixin.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_actions.dart';
|
||||
@@ -133,6 +134,7 @@ class MailboxController extends BaseMailboxController
|
||||
MailboxId? _newFolderId;
|
||||
NavigationRouter? _navigationRouter;
|
||||
WebSocketQueueHandler? _webSocketQueueHandler;
|
||||
Worker? isLabelsLoadedWorker;
|
||||
|
||||
final _openMailboxEventController = StreamController<OpenMailboxViewEvent>();
|
||||
StreamSubscription? _openMailboxEventStreamSubscription;
|
||||
@@ -198,6 +200,8 @@ class MailboxController extends BaseMailboxController
|
||||
_openMailboxEventController.close();
|
||||
mailboxListScrollController.dispose();
|
||||
_webSocketQueueHandler?.dispose();
|
||||
isLabelsLoadedWorker?.dispose();
|
||||
isLabelsLoadedWorker = null;
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
@@ -787,7 +791,9 @@ class MailboxController extends BaseMailboxController
|
||||
}
|
||||
break;
|
||||
case DashboardType.normal:
|
||||
if (_navigationRouter!.mailboxId != null) {
|
||||
if (_navigationRouter!.labelId != null) {
|
||||
handleLabelNavigation(_navigationRouter!, _navigationRouter!.labelId!);
|
||||
} else if (_navigationRouter!.mailboxId != null) {
|
||||
final matchedMailboxNode = findMailboxNodeById(_navigationRouter!.mailboxId!);
|
||||
if (matchedMailboxNode != null) {
|
||||
if (_navigationRouter!.emailId != null) {
|
||||
@@ -813,6 +819,11 @@ class MailboxController extends BaseMailboxController
|
||||
}
|
||||
}
|
||||
|
||||
void openEmailInsideMailboxFromLocationBar(
|
||||
PresentationMailbox presentationMailbox,
|
||||
EmailId emailId
|
||||
) => _openEmailInsideMailboxFromLocationBar(presentationMailbox, emailId);
|
||||
|
||||
void _openEmailInsideMailboxFromLocationBar(
|
||||
PresentationMailbox presentationMailbox,
|
||||
EmailId emailId
|
||||
@@ -822,15 +833,19 @@ class MailboxController extends BaseMailboxController
|
||||
_clearNavigationRouter();
|
||||
}
|
||||
|
||||
void openMailboxFromLocationBar(PresentationMailbox presentationMailbox) =>
|
||||
_openMailboxFromLocationBar(presentationMailbox);
|
||||
|
||||
void _openMailboxFromLocationBar(PresentationMailbox presentationMailbox) {
|
||||
mailboxDashBoardController.setSelectedMailbox(presentationMailbox);
|
||||
if (PlatformInfo.isWeb) {
|
||||
RouteUtils.replaceBrowserHistory(
|
||||
title: 'Mailbox-${presentationMailbox.mailboxId?.id.value}',
|
||||
title: presentationMailbox.browserRouteTitle,
|
||||
url: RouteUtils.createUrlWebLocationBar(
|
||||
AppRoutes.dashboard,
|
||||
router: NavigationRouter(
|
||||
mailboxId: presentationMailbox.mailboxId,
|
||||
mailboxId: presentationMailbox.browserRouteMailboxId,
|
||||
labelId: presentationMailbox.labelId,
|
||||
dashboardType: DashboardType.normal
|
||||
)
|
||||
)
|
||||
@@ -868,6 +883,8 @@ class MailboxController extends BaseMailboxController
|
||||
_clearNavigationRouter();
|
||||
}
|
||||
|
||||
void clearNavigationRouter() => _clearNavigationRouter();
|
||||
|
||||
void _clearNavigationRouter() {
|
||||
_navigationRouter = null;
|
||||
}
|
||||
@@ -1279,13 +1296,14 @@ class MailboxController extends BaseMailboxController
|
||||
}
|
||||
|
||||
void _replaceBrowserHistory() {
|
||||
log('MailboxController::_replaceBrowserHistory:selectedMailbox: ${selectedMailbox?.id}');
|
||||
final currentMailbox = selectedMailbox;
|
||||
log('MailboxController::_replaceBrowserHistory:selectedMailbox: ${currentMailbox?.id.asString}');
|
||||
if (PlatformInfo.isWeb && Get.currentRoute.startsWith(AppRoutes.dashboard)) {
|
||||
final selectedMailboxId = selectedMailbox?.id;
|
||||
final route = RouteUtils.createUrlWebLocationBar(
|
||||
AppRoutes.dashboard,
|
||||
router: NavigationRouter(
|
||||
mailboxId: selectedMailboxId,
|
||||
mailboxId: currentMailbox?.browserRouteMailboxId,
|
||||
labelId: currentMailbox?.labelId,
|
||||
searchQuery: mailboxDashBoardController.searchController.isSearchEmailRunning
|
||||
? mailboxDashBoardController.searchController.searchQuery
|
||||
: null,
|
||||
@@ -1295,7 +1313,7 @@ class MailboxController extends BaseMailboxController
|
||||
)
|
||||
);
|
||||
RouteUtils.replaceBrowserHistory(
|
||||
title: 'Mailbox-${selectedMailboxId?.id.value}',
|
||||
title: currentMailbox?.browserRouteTitle ?? '',
|
||||
url: route
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user