Skip to content

Commit

Permalink
TF-1831 Persist browser history when invoke system back button in Set…
Browse files Browse the repository at this point in the history
…ting View

Signed-off-by: dab246 <[email protected]>
  • Loading branch information
dab246 authored and hoangdat committed Dec 15, 2023
1 parent 2f0e62a commit fe6b0a5
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1414,13 +1414,23 @@ class MailboxDashBoardController extends ReloadableController {
BackButtonInterceptor.removeByName(AppRoutes.dashboard);
final result = await push(
AppRoutes.settings,
arguments: ManageAccountArguments(sessionCurrent)
arguments: ManageAccountArguments(
sessionCurrent,
previousUri: RouteUtils.baseUri,
),
);

BackButtonInterceptor.add(_onBackButtonInterceptor, name: AppRoutes.dashboard);
if (result is VacationResponse) {
vacationResponse.value = result;
dispatchMailboxUIAction(RefreshChangeMailboxAction(null));

if (result is Tuple2) {
if (result.value1 is VacationResponse) {
vacationResponse.value = result.value1;
dispatchMailboxUIAction(RefreshChangeMailboxAction(null));
}
await Future.delayed(
const Duration(milliseconds: 500),
() => _replaceBrowserHistory(uri: result.value2)
);
}
}

Expand Down Expand Up @@ -1477,13 +1487,22 @@ class MailboxDashBoardController extends ReloadableController {
AppRoutes.settings,
arguments: ManageAccountArguments(
sessionCurrent,
menuSettingCurrent: AccountMenuItem.vacation
menuSettingCurrent: AccountMenuItem.vacation,
previousUri: RouteUtils.baseUri
)
);

BackButtonInterceptor.add(_onBackButtonInterceptor, name: AppRoutes.dashboard);
if (result is VacationResponse) {
vacationResponse.value = result;

if (result is Tuple2) {
if (result.value1 is VacationResponse) {
vacationResponse.value = result.value1;
dispatchMailboxUIAction(RefreshChangeMailboxAction(null));
}
await Future.delayed(
const Duration(milliseconds: 500),
() => _replaceBrowserHistory(uri: result.value2)
);
}
}

Expand Down Expand Up @@ -2232,7 +2251,8 @@ class MailboxDashBoardController extends ReloadableController {
setSelectedEmail(email.toPresentationEmail());
}

void _replaceBrowserHistory() {
void _replaceBrowserHistory({Uri? uri}) {
log('MailboxDashBoardController::_replaceBrowserHistory:uri: $uri');
if (PlatformInfo.isWeb) {
final selectedMailboxId = selectedMailbox.value?.id;
final selectedEmailId = selectedEmail.value?.id;
Expand All @@ -2247,7 +2267,7 @@ class MailboxDashBoardController extends ReloadableController {
}
RouteUtils.replaceBrowserHistory(
title: title,
url: RouteUtils.createUrlWebLocationBar(
url: uri ?? RouteUtils.createUrlWebLocationBar(
AppRoutes.dashboard,
router: NavigationRouter(
emailId: selectedEmail.value?.id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import 'package:back_button_interceptor/back_button_interceptor.dart';
import 'package:core/core.dart';
import 'package:dartz/dartz.dart';
import 'package:flutter/material.dart';
import 'package:forward/forward/capability_forward.dart';
import 'package:get/get.dart';
Expand Down Expand Up @@ -51,6 +52,7 @@ class ManageAccountDashBoardController extends ReloadableController {

Session? sessionCurrent;
bool? isVacationDateDialogDisplayed;
Uri? previousUri;

@override
void onInit() {
Expand Down Expand Up @@ -97,6 +99,7 @@ class ManageAccountDashBoardController extends ReloadableController {
if (arguments is ManageAccountArguments) {
sessionCurrent = arguments.session;
accountId.value = arguments.session?.personalAccount.accountId;
previousUri = arguments.previousUri;
_getUserProfile();
_bindingInteractorForMenuItemView(sessionCurrent, accountId.value);
_getVacationResponse();
Expand Down Expand Up @@ -217,7 +220,7 @@ class ManageAccountDashBoardController extends ReloadableController {

void backToMailboxDashBoard({BuildContext? context}) {
if (context != null && canBack(context)) {
popBack(result: vacationResponse.value);
popBack(result: Tuple2(vacationResponse.value, previousUri));
} else {
log('ManageAccountDashBoardController::backToMailboxDashBoard(): canBack: FALSE');
pushAndPopAll(
Expand Down Expand Up @@ -316,32 +319,22 @@ class ManageAccountDashBoardController extends ReloadableController {

bool _navigateToScreen() {
log('ManageAccountDashBoardController::_navigateToScreen: settingsPageLevel: $settingsPageLevel');
if (PlatformInfo.isMobile) {
if (currentContext != null && responsiveUtils.isWebDesktop(currentContext!)) {
if (accountMenuItemSelected.value == AccountMenuItem.profiles) {
backToMailboxDashBoard(context: currentContext);
return true;
} else {
selectSettings(AccountMenuItem.profiles);
return true;
}
} else {
switch(settingsPageLevel.value) {
case SettingsPageLevel.level1:
backToUniversalSettings();
return true;
case SettingsPageLevel.universal:
return false;
}
} else {
if (currentContext != null && responsiveUtils.isWebDesktop(currentContext!)) {
if (accountMenuItemSelected.value == AccountMenuItem.profiles) {
backToMailboxDashBoard(context: currentContext);
return true;
} else {
selectSettings(AccountMenuItem.profiles);
return true;
}
} else {
switch(settingsPageLevel.value) {
case SettingsPageLevel.level1:
backToUniversalSettings();
return true;
case SettingsPageLevel.universal:
backToMailboxDashBoard(context: currentContext);
return true;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,20 @@ class ManageAccountArguments with EquatableMixin {

final Session? session;
final AccountMenuItem? menuSettingCurrent;
final Uri? previousUri;

ManageAccountArguments(this.session, {this.menuSettingCurrent});
ManageAccountArguments(
this.session,
{
this.menuSettingCurrent,
this.previousUri,
}
);

@override
List<Object?> get props => [session, menuSettingCurrent];
List<Object?> get props => [
session,
menuSettingCurrent,
previousUri,
];
}

0 comments on commit fe6b0a5

Please sign in to comment.