fix: unable to get latest workspaces on desktop

This commit is contained in:
Lucas.Xu 2024-04-01 21:40:15 +08:00
parent 4eb4ff1a32
commit b6fd7ca4f9
4 changed files with 31 additions and 8 deletions

View File

@ -55,6 +55,16 @@ class UserWorkspaceBloc extends Bloc<UserWorkspaceEvent, UserWorkspaceState> {
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<UserWorkspaceEvent, UserWorkspaceState> {
);
},
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<UserWorkspaceEvent, UserWorkspaceState> {
final UserProfilePB userProfile;
final UserBackendService _userService;
final UserListener _listener;
final DeepCollectionEquality _deepCollectionEquality =
const DeepCollectionEquality();
Future<
(

View File

@ -148,6 +148,11 @@ class _SidebarSwitchWorkspaceButtonState
direction: PopoverDirection.bottomWithCenterAligned,
offset: const Offset(0, 10),
constraints: const BoxConstraints(maxWidth: 260, maxHeight: 600),
onOpen: () {
context.read<UserWorkspaceBloc>().add(
const UserWorkspaceEvent.fetchWorkspaces(),
);
},
popupBuilder: (_) {
return BlocProvider<UserWorkspaceBloc>.value(
value: context.read<UserWorkspaceBloc>(),

View File

@ -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<bool> 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<Popover> {
child: _buildClickHandler(
widget.child,
() {
widget.onOpen?.call();
if (widget.triggerActions & PopoverTriggerFlags.click != 0) {
showOverlay();
}

View File

@ -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<bool> 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,