2024-01-05 05:20:55 +00:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2022-07-07 20:40:54 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-04-23 21:08:45 -05:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2025-03-12 19:26:56 +05:30
|
|
|
import 'package:immich_mobile/domain/models/user.model.dart';
|
|
|
|
|
import 'package:immich_mobile/entities/asset.entity.dart';
|
2023-11-29 04:17:29 +00:00
|
|
|
import 'package:immich_mobile/extensions/asyncvalue_extensions.dart';
|
2023-11-09 16:19:53 +00:00
|
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
2024-10-10 15:44:14 +07:00
|
|
|
import 'package:immich_mobile/providers/album/album.provider.dart';
|
2024-05-02 15:59:14 -05:00
|
|
|
import 'package:immich_mobile/providers/album/album_title.provider.dart';
|
|
|
|
|
import 'package:immich_mobile/providers/album/suggested_shared_users.provider.dart';
|
2022-04-23 21:08:45 -05:00
|
|
|
import 'package:immich_mobile/routing/router.dart';
|
2024-05-06 23:04:21 -05:00
|
|
|
import 'package:immich_mobile/widgets/common/user_circle_avatar.dart';
|
2022-04-23 21:08:45 -05:00
|
|
|
|
2024-08-06 12:50:20 -05:00
|
|
|
@RoutePage()
|
2024-05-05 13:14:49 -05:00
|
|
|
class AlbumSharedUserSelectionPage extends HookConsumerWidget {
|
|
|
|
|
const AlbumSharedUserSelectionPage({super.key, required this.assets});
|
2023-05-17 19:36:02 +02:00
|
|
|
|
|
|
|
|
final Set<Asset> assets;
|
2022-07-13 07:23:48 -05:00
|
|
|
|
2022-04-23 21:08:45 -05:00
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2025-03-12 19:26:56 +05:30
|
|
|
final sharedUsersList = useState<Set<UserDto>>({});
|
2023-05-25 05:52:43 +02:00
|
|
|
final suggestedShareUsers = ref.watch(otherUsersProvider);
|
2022-04-23 21:08:45 -05:00
|
|
|
|
2022-11-21 06:13:14 -06:00
|
|
|
createSharedAlbum() async {
|
2025-07-29 00:34:03 +05:30
|
|
|
var newAlbum = await ref.watch(albumProvider.notifier).createAlbum(ref.watch(albumTitleProvider), assets);
|
2022-04-23 21:08:45 -05:00
|
|
|
|
2022-08-03 00:04:34 -05:00
|
|
|
if (newAlbum != null) {
|
2022-04-23 21:08:45 -05:00
|
|
|
ref.watch(albumTitleProvider.notifier).clearAlbumTitle();
|
2024-05-14 19:07:31 +00:00
|
|
|
context.maybePop(true);
|
2024-12-02 09:33:44 -06:00
|
|
|
context.navigateTo(const TabControllerRoute(children: [AlbumsRoute()]));
|
2022-04-23 21:08:45 -05:00
|
|
|
}
|
|
|
|
|
|
2022-07-13 07:23:48 -05:00
|
|
|
ScaffoldMessenger(
|
|
|
|
|
child: SnackBar(
|
2023-11-29 04:17:29 +00:00
|
|
|
content: Text(
|
|
|
|
|
'select_user_for_sharing_page_err_album',
|
2025-07-29 00:34:03 +05:30
|
|
|
style: context.textTheme.bodyLarge?.copyWith(color: context.primaryColor),
|
2023-11-29 04:17:29 +00:00
|
|
|
).tr(),
|
2022-07-13 07:23:48 -05:00
|
|
|
),
|
|
|
|
|
);
|
2022-04-23 21:08:45 -05:00
|
|
|
}
|
|
|
|
|
|
2025-03-12 19:26:56 +05:30
|
|
|
buildTileIcon(UserDto user) {
|
2022-04-23 21:08:45 -05:00
|
|
|
if (sharedUsersList.value.contains(user)) {
|
2025-07-29 00:34:03 +05:30
|
|
|
return CircleAvatar(backgroundColor: context.primaryColor, child: const Icon(Icons.check_rounded, size: 25));
|
2022-04-23 21:08:45 -05:00
|
|
|
} else {
|
2025-07-29 00:34:03 +05:30
|
|
|
return UserCircleAvatar(user: user);
|
2022-04-23 21:08:45 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 19:26:56 +05:30
|
|
|
buildUserList(List<UserDto> users) {
|
2022-04-23 21:08:45 -05:00
|
|
|
List<Widget> usersChip = [];
|
|
|
|
|
|
|
|
|
|
for (var user in sharedUsersList.value) {
|
|
|
|
|
usersChip.add(
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
|
|
|
|
child: Chip(
|
2025-03-10 21:46:36 -05:00
|
|
|
backgroundColor: context.primaryColor.withValues(alpha: 0.15),
|
2022-04-23 21:08:45 -05:00
|
|
|
label: Text(
|
|
|
|
|
user.email,
|
2025-07-29 00:34:03 +05:30
|
|
|
style: const TextStyle(fontSize: 12, color: Colors.black87, fontWeight: FontWeight.bold),
|
2022-04-23 21:08:45 -05:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-03-14 13:28:18 +01:00
|
|
|
return ListView(
|
2022-04-23 21:08:45 -05:00
|
|
|
children: [
|
2025-07-29 00:34:03 +05:30
|
|
|
Wrap(children: [...usersChip]),
|
2022-07-07 20:40:54 +02:00
|
|
|
Padding(
|
2022-07-13 07:23:48 -05:00
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
|
child: const Text(
|
2025-04-15 10:54:26 -05:00
|
|
|
'suggestions',
|
2025-07-29 00:34:03 +05:30
|
|
|
style: TextStyle(fontSize: 14, color: Colors.grey, fontWeight: FontWeight.bold),
|
2022-07-07 20:40:54 +02:00
|
|
|
).tr(),
|
2022-04-23 21:08:45 -05:00
|
|
|
),
|
|
|
|
|
ListView.builder(
|
2024-03-14 13:28:18 +01:00
|
|
|
primary: false,
|
2022-04-23 21:08:45 -05:00
|
|
|
shrinkWrap: true,
|
|
|
|
|
itemBuilder: ((context, index) {
|
|
|
|
|
return ListTile(
|
2022-11-21 06:13:14 -06:00
|
|
|
leading: buildTileIcon(users[index]),
|
2025-07-29 00:34:03 +05:30
|
|
|
title: Text(users[index].email, style: const TextStyle(fontSize: 14, fontWeight: FontWeight.bold)),
|
2022-04-23 21:08:45 -05:00
|
|
|
onTap: () {
|
|
|
|
|
if (sharedUsersList.value.contains(users[index])) {
|
2022-06-26 03:46:51 +09:00
|
|
|
sharedUsersList.value = sharedUsersList.value
|
2025-07-29 00:34:03 +05:30
|
|
|
.where((selectedUser) => selectedUser.id != users[index].id)
|
2022-06-26 03:46:51 +09:00
|
|
|
.toSet();
|
2022-04-23 21:08:45 -05:00
|
|
|
} else {
|
2025-07-29 00:34:03 +05:30
|
|
|
sharedUsersList.value = {...sharedUsersList.value, users[index]};
|
2022-04-23 21:08:45 -05:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}),
|
|
|
|
|
itemCount: users.length,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: AppBar(
|
2025-07-29 00:34:03 +05:30
|
|
|
title: Text('invite_to_album', style: TextStyle(color: context.primaryColor)).tr(),
|
2022-04-23 21:08:45 -05:00
|
|
|
elevation: 0,
|
|
|
|
|
centerTitle: false,
|
|
|
|
|
leading: IconButton(
|
|
|
|
|
icon: const Icon(Icons.close_rounded),
|
|
|
|
|
onPressed: () async {
|
2024-05-14 19:07:31 +00:00
|
|
|
context.maybePop();
|
2022-04-23 21:08:45 -05:00
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
actions: [
|
|
|
|
|
TextButton(
|
2025-07-29 00:34:03 +05:30
|
|
|
style: TextButton.styleFrom(foregroundColor: context.primaryColor),
|
2022-11-21 06:13:14 -06:00
|
|
|
onPressed: sharedUsersList.value.isEmpty ? null : createSharedAlbum,
|
2022-07-13 07:23:48 -05:00
|
|
|
child: const Text(
|
2025-04-15 10:54:26 -05:00
|
|
|
"create_album",
|
2022-08-15 18:53:30 -05:00
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 14,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
2023-11-09 16:19:53 +00:00
|
|
|
// color: context.primaryColor,
|
2022-08-15 18:53:30 -05:00
|
|
|
),
|
2022-07-13 07:23:48 -05:00
|
|
|
).tr(),
|
2023-08-18 18:52:40 -04:00
|
|
|
),
|
2022-04-23 21:08:45 -05:00
|
|
|
],
|
|
|
|
|
),
|
2023-11-29 04:17:29 +00:00
|
|
|
body: suggestedShareUsers.widgetWhen(
|
|
|
|
|
onData: (users) {
|
2022-11-21 06:13:14 -06:00
|
|
|
return buildUserList(users);
|
2022-04-23 21:08:45 -05:00
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|