mirror of
https://github.com/immich-app/immich.git
synced 2026-07-04 03:45:59 -07:00
cb1af3a8ec
* chore: cleanup partner action test * feat: favorite bottom sheet action * review suggestions * implicit favorite handling * feat: viewer favorite icon to action (#29321) * feat: viewer favorite icon to action * feat: advance info action * implicit favorite handling * feat: viewer favorite icon to action # Conflicts: # mobile/lib/presentation/widgets/asset_viewer/viewer_top_app_bar.widget.dart --------- Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com> * chore: timeline action test (#29324) Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com> * clear selection only on success --------- Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
41 lines
1.6 KiB
Dart
41 lines
1.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:immich_mobile/domain/models/asset/base_asset.model.dart';
|
|
import 'package:immich_mobile/generated/translations.g.dart';
|
|
import 'package:immich_mobile/presentation/actions/action.dart';
|
|
import 'package:immich_mobile/providers/infrastructure/asset.provider.dart';
|
|
import 'package:immich_ui/immich_ui.dart';
|
|
|
|
class FavoriteAction extends AssetAction<RemoteAsset> {
|
|
final bool shouldFavorite;
|
|
|
|
FavoriteAction({required super.assets}) : shouldFavorite = assets.any((asset) => !asset.isFavorite);
|
|
|
|
@override
|
|
IconData get icon => shouldFavorite ? Icons.favorite_border_rounded : Icons.favorite_rounded;
|
|
|
|
@override
|
|
String label(ActionScope scope) => shouldFavorite ? scope.context.t.favorite : scope.context.t.unfavorite;
|
|
|
|
@override
|
|
Iterable<RemoteAsset> filter(ActionScope scope) => assets
|
|
.where(
|
|
(asset) => asset is RemoteAsset && asset.ownerId == scope.authUser.id && asset.isFavorite == !shouldFavorite,
|
|
)
|
|
.cast<RemoteAsset>();
|
|
|
|
@override
|
|
bool isVisible(ActionScope scope) => filter(scope).isNotEmpty;
|
|
|
|
@override
|
|
Future<void> onAction(ActionScope scope) async {
|
|
final ActionScope(:ref) = scope;
|
|
final assets = filter(scope).map((asset) => asset.id).toList(growable: false);
|
|
|
|
await ref.read(assetServiceProvider).updateFavorite(assets, shouldFavorite);
|
|
final message = shouldFavorite
|
|
? StaticTranslations.instance.favorite_action_prompt(count: assets.length)
|
|
: StaticTranslations.instance.unfavorite_action_prompt(count: assets.length);
|
|
snackbar.success(message);
|
|
}
|
|
}
|