diff --git a/lib/screens/garage_screen.dart b/lib/screens/garage_screen.dart index c0167e8..a16201b 100644 --- a/lib/screens/garage_screen.dart +++ b/lib/screens/garage_screen.dart @@ -93,7 +93,7 @@ class GarageScreenState extends State { final data = await supabase .from('hotwheels') .select( - 'id, created_at, hw_id, notes, user_image_url, global_cars(name, series, year, color)') + 'id, created_at, hw_id, notes, user_image_url, global_cars(name, series, year, color, is_verified, confirmation_count)') .eq('collection_id', widget.collectionId) .order('created_at', ascending: false) .range(from, to); @@ -476,6 +476,8 @@ class GarageScreenState extends State { final name = global?['name'] as String?; final series = global?['series'] as String?; final year = global?['year'] as int?; + final verified = global?['is_verified'] == true; + final confirmations = (global?['confirmation_count'] as num?)?.toInt() ?? 0; final notes = car['notes'] as String?; final imageUrl = car['signed_image_url'] as String?; @@ -597,11 +599,35 @@ class GarageScreenState extends State { _DetailRow(icon: Icons.collections, label: 'Series', value: series), if (year != null) _DetailRow(icon: Icons.calendar_today, label: 'Year', value: '$year'), + _DetailRow( + icon: verified ? Icons.verified : Icons.hourglass_bottom, + label: 'Validation', + value: verified + ? 'Verified by community' + : 'Pending verification', + ), + _DetailRow( + icon: Icons.how_to_vote, + label: 'Confirmations', + value: '$confirmations', + ), if (notes != null && notes.isNotEmpty) _DetailRow(icon: Icons.notes, label: 'Notes', value: notes), const SizedBox(height: 24), + if (!verified) ...[ + SizedBox( + width: double.infinity, + child: OutlinedButton.icon( + onPressed: () => _confirmCatalogEntry(hwId, context), + icon: const Icon(Icons.thumb_up_alt_outlined, size: 18), + label: const Text('Confirm Catalog Entry'), + ), + ), + const SizedBox(height: 10), + ], + // Edit & Delete buttons Row( children: [ @@ -730,6 +756,36 @@ class GarageScreenState extends State { } } + Future _confirmCatalogEntry(String hwId, BuildContext sheetContext) async { + final user = supabase.auth.currentUser; + if (user == null) return; + + try { + final existingVote = await supabase + .from('car_votes') + .select('id') + .eq('hw_id', hwId) + .eq('user_id', user.id) + .maybeSingle(); + + if (existingVote != null) { + showGlobalSnackBar('You already confirmed this catalog entry.'); + return; + } + + await supabase.from('car_votes').insert({ + 'hw_id': hwId, + 'user_id': user.id, + }); + + showGlobalSnackBar('Thanks! Your validation vote was recorded.'); + if (sheetContext.mounted) Navigator.pop(sheetContext); + _loadCars(reset: true); + } catch (e) { + showGlobalSnackBar('Failed to submit validation vote: $e', isError: true); + } + } + Future _pickTargetCollection() async { final collections = await CollectionService.getMyCollections(); if (!mounted) return null;