Skip to content

Commit

Permalink
Fixed a critical issue that caused an infinite loading loop when a de…
Browse files Browse the repository at this point in the history
…fault dashboard was assigned to a user. (#102)
  • Loading branch information
ybeshkarov authored Aug 1, 2024
1 parent 8782f3d commit 75d77a4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lib/core/context/tb_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,13 @@ class TbContext implements PopEntry {
if (defaultDashboardId != null) {
bool fullscreen = _userForceFullscreen();
if (!fullscreen) {
await navigateToDashboard(defaultDashboardId, animate: false);
navigateTo(
'/home',
replace: true,
closeDashboard: false,
transition: TransitionType.none,
);
await navigateToDashboard(defaultDashboardId, animate: false);
} else {
navigateTo(
'/fullscreenDashboard/$defaultDashboardId',
Expand Down
63 changes: 35 additions & 28 deletions lib/modules/dashboard/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,11 @@ class _DashboardState extends TbContextState<Dashboard> {
}
};
if (!UniversalPlatform.isWeb) {
var controller = await _controller.future;
await controller.postWebMessage(
message: WebMessage(data: jsonEncode(windowMessage)),
targetOrigin: Uri.parse('*'));
_controller.future.then((controller) {
controller.postWebMessage(
message: WebMessage(data: jsonEncode(windowMessage)),
targetOrigin: Uri.parse('*'));
});
}
}
}
Expand All @@ -170,6 +171,10 @@ class _DashboardState extends TbContextState<Dashboard> {
await _toggleRightLayout();
return false;
}
if (!_controller.isCompleted) {
return false;
}

var controller = await _controller.future;
if (await controller.canGoBack()) {
await controller.goBack();
Expand Down Expand Up @@ -205,34 +210,36 @@ class _DashboardState extends TbContextState<Dashboard> {
dashboardLoading.value = true;
InAppWebViewController? controller;
if (!UniversalPlatform.isWeb) {
controller = await _controller.future;
}
var windowMessage = <String, dynamic>{
'type': 'openDashboardMessage',
'data': <String, dynamic>{'dashboardId': dashboardId}
};
if (state != null) {
windowMessage['data']['state'] = state;
}
if (widget._home == true) {
windowMessage['data']['embedded'] = true;
}
if (hideToolbar == true) {
windowMessage['data']['hideToolbar'] = true;
}
var webMessage = WebMessage(data: jsonEncode(windowMessage));
if (!UniversalPlatform.isWeb) {
await controller!
.postWebMessage(message: webMessage, targetOrigin: Uri.parse('*'));
_controller.future.then((controller) {
var windowMessage = <String, dynamic>{
'type': 'openDashboardMessage',
'data': <String, dynamic>{'dashboardId': dashboardId}
};
if (state != null) {
windowMessage['data']['state'] = state;
}
if (widget._home == true) {
windowMessage['data']['embedded'] = true;
}
if (hideToolbar == true) {
windowMessage['data']['hideToolbar'] = true;
}
var webMessage = WebMessage(data: jsonEncode(windowMessage));
if (!UniversalPlatform.isWeb) {
controller.postWebMessage(
message: webMessage, targetOrigin: Uri.parse('*'));
}
});
}
}

Future<void> _toggleRightLayout() async {
var controller = await _controller.future;
var windowMessage = <String, dynamic>{'type': 'toggleDashboardLayout'};
var webMessage = WebMessage(data: jsonEncode(windowMessage));
await controller.postWebMessage(
message: webMessage, targetOrigin: Uri.parse('*'));
_controller.future.then((controller) {
var windowMessage = <String, dynamic>{'type': 'toggleDashboardLayout'};
var webMessage = WebMessage(data: jsonEncode(windowMessage));
controller.postWebMessage(
message: webMessage, targetOrigin: Uri.parse('*'));
});
}

Future<void> tryLocalNavigation(String? path) async {
Expand Down
1 change: 0 additions & 1 deletion lib/modules/dashboard/main_dashboard_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ class _MainDashboardPageState extends TbContextState<MainDashboardPage>
builder: (context, value, _) {
return Dashboard(
tbContext,
key: UniqueKey(),
activeByDefault: false,
titleCallback: (title) {
dashboardTitleValue.value = title;
Expand Down

0 comments on commit 75d77a4

Please sign in to comment.