Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

fix: workspace name update not synced (#8054)

Richard Shiue197cc016ed95
diff --git a/frontend/appflowy_flutter/lib/features/workspace/logic/workspace_bloc.dart b/frontend/appflowy_flutter/lib/features/workspace/logic/workspace_bloc.dart
index 5d5c8358c9..5345bfb1c9 100644
--- a/frontend/appflowy_flutter/lib/features/workspace/logic/workspace_bloc.dart
+++ b/frontend/appflowy_flutter/lib/features/workspace/logic/workspace_bloc.dart
@@ -55,6 +55,9 @@ class UserWorkspaceBloc extends Bloc<UserWorkspaceEvent, UserWorkspaceState> {
on<WorkspaceEventUpdateWorkspaceSubscriptionInfo>(
_onUpdateWorkspaceSubscriptionInfo,
);
+ on<WorkspaceEventEmitWorkspaces>(_onEmitWorkspaces);
+ on<WorkspaceEventEmitUserProfile>(_onEmitUserProfile);
+ on<WorkspaceEventEmitCurrentWorkspace>(_onEmitCurrentWorkspace);
}
final String? initialWorkspaceId;
@@ -72,7 +75,7 @@ class UserWorkspaceBloc extends Bloc<UserWorkspaceEvent, UserWorkspaceState> {
WorkspaceEventInitialize event,
Emitter<UserWorkspaceState> emit,
) async {
- await _setupListeners(emit);
+ await _setupListeners();
await _initializeWorkspaces(emit);
}
@@ -499,34 +502,60 @@ class UserWorkspaceBloc extends Bloc<UserWorkspaceEvent, UserWorkspaceState> {
);
}
- Future<void> _setupListeners(Emitter<UserWorkspaceState> emit) async {
+ Future<void> _onEmitWorkspaces(
+ WorkspaceEventEmitWorkspaces event,
+ Emitter<UserWorkspaceState> emit,
+ ) async {
+ emit(
+ state.copyWith(
+ workspaces: _sortWorkspaces(event.workspaces),
+ ),
+ );
+ }
+
+ Future<void> _onEmitUserProfile(
+ WorkspaceEventEmitUserProfile event,
+ Emitter<UserWorkspaceState> emit,
+ ) async {
+ emit(
+ state.copyWith(userProfile: event.userProfile),
+ );
+ }
+
+ Future<void> _onEmitCurrentWorkspace(
+ WorkspaceEventEmitCurrentWorkspace event,
+ Emitter<UserWorkspaceState> emit,
+ ) async {
+ emit(
+ state.copyWith(currentWorkspace: event.workspace),
+ );
+ }
+
+ Future<void> _setupListeners() async {
_listener.start(
onProfileUpdated: (result) {
- if (!isClosed && !emit.isDone) {
+ if (!isClosed) {
result.fold(
- (newProfile) => emit(
- state.copyWith(userProfile: newProfile),
+ (newProfile) => add(
+ UserWorkspaceEvent.emitUserProfile(userProfile: newProfile),
),
(error) => Log.error("Failed to get user profile: $error"),
);
}
},
onUserWorkspaceListUpdated: (workspaces) {
- if (!isClosed && !emit.isDone) {
- emit(
- state.copyWith(
+ if (!isClosed) {
+ add(
+ UserWorkspaceEvent.emitWorkspaces(
workspaces: _sortWorkspaces(workspaces.items),
),
);
}
},
onUserWorkspaceUpdated: (workspace) {
- if (!isClosed && !emit.isDone) {
- final currentWorkspace = state.currentWorkspace;
- if (currentWorkspace?.workspaceId == workspace.workspaceId) {
- emit(
- state.copyWith(currentWorkspace: workspace),
- );
+ if (!isClosed) {
+ if (state.currentWorkspace?.workspaceId == workspace.workspaceId) {
+ add(UserWorkspaceEvent.emitCurrentWorkspace(workspace: workspace));
}
}
},
diff --git a/frontend/appflowy_flutter/lib/features/workspace/logic/workspace_event.dart b/frontend/appflowy_flutter/lib/features/workspace/logic/workspace_event.dart
index d9be253d56..037a5d4c5d 100644
--- a/frontend/appflowy_flutter/lib/features/workspace/logic/workspace_event.dart
+++ b/frontend/appflowy_flutter/lib/features/workspace/logic/workspace_event.dart
@@ -64,6 +64,21 @@ sealed class UserWorkspaceEvent {
workspaceId: workspaceId,
subscriptionInfo: subscriptionInfo,
);
+
+ factory UserWorkspaceEvent.emitWorkspaces({
+ required List<UserWorkspacePB> workspaces,
+ }) =>
+ WorkspaceEventEmitWorkspaces(workspaces: workspaces);
+
+ factory UserWorkspaceEvent.emitUserProfile({
+ required UserProfilePB userProfile,
+ }) =>
+ WorkspaceEventEmitUserProfile(userProfile: userProfile);
+
+ factory UserWorkspaceEvent.emitCurrentWorkspace({
+ required UserWorkspacePB workspace,
+ }) =>
+ WorkspaceEventEmitCurrentWorkspace(workspace: workspace);
}
/// Initializes the workspace bloc.
@@ -161,3 +176,27 @@ class WorkspaceEventUpdateWorkspaceSubscriptionInfo extends UserWorkspaceEvent {
final String workspaceId;
final WorkspaceSubscriptionInfoPB subscriptionInfo;
}
+
+class WorkspaceEventEmitWorkspaces extends UserWorkspaceEvent {
+ WorkspaceEventEmitWorkspaces({
+ required this.workspaces,
+ });
+
+ final List<UserWorkspacePB> workspaces;
+}
+
+class WorkspaceEventEmitUserProfile extends UserWorkspaceEvent {
+ WorkspaceEventEmitUserProfile({
+ required this.userProfile,
+ });
+
+ final UserProfilePB userProfile;
+}
+
+class WorkspaceEventEmitCurrentWorkspace extends UserWorkspaceEvent {
+ WorkspaceEventEmitCurrentWorkspace({
+ required this.workspace,
+ });
+
+ final UserWorkspacePB workspace;
+}