From b6fd7ca4f9700421f6ab47761d84870cbe6e0a81 Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Mon, 1 Apr 2024 21:40:15 +0800 Subject: [PATCH] fix: unable to get latest workspaces on desktop --- .../application/user/user_workspace_bloc.dart | 18 ++++++++++++++++-- .../home/menu/sidebar/sidebar_workspace.dart | 5 +++++ .../appflowy_popover/lib/src/popover.dart | 8 +++++--- .../src/flowy_overlay/appflowy_popover.dart | 8 +++++--- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/frontend/appflowy_flutter/lib/workspace/application/user/user_workspace_bloc.dart b/frontend/appflowy_flutter/lib/workspace/application/user/user_workspace_bloc.dart index 1eec72fd21..f34f33f387 100644 --- a/frontend/appflowy_flutter/lib/workspace/application/user/user_workspace_bloc.dart +++ b/frontend/appflowy_flutter/lib/workspace/application/user/user_workspace_bloc.dart @@ -55,6 +55,16 @@ class UserWorkspaceBloc extends Bloc { fetchWorkspaces: () async { final result = await _fetchWorkspaces(); if (result != null) { + final currentWorkspace = result.$1; + final workspaces = result.$2; + // the equal function has been overridden. + if (_deepCollectionEquality.equals( + workspaces, + state.workspaces, + ) && + currentWorkspace == state.currentWorkspace) { + return; + } emit( state.copyWith( currentWorkspace: result.$1, @@ -255,8 +265,10 @@ class UserWorkspaceBloc extends Bloc { ); }, updateWorkspaces: (workspaces) async { - if (!const DeepCollectionEquality() - .equals(workspaces.items, state.workspaces)) { + if (!_deepCollectionEquality.equals( + workspaces.items, + state.workspaces, + )) { emit( state.copyWith( workspaces: workspaces.items, @@ -278,6 +290,8 @@ class UserWorkspaceBloc extends Bloc { final UserProfilePB userProfile; final UserBackendService _userService; final UserListener _listener; + final DeepCollectionEquality _deepCollectionEquality = + const DeepCollectionEquality(); Future< ( diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/sidebar_workspace.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/sidebar_workspace.dart index a3524110c5..8161b2ed7a 100644 --- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/sidebar_workspace.dart +++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/sidebar_workspace.dart @@ -148,6 +148,11 @@ class _SidebarSwitchWorkspaceButtonState direction: PopoverDirection.bottomWithCenterAligned, offset: const Offset(0, 10), constraints: const BoxConstraints(maxWidth: 260, maxHeight: 600), + onOpen: () { + context.read().add( + const UserWorkspaceEvent.fetchWorkspaces(), + ); + }, popupBuilder: (_) { return BlocProvider.value( value: context.read(), diff --git a/frontend/appflowy_flutter/packages/appflowy_popover/lib/src/popover.dart b/frontend/appflowy_flutter/packages/appflowy_popover/lib/src/popover.dart index 17eefc44f0..378f29d3a1 100644 --- a/frontend/appflowy_flutter/packages/appflowy_popover/lib/src/popover.dart +++ b/frontend/appflowy_flutter/packages/appflowy_popover/lib/src/popover.dart @@ -1,8 +1,7 @@ +import 'package:appflowy_popover/src/layout.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:appflowy_popover/src/layout.dart'; - import 'mask.dart'; import 'mutex.dart'; @@ -79,7 +78,8 @@ class Popover extends StatefulWidget { /// The direction of the popover final PopoverDirection direction; - final void Function()? onClose; + final VoidCallback? onOpen; + final VoidCallback? onClose; final Future Function()? canClose; final bool asBarrier; @@ -109,6 +109,7 @@ class Popover extends StatefulWidget { this.direction = PopoverDirection.rightWithTopAligned, this.mutex, this.windowPadding, + this.onOpen, this.onClose, this.canClose, this.asBarrier = false, @@ -228,6 +229,7 @@ class PopoverState extends State { child: _buildClickHandler( widget.child, () { + widget.onOpen?.call(); if (widget.triggerActions & PopoverTriggerFlags.click != 0) { showOverlay(); } diff --git a/frontend/appflowy_flutter/packages/flowy_infra_ui/lib/src/flowy_overlay/appflowy_popover.dart b/frontend/appflowy_flutter/packages/flowy_infra_ui/lib/src/flowy_overlay/appflowy_popover.dart index 0a3ff0a119..3014d393dd 100644 --- a/frontend/appflowy_flutter/packages/flowy_infra_ui/lib/src/flowy_overlay/appflowy_popover.dart +++ b/frontend/appflowy_flutter/packages/flowy_infra_ui/lib/src/flowy_overlay/appflowy_popover.dart @@ -1,7 +1,6 @@ -import 'package:flutter/material.dart'; - import 'package:appflowy_popover/appflowy_popover.dart'; import 'package:flowy_infra_ui/style_widget/decoration.dart'; +import 'package:flutter/material.dart'; class AppFlowyPopover extends StatelessWidget { final Widget child; @@ -10,7 +9,8 @@ class AppFlowyPopover extends StatelessWidget { final PopoverDirection direction; final int triggerActions; final BoxConstraints constraints; - final void Function()? onClose; + final VoidCallback? onOpen; + final VoidCallback? onClose; final Future Function()? canClose; final PopoverMutex? mutex; final Offset? offset; @@ -35,6 +35,7 @@ class AppFlowyPopover extends StatelessWidget { required this.child, required this.popupBuilder, this.direction = PopoverDirection.rightWithTopAligned, + this.onOpen, this.onClose, this.canClose, this.constraints = const BoxConstraints(maxWidth: 240, maxHeight: 600), @@ -54,6 +55,7 @@ class AppFlowyPopover extends StatelessWidget { Widget build(BuildContext context) { return Popover( controller: controller, + onOpen: onOpen, onClose: onClose, canClose: canClose, direction: direction,