diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/sidebar.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/sidebar.dart index d05200cabf..9c19184217 100644 --- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/sidebar.dart +++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/sidebar.dart @@ -176,43 +176,35 @@ class HomeSideBar extends StatelessWidget { listener: _onNotificationAction, ), BlocListener( - listenWhen: (previous, current) => - previous.currentWorkspace?.workspaceId != - current.currentWorkspace?.workspaceId || - current.actionResult?.actionType == - UserWorkspaceActionType.create || - current.actionResult?.actionType == - UserWorkspaceActionType.delete || - current.actionResult?.actionType == - UserWorkspaceActionType.open, listener: (context, state) { - final workspaceId = state.currentWorkspace?.workspaceId ?? - workspaceSetting.workspaceId; + final actionType = state.actionResult?.actionType; - // Reset all workspace-specific data - getIt().reset(); + if (actionType == UserWorkspaceActionType.create || + actionType == UserWorkspaceActionType.delete || + actionType == UserWorkspaceActionType.open) { + if (context.read().state.spaces.isEmpty) { + context.read().add( + SidebarSectionsEvent.reload( + userProfile, + state.currentWorkspace?.workspaceId ?? + workspaceSetting.workspaceId, + ), + ); + } else { + context.read().add( + SpaceEvent.reset( + userProfile, + state.currentWorkspace?.workspaceId ?? + workspaceSetting.workspaceId, + true, + ), + ); + } - // Always reload sidebar sections to ensure fresh data - context.read().add( - SidebarSectionsEvent.reload( - userProfile, - workspaceId, - ), - ); - - // Reset space data with the current workspace - context.read().add( - SpaceEvent.reset( - userProfile, - workspaceId, - true, - ), - ); - - // Fetch updated favorites - context - .read() - .add(const FavoriteEvent.fetchFavorites()); + context + .read() + .add(const FavoriteEvent.fetchFavorites()); + } }, ), ],