mirror of
https://github.com/immich-app/immich.git
synced 2026-04-28 03:50:37 -04:00
* set album cover from asset * add to correct kebab group * add to album selection * add to legacy control bottom bar * add tests * format * analyze * Revert "add to legacy control bottom bar" This reverts commit 9d68e12a08d04e6c2888bbe223ff7b4436509930. * remove unnecessary event emission * lint * fix tests * fix: button order and remove unncessary check --------- Co-authored-by: Alex <alex.tran1502@gmail.com>
57 lines
1.8 KiB
Dart
57 lines
1.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:immich_mobile/constants/enums.dart';
|
|
import 'package:immich_mobile/extensions/translate_extensions.dart';
|
|
import 'package:immich_mobile/presentation/widgets/action_buttons/base_action_button.widget.dart';
|
|
import 'package:immich_mobile/providers/infrastructure/action.provider.dart';
|
|
import 'package:immich_mobile/providers/timeline/multiselect.provider.dart';
|
|
import 'package:immich_mobile/widgets/common/immich_toast.dart';
|
|
|
|
class SetAlbumCoverActionButton extends ConsumerWidget {
|
|
final String albumId;
|
|
final ActionSource source;
|
|
final bool iconOnly;
|
|
final bool menuItem;
|
|
|
|
const SetAlbumCoverActionButton({
|
|
super.key,
|
|
required this.albumId,
|
|
required this.source,
|
|
this.iconOnly = false,
|
|
this.menuItem = false,
|
|
});
|
|
|
|
void _onTap(BuildContext context, WidgetRef ref) async {
|
|
if (!context.mounted) {
|
|
return;
|
|
}
|
|
|
|
final result = await ref.read(actionProvider.notifier).setAlbumCover(source, albumId);
|
|
ref.read(multiSelectProvider.notifier).reset();
|
|
|
|
final successMessage = 'album_cover_updated'.t(context: context);
|
|
|
|
if (context.mounted) {
|
|
ImmichToast.show(
|
|
context: context,
|
|
msg: result.success ? successMessage : 'scaffold_body_error_occurred'.t(context: context),
|
|
gravity: ToastGravity.BOTTOM,
|
|
toastType: result.success ? ToastType.success : ToastType.error,
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
return BaseActionButton(
|
|
iconData: Icons.image_outlined,
|
|
label: 'set_as_album_cover'.t(context: context),
|
|
iconOnly: iconOnly,
|
|
menuItem: menuItem,
|
|
onPressed: () => _onTap(context, ref),
|
|
maxWidth: 100,
|
|
);
|
|
}
|
|
}
|