Teams CRUD
This commit is contained in:
@@ -1,21 +1,24 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'supabase_provider.dart';
|
||||
import '../models/team.dart';
|
||||
import '../models/team_member.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
final teamsProvider = FutureProvider<List<Team>>((ref) async {
|
||||
final data = await Supabase.instance.client
|
||||
/// Real-time stream of teams (keeps UI in sync with DB changes).
|
||||
final teamsProvider = StreamProvider<List<Team>>((ref) {
|
||||
final client = ref.watch(supabaseClientProvider);
|
||||
return client
|
||||
.from('teams')
|
||||
.select()
|
||||
.order('name');
|
||||
return (data as List<dynamic>? ?? [])
|
||||
.map((e) => Team.fromMap(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
.stream(primaryKey: ['id'])
|
||||
.order('name')
|
||||
.map((rows) => rows.map((r) => Team.fromMap(r)).toList());
|
||||
});
|
||||
|
||||
final teamMembersProvider = FutureProvider<List<TeamMember>>((ref) async {
|
||||
final data = await Supabase.instance.client.from('team_members').select();
|
||||
return (data as List<dynamic>? ?? [])
|
||||
.map((e) => TeamMember.fromMap(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
/// Real-time stream of team membership rows.
|
||||
final teamMembersProvider = StreamProvider<List<TeamMember>>((ref) {
|
||||
final client = ref.watch(supabaseClientProvider);
|
||||
return client
|
||||
.from('team_members')
|
||||
.stream(primaryKey: ['team_id', 'user_id'])
|
||||
.map((rows) => rows.map((r) => TeamMember.fromMap(r)).toList());
|
||||
});
|
||||
|
||||
@@ -133,10 +133,11 @@ class TypingIndicatorController extends StateNotifier<TypingIndicatorState> {
|
||||
|
||||
void userTyping() {
|
||||
if (_disposed || !mounted) {
|
||||
if (kDebugMode)
|
||||
if (kDebugMode) {
|
||||
debugPrint(
|
||||
'TypingIndicatorController.userTyping() ignored after dispose',
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (_client.auth.currentUser?.id == null) return;
|
||||
@@ -144,10 +145,11 @@ class TypingIndicatorController extends StateNotifier<TypingIndicatorState> {
|
||||
_typingTimer?.cancel();
|
||||
_typingTimer = Timer(const Duration(milliseconds: 150), () {
|
||||
if (_disposed || !mounted) {
|
||||
if (kDebugMode)
|
||||
if (kDebugMode) {
|
||||
debugPrint(
|
||||
'TypingIndicatorController._typingTimer callback ignored after dispose',
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
_sendTypingEvent('stop');
|
||||
@@ -156,10 +158,11 @@ class TypingIndicatorController extends StateNotifier<TypingIndicatorState> {
|
||||
|
||||
void stopTyping() {
|
||||
if (_disposed || !mounted) {
|
||||
if (kDebugMode)
|
||||
if (kDebugMode) {
|
||||
debugPrint(
|
||||
'TypingIndicatorController.stopTyping() ignored after dispose',
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
_typingTimer?.cancel();
|
||||
@@ -182,10 +185,11 @@ class TypingIndicatorController extends StateNotifier<TypingIndicatorState> {
|
||||
_remoteTimeouts[userId]?.cancel();
|
||||
_remoteTimeouts[userId] = Timer(const Duration(milliseconds: 400), () {
|
||||
if (_disposed || !mounted) {
|
||||
if (kDebugMode)
|
||||
if (kDebugMode) {
|
||||
debugPrint(
|
||||
'TypingIndicatorController.remote timeout callback ignored after dispose for user: $userId',
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
_clearRemoteTyping(userId);
|
||||
@@ -194,10 +198,11 @@ class TypingIndicatorController extends StateNotifier<TypingIndicatorState> {
|
||||
|
||||
void _clearRemoteTyping(String userId) {
|
||||
if (_disposed || !mounted) {
|
||||
if (kDebugMode)
|
||||
if (kDebugMode) {
|
||||
debugPrint(
|
||||
'TypingIndicatorController._clearRemoteTyping ignored after dispose for user: $userId',
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
final updated = {...state.userIds}..remove(userId);
|
||||
|
||||
Reference in New Issue
Block a user