mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 22:31:12 -05:00
Refactor: Use RPC for user data
This commit is contained in:
@@ -85,10 +85,12 @@ export function UserRoleManager() {
|
||||
// Get unique user IDs
|
||||
const userIds = [...new Set((data || []).map(r => r.user_id))];
|
||||
|
||||
// Fetch user profiles
|
||||
// Fetch user profiles with emails (for admins)
|
||||
const {
|
||||
data: profiles
|
||||
} = await supabase.from('profiles').select('user_id, username, display_name').in('user_id', userIds);
|
||||
data: allProfiles
|
||||
} = await supabase.rpc('get_users_with_emails');
|
||||
|
||||
const profiles = allProfiles?.filter(p => userIds.includes(p.user_id));
|
||||
const profileMap = new Map(profiles?.map(p => [p.user_id, p]) || []);
|
||||
|
||||
// Combine data with profiles
|
||||
@@ -113,9 +115,15 @@ export function UserRoleManager() {
|
||||
}
|
||||
try {
|
||||
const {
|
||||
data,
|
||||
data: allUsers,
|
||||
error
|
||||
} = await supabase.from('profiles').select('user_id, username, display_name').or(`username.ilike.%${search}%,display_name.ilike.%${search}%`).limit(10);
|
||||
} = await supabase.rpc('get_users_with_emails');
|
||||
|
||||
// Filter by search term
|
||||
const data = allUsers?.filter(user =>
|
||||
user.username.toLowerCase().includes(search.toLowerCase()) ||
|
||||
user.display_name?.toLowerCase().includes(search.toLowerCase())
|
||||
).slice(0, 10);
|
||||
if (error) throw error;
|
||||
|
||||
// Filter out users who already have roles
|
||||
|
||||
Reference in New Issue
Block a user