Skip to content

Commit

Permalink
fix: unable to get latest workspaces on desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 committed Apr 1, 2024
1 parent 4eb4ff1 commit b6fd7ca
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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<
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>(),
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -228,6 +229,7 @@ class PopoverState extends State<Popover> {
child: _buildClickHandler(
widget.child,
() {
widget.onOpen?.call();
if (widget.triggerActions & PopoverTriggerFlags.click != 0) {
showOverlay();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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),
Expand All @@ -54,6 +55,7 @@ class AppFlowyPopover extends StatelessWidget {
Widget build(BuildContext context) {
return Popover(
controller: controller,
onOpen: onOpen,
onClose: onClose,
canClose: canClose,
direction: direction,
Expand Down

0 comments on commit b6fd7ca

Please sign in to comment.