diff --git a/mobile/lib/presentation/widgets/action_buttons/archive_action_button.widget.dart b/mobile/lib/presentation/widgets/action_buttons/archive_action_button.widget.dart index 5ec88231ca..d1d0695a99 100644 --- a/mobile/lib/presentation/widgets/action_buttons/archive_action_button.widget.dart +++ b/mobile/lib/presentation/widgets/action_buttons/archive_action_button.widget.dart @@ -40,10 +40,6 @@ class ArchiveActionButton extends ConsumerWidget { } } - void viewerAction(WidgetRef _) { - UnimplementedError("Viewer action for archive is not implemented yet."); - } - @override Widget build(BuildContext context, WidgetRef ref) { return BaseActionButton( diff --git a/mobile/lib/presentation/widgets/action_buttons/favorite_action_button.widget.dart b/mobile/lib/presentation/widgets/action_buttons/favorite_action_button.widget.dart index dbe43d2f17..50d13e6b4e 100644 --- a/mobile/lib/presentation/widgets/action_buttons/favorite_action_button.widget.dart +++ b/mobile/lib/presentation/widgets/action_buttons/favorite_action_button.widget.dart @@ -40,10 +40,6 @@ class FavoriteActionButton extends ConsumerWidget { } } - void viewerAction(WidgetRef _) { - UnimplementedError("Viewer action for favorite is not implemented yet."); - } - @override Widget build(BuildContext context, WidgetRef ref) { return BaseActionButton( diff --git a/mobile/lib/presentation/widgets/action_buttons/move_to_lock_folder_action_button.widget.dart b/mobile/lib/presentation/widgets/action_buttons/move_to_lock_folder_action_button.widget.dart index b150c13359..503dd34403 100644 --- a/mobile/lib/presentation/widgets/action_buttons/move_to_lock_folder_action_button.widget.dart +++ b/mobile/lib/presentation/widgets/action_buttons/move_to_lock_folder_action_button.widget.dart @@ -41,12 +41,6 @@ class MoveToLockFolderActionButton extends ConsumerWidget { } } - void viewerAction(WidgetRef _) { - UnimplementedError( - "Viewer action for move to locked folder is not implemented yet.", - ); - } - @override Widget build(BuildContext context, WidgetRef ref) { return BaseActionButton( diff --git a/mobile/lib/presentation/widgets/action_buttons/remove_from_lock_folder_action_button.widget.dart b/mobile/lib/presentation/widgets/action_buttons/remove_from_lock_folder_action_button.widget.dart index e17f655f01..32857f300e 100644 --- a/mobile/lib/presentation/widgets/action_buttons/remove_from_lock_folder_action_button.widget.dart +++ b/mobile/lib/presentation/widgets/action_buttons/remove_from_lock_folder_action_button.widget.dart @@ -41,12 +41,6 @@ class RemoveFromLockFolderActionButton extends ConsumerWidget { } } - void viewerAction(WidgetRef _) { - UnimplementedError( - "Viewer action for remove from locked folder is not implemented yet.", - ); - } - @override Widget build(BuildContext context, WidgetRef ref) { return BaseActionButton( diff --git a/mobile/lib/presentation/widgets/action_buttons/share_link_action_button.widget.dart b/mobile/lib/presentation/widgets/action_buttons/share_link_action_button.widget.dart index 8b82b1c54e..d23dd377c4 100644 --- a/mobile/lib/presentation/widgets/action_buttons/share_link_action_button.widget.dart +++ b/mobile/lib/presentation/widgets/action_buttons/share_link_action_button.widget.dart @@ -1,44 +1,42 @@ -import 'package:auto_route/auto_route.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/domain/models/asset/base_asset.model.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/routing/router.dart'; +import 'package:immich_mobile/widgets/common/immich_toast.dart'; class ShareLinkActionButton extends ConsumerWidget { final ActionSource source; const ShareLinkActionButton({super.key, required this.source}); - onAction(BuildContext context, WidgetRef ref) { - switch (source) { - case ActionSource.timeline: - timelineAction(context, ref); - case ActionSource.viewer: - viewerAction(ref); + _onTap(BuildContext context, WidgetRef ref) async { + if (!context.mounted) { + return; } - } - void timelineAction(BuildContext context, WidgetRef ref) { - final ids = ref - .read(multiSelectProvider.select((value) => value.selectedAssets)) - .whereType() - .toList() - .map((asset) => asset.id) - .toList(); + final result = + await ref.read(actionProvider.notifier).shareLink(source, context); + ref.read(multiSelectProvider.notifier).reset(); - context.pushRoute( - SharedLinkEditRoute( - assetsList: ids, - ), + final successMessage = 'share_link_action_prompt'.t( + context: context, + args: {'count': result.count.toString()}, ); - } - void viewerAction(WidgetRef _) { - UnimplementedError("Viewer action for favorite is not implemented yet."); + 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 @@ -46,7 +44,7 @@ class ShareLinkActionButton extends ConsumerWidget { return BaseActionButton( iconData: Icons.link_rounded, label: "share_link".t(context: context), - onPressed: () => onAction(context, ref), + onPressed: () => _onTap(context, ref), ); } } diff --git a/mobile/lib/providers/infrastructure/action.provider.dart b/mobile/lib/providers/infrastructure/action.provider.dart index 6b4c675929..e18a2aeb1b 100644 --- a/mobile/lib/providers/infrastructure/action.provider.dart +++ b/mobile/lib/providers/infrastructure/action.provider.dart @@ -1,3 +1,4 @@ +import 'package:flutter/material.dart'; import 'package:immich_mobile/constants/enums.dart'; import 'package:immich_mobile/domain/models/asset/base_asset.model.dart'; import 'package:immich_mobile/providers/infrastructure/timeline.provider.dart'; @@ -66,6 +67,24 @@ class ActionNotifier extends Notifier { }; } + Future shareLink( + ActionSource source, + BuildContext context, + ) async { + final ids = _getIdsForSource(source); + try { + await _service.shareLink(ids, context); + return ActionResult(count: ids.length, success: true); + } catch (error, stack) { + _logger.severe('Failed to create shared link for assets', error, stack); + return ActionResult( + count: ids.length, + success: false, + error: error.toString(), + ); + } + } + Future favorite(ActionSource source) async { final ids = _getIdsForSource(source); try { @@ -127,7 +146,7 @@ class ActionNotifier extends Notifier { } Future moveToLockFolder(ActionSource source) async { - final ids = _getIdsForSource(source); + final ids = _getIdsForSource(source); try { await _service.moveToLockFolder(ids); return ActionResult(count: ids.length, success: true); @@ -142,7 +161,7 @@ class ActionNotifier extends Notifier { } Future removeFromLockFolder(ActionSource source) async { - final ids = _getIdsForSource(source); + final ids = _getIdsForSource(source); try { await _service.removeFromLockFolder(ids); return ActionResult(count: ids.length, success: true); diff --git a/mobile/lib/services/action.service.dart b/mobile/lib/services/action.service.dart index 3b7c04ea94..df059405ed 100644 --- a/mobile/lib/services/action.service.dart +++ b/mobile/lib/services/action.service.dart @@ -1,7 +1,10 @@ +import 'package:auto_route/auto_route.dart'; +import 'package:flutter/material.dart'; import 'package:immich_mobile/constants/enums.dart'; import 'package:immich_mobile/domain/models/asset/base_asset.model.dart'; import 'package:immich_mobile/infrastructure/repositories/remote_asset.repository.dart'; import 'package:immich_mobile/repositories/asset_api.repository.dart'; +import 'package:immich_mobile/routing/router.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; final actionServiceProvider = Provider( @@ -17,6 +20,14 @@ class ActionService { const ActionService(this._assetApiRepository, this._remoteAssetRepository); + Future shareLink(List remoteIds, BuildContext context) async { + context.pushRoute( + SharedLinkEditRoute( + assetsList: remoteIds, + ), + ); + } + Future favorite(List remoteIds) async { await _assetApiRepository.updateFavorite(remoteIds, true); await _remoteAssetRepository.updateFavorite(remoteIds, true);