2024-01-15 18:50:33 +02:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2023-11-06 17:46:26 +02:00
|
|
|
import 'package:collection/collection.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart' hide Store;
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2023-11-29 06:17:29 +02:00
|
|
|
import 'package:immich_mobile/extensions/asyncvalue_extensions.dart';
|
2023-11-09 18:19:53 +02:00
|
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
2023-11-06 17:46:26 +02:00
|
|
|
import 'package:immich_mobile/modules/activities/models/activity.model.dart';
|
|
|
|
import 'package:immich_mobile/modules/activities/providers/activity.provider.dart';
|
2024-01-05 07:20:55 +02:00
|
|
|
import 'package:immich_mobile/modules/activities/widgets/activity_text_field.dart';
|
|
|
|
import 'package:immich_mobile/modules/activities/widgets/activity_tile.dart';
|
|
|
|
import 'package:immich_mobile/modules/activities/widgets/dismissible_activity.dart';
|
|
|
|
import 'package:immich_mobile/modules/album/providers/current_album.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/asset_viewer/providers/current_asset.provider.dart';
|
|
|
|
import 'package:immich_mobile/shared/providers/user.provider.dart';
|
2023-11-06 17:46:26 +02:00
|
|
|
|
2024-01-15 18:50:33 +02:00
|
|
|
@RoutePage()
|
2023-11-06 17:46:26 +02:00
|
|
|
class ActivitiesPage extends HookConsumerWidget {
|
2024-01-05 07:20:55 +02:00
|
|
|
const ActivitiesPage({
|
2023-11-06 17:46:26 +02:00
|
|
|
super.key,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2024-01-05 07:20:55 +02:00
|
|
|
// Album has to be set in the provider before reaching this page
|
|
|
|
final album = ref.watch(currentAlbumProvider)!;
|
|
|
|
final asset = ref.watch(currentAssetProvider);
|
|
|
|
final user = ref.watch(currentUserProvider);
|
2023-11-06 17:46:26 +02:00
|
|
|
|
2024-01-05 07:20:55 +02:00
|
|
|
final activityNotifier = ref
|
|
|
|
.read(albumActivityProvider(album.remoteId!, asset?.remoteId).notifier);
|
|
|
|
final activities =
|
|
|
|
ref.watch(albumActivityProvider(album.remoteId!, asset?.remoteId));
|
2023-11-06 17:46:26 +02:00
|
|
|
|
2024-01-05 07:20:55 +02:00
|
|
|
final listViewScrollController = useScrollController();
|
2023-11-06 17:46:26 +02:00
|
|
|
|
2024-01-05 07:20:55 +02:00
|
|
|
Future<void> onAddComment(String comment) async {
|
|
|
|
await activityNotifier.addComment(comment);
|
|
|
|
// Scroll to the end of the list to show the newly added activity
|
|
|
|
listViewScrollController.animateTo(
|
|
|
|
listViewScrollController.position.maxScrollExtent + 200,
|
|
|
|
duration: const Duration(milliseconds: 600),
|
|
|
|
curve: Curves.fastOutSlowIn,
|
2023-11-06 17:46:26 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Scaffold(
|
2024-01-05 07:20:55 +02:00
|
|
|
appBar: AppBar(title: asset == null ? Text(album.name) : null),
|
2023-11-29 06:17:29 +02:00
|
|
|
body: activities.widgetWhen(
|
|
|
|
onData: (data) {
|
2023-11-06 17:46:26 +02:00
|
|
|
final liked = data.firstWhereOrNull(
|
|
|
|
(a) =>
|
|
|
|
a.type == ActivityType.like &&
|
2024-01-05 07:20:55 +02:00
|
|
|
a.user.id == user?.id &&
|
|
|
|
a.assetId == asset?.remoteId,
|
2023-11-06 17:46:26 +02:00
|
|
|
);
|
|
|
|
|
2023-11-08 05:07:43 +02:00
|
|
|
return SafeArea(
|
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
ListView.builder(
|
|
|
|
controller: listViewScrollController,
|
2024-01-05 07:20:55 +02:00
|
|
|
// +1 to display an additional over-scroll space after the last element
|
2023-11-08 05:07:43 +02:00
|
|
|
itemCount: data.length + 1,
|
|
|
|
itemBuilder: (context, index) {
|
2024-01-05 07:20:55 +02:00
|
|
|
// Additional vertical gap after the last element
|
2023-11-08 05:07:43 +02:00
|
|
|
if (index == data.length) {
|
|
|
|
return const SizedBox(
|
|
|
|
height: 80,
|
|
|
|
);
|
|
|
|
}
|
2023-11-06 17:46:26 +02:00
|
|
|
|
2023-11-08 05:07:43 +02:00
|
|
|
final activity = data[index];
|
2024-01-05 07:20:55 +02:00
|
|
|
final canDelete = activity.user.id == user?.id ||
|
|
|
|
album.ownerId == user?.id;
|
2023-11-06 17:46:26 +02:00
|
|
|
|
2023-11-08 05:07:43 +02:00
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.all(5),
|
2024-01-05 07:20:55 +02:00
|
|
|
child: DismissibleActivity(
|
|
|
|
activity.id,
|
|
|
|
ActivityTile(activity),
|
|
|
|
onDismiss: canDelete
|
|
|
|
? (activityId) async => await activityNotifier
|
|
|
|
.removeActivity(activity.id)
|
|
|
|
: null,
|
|
|
|
),
|
2023-11-08 05:07:43 +02:00
|
|
|
);
|
|
|
|
},
|
2023-11-06 17:46:26 +02:00
|
|
|
),
|
2023-11-08 05:07:43 +02:00
|
|
|
Align(
|
|
|
|
alignment: Alignment.bottomCenter,
|
|
|
|
child: Container(
|
2023-11-09 18:19:53 +02:00
|
|
|
color: context.scaffoldBackgroundColor,
|
2024-01-05 07:20:55 +02:00
|
|
|
child: ActivityTextField(
|
|
|
|
isEnabled: album.activityEnabled,
|
|
|
|
likeId: liked?.id,
|
|
|
|
onSubmit: onAddComment,
|
|
|
|
),
|
2023-11-08 05:07:43 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2023-11-06 17:46:26 +02:00
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|