fix: remove the deleted workspace from local storage (#5026)

* fix: remove the deleted workspace from local storage

* fix: unable to get latest workspaces on mobile

* fix: unable to get latest workspaces on desktop

* chore: try to fix ios ci

* fix: user workspace menu flash

* Revert "chore: try to fix ios ci"

This reverts commit 4a1e8bcb9d.
This commit is contained in:
Lucas.Xu
2024-04-02 11:28:05 +08:00
committed by GitHub
parent 1816b15b55
commit 096a01ed44
9 changed files with 191 additions and 109 deletions

View File

@ -3,6 +3,7 @@ import 'package:appflowy/core/config/kv_keys.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/shared/feature_flags.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/user/application/user_listener.dart';
import 'package:appflowy/user/application/user_service.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-error/code.pbenum.dart';
@ -22,11 +23,18 @@ class UserWorkspaceBloc extends Bloc<UserWorkspaceEvent, UserWorkspaceState> {
UserWorkspaceBloc({
required this.userProfile,
}) : _userService = UserBackendService(userId: userProfile.id),
_listener = UserListener(userProfile: userProfile),
super(UserWorkspaceState.initial()) {
on<UserWorkspaceEvent>(
(event, emit) async {
await event.when(
initial: () async {
_listener
..didUpdateUserWorkspaces = (workspaces) {
add(UserWorkspaceEvent.updateWorkspaces(workspaces));
}
..start();
final result = await _fetchWorkspaces();
final isCollabWorkspaceOn =
userProfile.authenticator != AuthenticatorPB.Local &&
@ -237,13 +245,27 @@ class UserWorkspaceBloc extends Bloc<UserWorkspaceEvent, UserWorkspaceState> {
),
);
},
updateWorkspaces: (workspaces) async {
emit(
state.copyWith(
workspaces: workspaces.items,
),
);
},
);
},
);
}
@override
Future<void> close() {
_listener.stop();
return super.close();
}
final UserProfilePB userProfile;
final UserBackendService _userService;
final UserListener _listener;
Future<
(
@ -270,7 +292,10 @@ class UserWorkspaceBloc extends Bloc<UserWorkspaceEvent, UserWorkspaceState> {
currentWorkspaceInList ??= workspaces.first;
return (
currentWorkspaceInList,
workspaces,
workspaces
..sort(
(a, b) => a.createdAtTimestamp.compareTo(b.createdAtTimestamp),
),
lastOpenedWorkspaceId != currentWorkspace.id
);
} catch (e) {
@ -300,6 +325,9 @@ class UserWorkspaceEvent with _$UserWorkspaceEvent {
) = _UpdateWorkspaceIcon;
const factory UserWorkspaceEvent.leaveWorkspace(String workspaceId) =
LeaveWorkspace;
const factory UserWorkspaceEvent.updateWorkspaces(
RepeatedUserWorkspacePB workspaces,
) = UpdateWorkspaces;
}
enum UserWorkspaceActionType {
@ -339,13 +367,16 @@ class UserWorkspaceState with _$UserWorkspaceState {
@override
int get hashCode => runtimeType.hashCode;
final DeepCollectionEquality _deepCollectionEquality =
const DeepCollectionEquality();
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is UserWorkspaceState &&
other.currentWorkspace == currentWorkspace &&
other.workspaces == workspaces &&
_deepCollectionEquality.equals(other.workspaces, workspaces) &&
identical(other.actionResult, actionResult);
}
}