forked from AppFlowy-IO/AppFlowy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: toggle favourites from the documents top bar. (AppFlowy-IO#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
- Loading branch information
1 parent
60fc5bb
commit 747fe40
Showing
4 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
frontend/appflowy_flutter/lib/plugins/document/presentation/favorite/favorite_button.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters