From 89669e4ffbf0740ae1d16b6de24132b0e4c25688 Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Mon, 17 Jun 2024 18:28:23 +0800 Subject: [PATCH] feat: support collapsing space and switching space by shortcuts --- .../application/sidebar/space/space_bloc.dart | 4 +- .../menu/sidebar/space/sidebar_space.dart | 19 ++++--- .../sidebar/space/sidebar_space_header.dart | 57 +++++++++++++------ 3 files changed, 54 insertions(+), 26 deletions(-) diff --git a/frontend/appflowy_flutter/lib/workspace/application/sidebar/space/space_bloc.dart b/frontend/appflowy_flutter/lib/workspace/application/sidebar/space/space_bloc.dart index 193c73f131960..53c4a4038ab32 100644 --- a/frontend/appflowy_flutter/lib/workspace/application/sidebar/space/space_bloc.dart +++ b/frontend/appflowy_flutter/lib/workspace/application/sidebar/space/space_bloc.dart @@ -84,7 +84,9 @@ class SpaceBloc extends Bloc { ); if (shouldShowUpgradeDialog) { - add(const SpaceEvent.migrate()); + if (!integrationMode().isTest) { + add(const SpaceEvent.migrate()); + } } if (openFirstPage) { diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/sidebar_space.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/sidebar_space.dart index 890ae8e0def35..e5fe8d2596334 100644 --- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/sidebar_space.dart +++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/sidebar_space.dart @@ -111,16 +111,17 @@ class _SpaceState extends State<_Space> { onCreateNewSpace: () => _showCreateSpaceDialog(context), onCollapseAllPages: () => isExpandedNotifier.value = true, ), - MouseRegion( - onEnter: (_) => isHovered.value = true, - onExit: (_) => isHovered.value = false, - child: _Pages( - key: ValueKey(currentSpace.id), - isExpandedNotifier: isExpandedNotifier, - space: currentSpace, - isHovered: isHovered, + if (state.isExpanded) + MouseRegion( + onEnter: (_) => isHovered.value = true, + onExit: (_) => isHovered.value = false, + child: _Pages( + key: ValueKey(currentSpace.id), + isExpandedNotifier: isExpandedNotifier, + space: currentSpace, + isHovered: isHovered, + ), ), - ), ], ); }, diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/sidebar_space_header.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/sidebar_space_header.dart index 5a672c61c438e..6c277736cc513 100644 --- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/sidebar_space_header.dart +++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/sidebar_space_header.dart @@ -16,6 +16,7 @@ import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart'; import 'package:appflowy_popover/appflowy_popover.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flowy_infra_ui/flowy_infra_ui.dart'; +import 'package:flowy_infra_ui/style_widget/hover.dart'; import 'package:flowy_infra_ui/widget/flowy_tooltip.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -53,15 +54,8 @@ class _SidebarSpaceHeaderState extends State { @override Widget build(BuildContext context) { - return AppFlowyPopover( - constraints: const BoxConstraints(maxWidth: 252), - direction: PopoverDirection.bottomWithLeftAligned, - clickHandler: PopoverClickHandler.gestureDetector, - offset: const Offset(0, 4), - popupBuilder: (_) => BlocProvider.value( - value: context.read(), - child: const SidebarSpaceMenu(), - ), + return ValueListenableBuilder( + valueListenable: isHovered, child: SizedBox( height: HomeSizes.workspaceSectionHeight, child: MouseRegion( @@ -70,13 +64,28 @@ class _SidebarSpaceHeaderState extends State { child: Stack( alignment: Alignment.center, children: [ - SizedBox( - height: HomeSizes.workspaceSectionHeight, - child: FlowyButton( - margin: const EdgeInsets.only(left: 6.0, right: 4.0), - iconPadding: 10.0, - text: _buildChild(), - rightIcon: const HSpace(60.0), + Positioned( + left: 3, + top: 3, + bottom: 3, + child: SizedBox( + height: HomeSizes.workspaceSectionHeight, + child: AppFlowyPopover( + constraints: const BoxConstraints(maxWidth: 252), + direction: PopoverDirection.bottomWithLeftAligned, + clickHandler: PopoverClickHandler.gestureDetector, + offset: const Offset(0, 4), + popupBuilder: (_) => BlocProvider.value( + value: context.read(), + child: const SidebarSpaceMenu(), + ), + child: FlowyButton( + useIntrinsicWidth: true, + margin: const EdgeInsets.only(left: 3.0, right: 4.0), + iconPadding: 10.0, + text: _buildChild(), + ), + ), ), ), Positioned( @@ -87,6 +96,22 @@ class _SidebarSpaceHeaderState extends State { ), ), ), + builder: (context, isHovered, child) { + final style = HoverStyle( + hoverColor: isHovered + ? Theme.of(context).colorScheme.secondary + : Colors.transparent, + ); + return GestureDetector( + onTap: () => context + .read() + .add(SpaceEvent.expand(widget.space, !widget.isExpanded)), + child: FlowyHoverContainer( + style: style, + child: child!, + ), + ); + }, ); }