From 49683e6079fb9c3736520e220f5b0ed24c71ddc6 Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Mon, 17 Jun 2024 10:29:15 +0800 Subject: [PATCH] fix: migrate the private views only if they are not empty (#5544) --- .../application/sidebar/space/space_bloc.dart | 70 ++++++++++--------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/frontend/appflowy_flutter/lib/workspace/application/sidebar/space/space_bloc.dart b/frontend/appflowy_flutter/lib/workspace/application/sidebar/space/space_bloc.dart index 337ec43881..eba03cd803 100644 --- a/frontend/appflowy_flutter/lib/workspace/application/sidebar/space/space_bloc.dart +++ b/frontend/appflowy_flutter/lib/workspace/application/sidebar/space/space_bloc.dart @@ -82,7 +82,7 @@ class SpaceBloc extends Bloc { ); if (shouldShowUpgradeDialog) { - // add(const SpaceEvent.migrate()); + add(const SpaceEvent.migrate()); } }, create: (name, icon, iconColor, permission) async { @@ -383,7 +383,7 @@ class SpaceBloc extends Bloc { }); } - Future migrate() async { + Future migrate({bool auto = true}) async { if (_workspaceId == null) { return false; } @@ -407,45 +407,51 @@ class SpaceBloc extends Bloc { // move all the views in the workspace to the new public/private space final publicViews = await _workspaceService.getPublicViews().getOrThrow(); - final publicSpace = await _createSpace( - name: 'Shared', - icon: builtInSpaceIcons.first, - iconColor: builtInSpaceColors.first, - permission: SpacePermission.publicToAll, - ); + // only migrate the public space if there are any public views + if (publicViews.isNotEmpty) { + final publicSpace = await _createSpace( + name: 'General', + icon: builtInSpaceIcons.first, + iconColor: builtInSpaceColors.first, + permission: SpacePermission.publicToAll, + ); - if (publicSpace != null) { - for (final view in publicViews.reversed) { - if (view.isSpace) { - continue; + if (publicSpace != null) { + for (final view in publicViews.reversed) { + if (view.isSpace) { + continue; + } + await ViewBackendService.moveViewV2( + viewId: view.id, + newParentId: publicSpace.id, + prevViewId: view.parentViewId, + ); } - await ViewBackendService.moveViewV2( - viewId: view.id, - newParentId: publicSpace.id, - prevViewId: view.parentViewId, - ); } } } // create a new private space final privateViews = await _workspaceService.getPrivateViews().getOrThrow(); - final privateSpace = await _createSpace( - name: 'Private', - icon: builtInSpaceIcons.last, - iconColor: builtInSpaceColors.last, - permission: SpacePermission.private, - ); - if (privateSpace != null) { - for (final view in privateViews.reversed) { - if (view.isSpace) { - continue; + // only migrate the private space if there are any private views + if (privateViews.isNotEmpty) { + final privateSpace = await _createSpace( + name: 'Private', + icon: builtInSpaceIcons.last, + iconColor: builtInSpaceColors.last, + permission: SpacePermission.private, + ); + if (privateSpace != null) { + for (final view in privateViews.reversed) { + if (view.isSpace) { + continue; + } + await ViewBackendService.moveViewV2( + viewId: view.id, + newParentId: privateSpace.id, + prevViewId: view.parentViewId, + ); } - await ViewBackendService.moveViewV2( - viewId: view.id, - newParentId: privateSpace.id, - prevViewId: view.parentViewId, - ); } }