import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; import 'package:provider/provider.dart'; import 'package:relatica/controls/async_value_widget.dart'; import 'package:relatica/riverpod_controllers/interactions_details_services.dart'; import '../controls/error_message_widget.dart'; import '../controls/image_control.dart'; import '../controls/responsive_max_width.dart'; import '../controls/standard_appbar.dart'; import '../controls/status_and_refresh_button.dart'; import '../globals.dart'; import '../models/auth/profile.dart'; import '../models/interaction_type_enum.dart'; import '../routes.dart'; import '../services/auth_service.dart'; import '../services/connections_manager.dart'; import '../services/network_status_service.dart'; import '../utils/active_profile_selector.dart'; class InteractionsViewerScreen extends ConsumerWidget { final String statusId; final InteractionType type; const InteractionsViewerScreen({ super.key, required this.statusId, required this.type, }); void refreshInteractors(WidgetRef ref, Profile profile) async { switch (type) { case InteractionType.like: return ref.invalidate(likesForStatusProvider(profile, statusId)); case InteractionType.reshare: return ref.invalidate(resharesForStatusProvider(profile, statusId)); } } @override Widget build(BuildContext context, WidgetRef ref) { final profile = context.watch().currentProfile; final nss = getIt(); final connectionsAsyncValue = switch (type) { InteractionType.like => ref.watch(likesForStatusProvider(profile, statusId)), InteractionType.reshare => ref.watch(resharesForStatusProvider(profile, statusId)), }; return Scaffold( appBar: StandardAppBar.build(context, buildTitle(), actions: [ StatusAndRefreshButton( valueListenable: nss.interactionsLoadingStatus, refreshFunction: () async => refreshInteractors(ref, profile), busyColor: Theme.of(context).colorScheme.surface, ) ]), body: Center( child: ResponsiveMaxWidth( child: AsyncValueWidget(connectionsAsyncValue, valueBuilder: (context, ref, connectionsResult) { if (connectionsResult.isFailure) { return ErrorMessageWidget(message: connectionsResult.error.message); } final connections = connectionsResult.value; return ListView.separated( itemCount: connections.length, itemBuilder: (context, index) { final connection = connections[index]; return ListTile( onTap: () async { await getIt>() .activeEntry .andThenSuccessAsync((cm) async { final existingData = cm.getById(connection.id); if (existingData.isFailure) { await cm.fullRefresh(connection); } }); if (context.mounted) { context.pushNamed(ScreenPaths.userProfile, pathParameters: {'id': connection.id}); } }, leading: ImageControl( imageUrl: connection.avatarUrl.toString(), iconOverride: const Icon(Icons.person), width: 32.0, onTap: () => context.pushNamed(ScreenPaths.userProfile, pathParameters: {'id': connection.id}), ), title: Text('${connection.name} (${connection.handle})'), ); }, separatorBuilder: (_, __) => const Divider(), ); })), ), ); } String buildTitle() { switch (type) { case InteractionType.like: return 'Likes'; case InteractionType.reshare: return 'Reshares'; } } }