mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: toggle favourites from the documents top bar. (#4382)
* feat: init star button * feat: implemented star button on the right bar * feat: Implemented toggle logic * chore: Added ToolTip for favorite button * refactor: renamed star to favorite * refactor: moved appplication logic into favorite_cubit * chore: arranged imports in alphabetical order * refactor: reused favorite_bloc for toggle * fix: fixed the icon no rebuild * refactor: moved the FavoriteBloc higher in the widget tree * refactor: moved FavoriteBloc inside multiBlocProvider of desktop_home_screen * chore: specified bloc type * chore: cleaned code * refactor: use any instead of map
This commit is contained in:
parent
60fc5bb2c8
commit
747fe40648
@ -8,6 +8,7 @@ import 'package:appflowy/plugins/document/document_page.dart';
|
||||
import 'package:appflowy/plugins/document/presentation/more/cubit/document_appearance_cubit.dart';
|
||||
import 'package:appflowy/plugins/document/presentation/more/more_button.dart';
|
||||
import 'package:appflowy/plugins/document/presentation/share/share_button.dart';
|
||||
import 'package:appflowy/plugins/document/presentation/favorite/favorite_button.dart';
|
||||
import 'package:appflowy/plugins/util.dart';
|
||||
import 'package:appflowy/startup/plugin/plugin.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/home_stack.dart';
|
||||
@ -121,6 +122,11 @@ class DocumentPluginWidgetBuilder extends PluginWidgetBuilder
|
||||
children: [
|
||||
DocumentShareButton(key: ValueKey(view.id), view: view),
|
||||
const HSpace(4),
|
||||
DocumentFavoriteButton(
|
||||
key: ValueKey('favorite_button_${view.id}'),
|
||||
view: view,
|
||||
),
|
||||
const HSpace(4),
|
||||
const DocumentMoreButton(),
|
||||
],
|
||||
);
|
||||
|
@ -0,0 +1,54 @@
|
||||
import 'package:appflowy/generated/flowy_svgs.g.dart';
|
||||
import 'package:appflowy/generated/locale_keys.g.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
||||
import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart';
|
||||
import 'package:easy_localization/easy_localization.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';
|
||||
|
||||
class DocumentFavoriteButton extends StatelessWidget {
|
||||
const DocumentFavoriteButton({
|
||||
super.key,
|
||||
required this.view,
|
||||
});
|
||||
|
||||
final ViewPB view;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<FavoriteBloc, FavoriteState>(
|
||||
builder: (context, state) {
|
||||
final isFavorite = state.views.any((v) => v.id == view.id);
|
||||
return _buildFavoriteButton(context, isFavorite);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFavoriteButton(BuildContext context, bool isFavorite) {
|
||||
return FlowyTooltip(
|
||||
message: isFavorite
|
||||
? LocaleKeys.button_removeFromFavorites.tr()
|
||||
: LocaleKeys.button_addToFavorites.tr(),
|
||||
child: FlowyHover(
|
||||
child: GestureDetector(
|
||||
onTap: () =>
|
||||
context.read<FavoriteBloc>().add(FavoriteEvent.toggle(view)),
|
||||
child: _buildFavoriteIcon(context, isFavorite),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFavoriteIcon(BuildContext context, bool isFavorite) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(6),
|
||||
child: FlowySvg(
|
||||
isFavorite ? FlowySvgs.favorite_s : FlowySvgs.unfavorite_s,
|
||||
size: const Size(18, 18),
|
||||
color: Theme.of(context).iconTheme.color,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@ import 'package:appflowy/workspace/application/view/view_ext.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/errors/workspace_failed_screen.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/hotkeys.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/menu/sidebar/sidebar.dart';
|
||||
import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart';
|
||||
import 'package:appflowy/workspace/presentation/widgets/edit_panel/panel_animation.dart';
|
||||
import 'package:appflowy/workspace/presentation/widgets/float_bubble/question_bubble.dart';
|
||||
import 'package:appflowy_backend/dispatch/dispatch.dart';
|
||||
@ -85,6 +86,10 @@ class DesktopHomeScreen extends StatelessWidget {
|
||||
)..add(const HomeSettingEvent.initial());
|
||||
},
|
||||
),
|
||||
BlocProvider<FavoriteBloc>(
|
||||
create: (context) =>
|
||||
FavoriteBloc()..add(const FavoriteEvent.initial()),
|
||||
),
|
||||
],
|
||||
child: HomeHotKeys(
|
||||
child: Scaffold(
|
||||
|
@ -51,9 +51,6 @@ class HomeSideBar extends StatelessWidget {
|
||||
workspaceId: workspaceSetting.workspaceId,
|
||||
)..add(const MenuEvent.initial()),
|
||||
),
|
||||
BlocProvider(
|
||||
create: (_) => FavoriteBloc()..add(const FavoriteEvent.initial()),
|
||||
),
|
||||
],
|
||||
child: MultiBlocListener(
|
||||
listeners: [
|
||||
|
Loading…
Reference in New Issue
Block a user