| 108 | // Fetch robots for dropdown |
| 109 | useEffect(() => { |
| 110 | const fetchRobots = async () => { |
| 111 | if (!user || !supabase) return; |
| 112 | |
| 113 | setLoadingRobots(true); |
| 114 | try { |
| 115 | const { data, error } = await supabase |
| 116 | .from('robots') |
| 117 | .select('*') |
| 118 | .order('is_favorite', { ascending: false }) |
| 119 | .order('name', { ascending: true }); |
| 120 | |
| 121 | if (error) throw error; |
| 122 | |
| 123 | setRobots(data || []); |
| 124 | } catch (error) { |
| 125 | console.error('Error fetching robots:', error); |
| 126 | } finally { |
| 127 | setLoadingRobots(false); |
| 128 | } |
| 129 | }; |
| 130 | |
| 131 | fetchRobots(); |
| 132 | }, [user, supabase]); |