2023-01-31 03:22:08 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-11-26 22:10:51 +00:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2023-01-31 19:39:06 +00:00
|
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
|
2024-12-10 11:54:45 +00:00
|
|
|
import '../controls/async_value_widget.dart';
|
2024-11-26 22:10:51 +00:00
|
|
|
import '../controls/error_message_widget.dart';
|
2023-01-31 19:39:06 +00:00
|
|
|
import '../controls/image_control.dart';
|
2023-04-13 14:30:09 +00:00
|
|
|
import '../controls/responsive_max_width.dart';
|
2023-01-31 19:39:06 +00:00
|
|
|
import '../controls/standard_appbar.dart';
|
|
|
|
import '../controls/status_and_refresh_button.dart';
|
2024-11-26 22:10:51 +00:00
|
|
|
import '../models/auth/profile.dart';
|
2023-01-31 19:39:06 +00:00
|
|
|
import '../models/interaction_type_enum.dart';
|
2024-12-10 11:54:45 +00:00
|
|
|
import '../riverpod_controllers/account_services.dart';
|
2024-12-07 02:33:51 +00:00
|
|
|
import '../riverpod_controllers/connection_manager_services.dart';
|
2024-12-10 11:54:45 +00:00
|
|
|
import '../riverpod_controllers/interactions_details_services.dart';
|
2023-01-31 19:39:06 +00:00
|
|
|
import '../routes.dart';
|
2023-01-31 03:22:08 +00:00
|
|
|
|
2024-11-26 22:10:51 +00:00
|
|
|
class InteractionsViewerScreen extends ConsumerWidget {
|
2023-01-31 19:39:06 +00:00
|
|
|
final String statusId;
|
2023-01-31 03:22:08 +00:00
|
|
|
final InteractionType type;
|
|
|
|
|
|
|
|
const InteractionsViewerScreen({
|
|
|
|
super.key,
|
2023-01-31 19:39:06 +00:00
|
|
|
required this.statusId,
|
2023-01-31 03:22:08 +00:00
|
|
|
required this.type,
|
|
|
|
});
|
|
|
|
|
2024-11-26 22:10:51 +00:00
|
|
|
void refreshInteractors(WidgetRef ref, Profile profile) async {
|
2023-01-31 19:39:06 +00:00
|
|
|
switch (type) {
|
|
|
|
case InteractionType.like:
|
2024-11-26 22:10:51 +00:00
|
|
|
return ref.invalidate(likesForStatusProvider(profile, statusId));
|
2023-01-31 19:39:06 +00:00
|
|
|
case InteractionType.reshare:
|
2024-11-26 22:10:51 +00:00
|
|
|
return ref.invalidate(resharesForStatusProvider(profile, statusId));
|
2023-01-31 19:39:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-31 03:22:08 +00:00
|
|
|
@override
|
2024-11-26 22:10:51 +00:00
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2024-12-10 11:54:45 +00:00
|
|
|
final profile = ref.watch(activeProfileProvider);
|
2024-11-26 22:10:51 +00:00
|
|
|
final connectionsAsyncValue = switch (type) {
|
|
|
|
InteractionType.like =>
|
|
|
|
ref.watch(likesForStatusProvider(profile, statusId)),
|
|
|
|
InteractionType.reshare =>
|
|
|
|
ref.watch(resharesForStatusProvider(profile, statusId)),
|
|
|
|
};
|
|
|
|
|
2024-12-13 04:57:57 +00:00
|
|
|
final loading = switch (connectionsAsyncValue) {
|
|
|
|
AsyncData() => false,
|
|
|
|
_ => true,
|
|
|
|
};
|
|
|
|
|
2023-01-31 03:22:08 +00:00
|
|
|
return Scaffold(
|
2023-01-31 19:39:06 +00:00
|
|
|
appBar: StandardAppBar.build(context, buildTitle(), actions: [
|
2024-12-20 01:30:14 +00:00
|
|
|
StatusAndRefreshButton(
|
2024-12-13 04:57:57 +00:00
|
|
|
executing: loading,
|
2024-11-26 22:10:51 +00:00
|
|
|
refreshFunction: () async => refreshInteractors(ref, profile),
|
2024-05-19 15:07:15 +00:00
|
|
|
busyColor: Theme.of(context).colorScheme.surface,
|
2023-01-31 19:39:06 +00:00
|
|
|
)
|
|
|
|
]),
|
2023-01-31 03:22:08 +00:00
|
|
|
body: Center(
|
2023-04-13 14:30:09 +00:00
|
|
|
child: ResponsiveMaxWidth(
|
2024-11-26 22:10:51 +00:00
|
|
|
child: AsyncValueWidget(connectionsAsyncValue,
|
|
|
|
valueBuilder: (context, ref, connectionsResult) {
|
|
|
|
if (connectionsResult.isFailure) {
|
|
|
|
return ErrorMessageWidget(message: connectionsResult.error.message);
|
|
|
|
}
|
|
|
|
final connections = connectionsResult.value;
|
|
|
|
return ListView.separated(
|
2023-04-13 14:30:09 +00:00
|
|
|
itemCount: connections.length,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
final connection = connections[index];
|
|
|
|
return ListTile(
|
|
|
|
onTap: () async {
|
2024-12-07 02:33:51 +00:00
|
|
|
await ref
|
|
|
|
.read(connectionByIdProvider(profile, connection.id))
|
|
|
|
.withErrorAsync((_) => ref
|
|
|
|
.read(connectionModifierProvider(profile, connection)
|
|
|
|
.notifier)
|
|
|
|
.fullRefresh());
|
2023-04-13 14:30:09 +00:00
|
|
|
if (context.mounted) {
|
|
|
|
context.pushNamed(ScreenPaths.userProfile,
|
2023-10-31 01:44:16 +00:00
|
|
|
pathParameters: {'id': connection.id});
|
2023-03-22 13:24:14 +00:00
|
|
|
}
|
2023-04-13 14:30:09 +00:00
|
|
|
},
|
|
|
|
leading: ImageControl(
|
|
|
|
imageUrl: connection.avatarUrl.toString(),
|
|
|
|
iconOverride: const Icon(Icons.person),
|
|
|
|
width: 32.0,
|
|
|
|
onTap: () => context.pushNamed(ScreenPaths.userProfile,
|
2023-10-31 01:44:16 +00:00
|
|
|
pathParameters: {'id': connection.id}),
|
2023-04-13 14:30:09 +00:00
|
|
|
),
|
|
|
|
title: Text('${connection.name} (${connection.handle})'),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
separatorBuilder: (_, __) => const Divider(),
|
2024-11-26 22:10:51 +00:00
|
|
|
);
|
|
|
|
})),
|
2023-01-31 19:39:06 +00:00
|
|
|
),
|
2023-01-31 03:22:08 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
String buildTitle() {
|
|
|
|
switch (type) {
|
|
|
|
case InteractionType.like:
|
|
|
|
return 'Likes';
|
|
|
|
case InteractionType.reshare:
|
|
|
|
return 'Reshares';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|