Skip to content

Commit

Permalink
fix: open the first page(non-space) after switching workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 committed Jun 17, 2024
1 parent 7bfa910 commit aae81ba
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class MobileFolders extends StatelessWidget {
create: (_) => FavoriteBloc()..add(const FavoriteEvent.initial()),
),
BlocProvider(
create: (_) =>
SpaceBloc()..add(SpaceEvent.initial(user, workspaceId)),
create: (_) => SpaceBloc()
..add(SpaceEvent.initial(user, workspaceId, openFirstPage: false)),
),
],
child: BlocListener<UserWorkspaceBloc, UserWorkspaceState>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class SpaceBloc extends Bloc<SpaceEvent, SpaceState> {
on<SpaceEvent>(
(event, emit) async {
await event.when(
initial: (userProfile, workspaceId) async {
initial: (userProfile, workspaceId, openFirstPage) async {
_initial(userProfile, workspaceId);

final (spaces, publicViews, privateViews) = await _getSpaces();
Expand All @@ -86,6 +86,12 @@ class SpaceBloc extends Bloc<SpaceEvent, SpaceState> {
if (shouldShowUpgradeDialog) {
add(const SpaceEvent.migrate());
}

if (openFirstPage) {
if (currentSpace != null) {
add(SpaceEvent.open(currentSpace));
}
}
},
create: (
name,
Expand Down Expand Up @@ -247,7 +253,13 @@ class SpaceBloc extends Bloc<SpaceEvent, SpaceState> {
reset: (userProfile, workspaceId) async {
_reset(userProfile, workspaceId);

add(SpaceEvent.initial(userProfile, workspaceId));
add(
SpaceEvent.initial(
userProfile,
workspaceId,
openFirstPage: true,
),
);
},
migrate: () async {
final result = await migrate();
Expand Down Expand Up @@ -540,8 +552,9 @@ class SpaceBloc extends Bloc<SpaceEvent, SpaceState> {
class SpaceEvent with _$SpaceEvent {
const factory SpaceEvent.initial(
UserProfilePB userProfile,
String workspaceId,
) = _Initial;
String workspaceId, {
required bool openFirstPage,
}) = _Initial;
const factory SpaceEvent.create({
required String name,
required String icon,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class HomeSideBar extends StatelessWidget {
userProfile,
state.currentWorkspace?.workspaceId ??
workspaceSetting.workspaceId,
openFirstPage: false,
),
),
),
Expand Down Expand Up @@ -164,23 +165,27 @@ class HomeSideBar extends StatelessWidget {
if (actionType == UserWorkspaceActionType.create ||
actionType == UserWorkspaceActionType.delete ||
actionType == UserWorkspaceActionType.open) {
context.read<SidebarSectionsBloc>().add(
SidebarSectionsEvent.reload(
userProfile,
state.currentWorkspace?.workspaceId ??
workspaceSetting.workspaceId,
),
);
if (context.read<SpaceBloc>().state.spaces.isEmpty) {
context.read<SidebarSectionsBloc>().add(
SidebarSectionsEvent.reload(
userProfile,
state.currentWorkspace?.workspaceId ??
workspaceSetting.workspaceId,
),
);
} else {
context.read<SpaceBloc>().add(
SpaceEvent.reset(
userProfile,
state.currentWorkspace?.workspaceId ??
workspaceSetting.workspaceId,
),
);
}

context
.read<FavoriteBloc>()
.add(const FavoriteEvent.fetchFavorites());
context.read<SpaceBloc>().add(
SpaceEvent.reset(
userProfile,
state.currentWorkspace?.workspaceId ??
workspaceSetting.workspaceId,
),
);
}
},
),
Expand Down

0 comments on commit aae81ba

Please sign in to comment.