feat(validation): record independent discovery votes during catalog adds
- Add vote tracking when users add an existing global car entry - Guard against duplicate votes by checking user_id + hw_id first - Keep new-discovery flow voting unchanged while extending repeated-add validation - Align scanner business flow with TPB community verification model
This commit is contained in:
parent
99da5cf1ca
commit
d4883c1d32
1 changed files with 18 additions and 0 deletions
|
|
@ -340,6 +340,7 @@ class ScanTabState extends State<ScanTab> {
|
||||||
|
|
||||||
if (addConfirmed == true) {
|
if (addConfirmed == true) {
|
||||||
await _addToCollection(collection.id, hwId);
|
await _addToCollection(collection.id, hwId);
|
||||||
|
await _ensureValidationVote(hwId);
|
||||||
if (!mounted) return false;
|
if (!mounted) return false;
|
||||||
showGlobalSnackBar('$hwId added to "${collection.name}"! 🎉');
|
showGlobalSnackBar('$hwId added to "${collection.name}"! 🎉');
|
||||||
}
|
}
|
||||||
|
|
@ -410,6 +411,23 @@ class ScanTabState extends State<ScanTab> {
|
||||||
'user_id': supabase.auth.currentUser!.id,
|
'user_id': supabase.auth.currentUser!.id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _ensureValidationVote(String hwId) async {
|
||||||
|
final userId = supabase.auth.currentUser!.id;
|
||||||
|
final existingVote = await supabase
|
||||||
|
.from('car_votes')
|
||||||
|
.select('id')
|
||||||
|
.eq('hw_id', hwId)
|
||||||
|
.eq('user_id', userId)
|
||||||
|
.maybeSingle();
|
||||||
|
|
||||||
|
if (existingVote != null) return;
|
||||||
|
|
||||||
|
await supabase.from('car_votes').insert({
|
||||||
|
'hw_id': hwId,
|
||||||
|
'user_id': userId,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _FoundCarSheet extends StatelessWidget {
|
class _FoundCarSheet extends StatelessWidget {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue