Skip to content

Commit

Permalink
feat: add a pinned icon after page name
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 committed Jun 17, 2024
1 parent 1fd34bc commit 9bb8b5a
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/workspace/application/sidebar/folder/folder_bloc.dart';
import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/favorites/favorite_menu_bloc.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/favorites/favorite_more_actions.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/favorites/favorite_pin_action.dart';
Expand Down Expand Up @@ -52,16 +53,76 @@ class FavoriteMenu extends StatelessWidget {
},
),
const VSpace(12),
_buildViews(context, state),
_FavoriteGroups(
minWidth: minWidth,
),
],
);
},
),
),
);
}
}

class _FavoriteGroupedViews extends StatelessWidget {
const _FavoriteGroupedViews({
required this.views,
});

final List<ViewPB> views;

@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: views
.map(
(e) => ViewItem(
key: ValueKey(e.id),
view: e,
spaceType: FolderSpaceType.favorite,
level: 0,
onSelected: (_, view) {
context.read<TabsBloc>().openPlugin(view);
PopoverContainer.maybeOf(context)?.close();
},
isFeedback: false,
isDraggable: false,
shouldRenderChildren: false,
extendBuilder: (view) => view.isPinned
? [
const HSpace(4.0),
const FlowySvg(
FlowySvgs.favorite_pin_s,
blendMode: null,
),
]
: [],
leftIconBuilder: (_, __) => const HSpace(4.0),
rightIconsBuilder: (_, view) => [
FavoriteMoreActions(view: view),
const HSpace(6.0),
FavoritePinAction(view: view),
const HSpace(4.0),
],
),
)
.toList(),
);
}
}

class _FavoriteGroups extends StatelessWidget {
const _FavoriteGroups({
required this.minWidth,
});

final double minWidth;

Widget _buildViews(BuildContext context, FavoriteMenuState state) {
@override
Widget build(BuildContext context) {
final state = context.read<FavoriteMenuBloc>().state;
final today = _buildGroups(
context,
state.todayViews,
Expand Down Expand Up @@ -131,41 +192,11 @@ class FavoriteMenu extends StatelessWidget {
),
),
const VSpace(2),
_buildGroupedViews(context, views),
_FavoriteGroupedViews(views: views),
const VSpace(8),
],
];
}

Widget _buildGroupedViews(BuildContext context, List<ViewPB> views) {
return Column(
mainAxisSize: MainAxisSize.min,
children: views
.map(
(e) => ViewItem(
key: ValueKey(e.id),
view: e,
spaceType: FolderSpaceType.favorite,
level: 0,
onSelected: (_, view) {
context.read<TabsBloc>().openPlugin(view);
PopoverContainer.maybeOf(context)?.close();
},
isFeedback: false,
isDraggable: false,
shouldRenderChildren: false,
leftIconBuilder: (_, __) => const HSpace(4.0),
rightIconsBuilder: (_, view) => [
FavoriteMoreActions(view: view),
const HSpace(6.0),
FavoritePinAction(view: view),
const HSpace(4.0),
],
),
)
.toList(),
);
}
}

class _FavoriteSearchField extends StatefulWidget {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class ViewItem extends StatelessWidget {
this.rightIconsBuilder,
this.shouldLoadChildViews = true,
this.isExpandedNotifier,
this.extendBuilder,
});

final ViewPB view;
Expand Down Expand Up @@ -113,6 +114,8 @@ class ViewItem extends StatelessWidget {
final bool shouldLoadChildViews;
final PropertyValueNotifier<bool>? isExpandedNotifier;

final List<Widget> Function(ViewPB view)? extendBuilder;

@override
Widget build(BuildContext context) {
return BlocProvider(
Expand Down Expand Up @@ -148,6 +151,7 @@ class ViewItem extends StatelessWidget {
leftIconBuilder: leftIconBuilder,
rightIconsBuilder: rightIconsBuilder,
isExpandedNotifier: isExpandedNotifier,
extendBuilder: extendBuilder,
);
},
),
Expand Down Expand Up @@ -181,6 +185,7 @@ class InnerViewItem extends StatefulWidget {
required this.leftIconBuilder,
required this.rightIconsBuilder,
this.isExpandedNotifier,
required this.extendBuilder,
});

final ViewPB view;
Expand Down Expand Up @@ -210,6 +215,7 @@ class InnerViewItem extends StatefulWidget {
final ViewItemRightIconsBuilder? rightIconsBuilder;

final PropertyValueNotifier<bool>? isExpandedNotifier;
final List<Widget> Function(ViewPB view)? extendBuilder;

@override
State<InnerViewItem> createState() => _InnerViewItemState();
Expand Down Expand Up @@ -247,6 +253,7 @@ class _InnerViewItemState extends State<InnerViewItem> {
isHovered: widget.isHovered,
leftIconBuilder: widget.leftIconBuilder,
rightIconsBuilder: widget.rightIconsBuilder,
extendBuilder: widget.extendBuilder,
);

// if the view is expanded and has child views, render its child views
Expand All @@ -270,6 +277,7 @@ class _InnerViewItemState extends State<InnerViewItem> {
isHovered: widget.isHovered,
leftIconBuilder: widget.leftIconBuilder,
rightIconsBuilder: widget.rightIconsBuilder,
extendBuilder: widget.extendBuilder,
);
}).toList();

Expand Down Expand Up @@ -315,6 +323,7 @@ class _InnerViewItemState extends State<InnerViewItem> {
isFeedback: true,
leftIconBuilder: widget.leftIconBuilder,
rightIconsBuilder: widget.rightIconsBuilder,
extendBuilder: widget.extendBuilder,
),
);
},
Expand Down Expand Up @@ -389,6 +398,7 @@ class SingleInnerViewItem extends StatefulWidget {
this.isHovered,
required this.leftIconBuilder,
required this.rightIconsBuilder,
required this.extendBuilder,
});

final ViewPB view;
Expand All @@ -413,6 +423,8 @@ class SingleInnerViewItem extends StatefulWidget {
final ViewItemLeftIconBuilder? leftIconBuilder;
final ViewItemRightIconsBuilder? rightIconsBuilder;

final List<Widget> Function(ViewPB view)? extendBuilder;

@override
State<SingleInnerViewItem> createState() => _SingleInnerViewItemState();
}
Expand Down Expand Up @@ -463,9 +475,15 @@ class _SingleInnerViewItemState extends State<SingleInnerViewItem> {
const HSpace(6),
// title
Expanded(
child: FlowyText.regular(
widget.view.name,
overflow: TextOverflow.ellipsis,
child: Row(
children: [
FlowyText.regular(
widget.view.name,
overflow: TextOverflow.ellipsis,
),
if (widget.extendBuilder != null)
...widget.extendBuilder!(widget.view),
],
),
),
];
Expand Down
3 changes: 3 additions & 0 deletions frontend/resources/flowy_icons/16x/favorite_pin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9bb8b5a

Please sign in to comment.