From 979f1533affae3337025d0d424a1daceefe03793 Mon Sep 17 00:00:00 2001 From: Biwas Bhandari Date: Wed, 4 Dec 2024 12:03:09 +0545 Subject: [PATCH 1/5] fix: mobile chat height --- src/components/chat/Chat.tsx | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/components/chat/Chat.tsx b/src/components/chat/Chat.tsx index 6cc7cbb0..eb495133 100644 --- a/src/components/chat/Chat.tsx +++ b/src/components/chat/Chat.tsx @@ -74,13 +74,13 @@ export default function Chat() { }, []); return ( -
+
@@ -93,9 +93,18 @@ export default function Chat() {
-
-
-
+
+
+
From 46a6999b38aec4ea786dc78111c546d47e5d794a Mon Sep 17 00:00:00 2001 From: Biwas Bhandari Date: Thu, 5 Dec 2024 10:17:28 +0545 Subject: [PATCH 2/5] fix: remove (cloned) --- src/components/marketplace/ClonePublicCrew.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/marketplace/ClonePublicCrew.tsx b/src/components/marketplace/ClonePublicCrew.tsx index 7f2cc694..2e57367d 100644 --- a/src/components/marketplace/ClonePublicCrew.tsx +++ b/src/components/marketplace/ClonePublicCrew.tsx @@ -37,7 +37,7 @@ export function ClonePublicCrew({ crew, disabled }: ClonePublicCrewProps) { const { data: clonedCrew, error: crewError } = await supabase .from("crews") .insert({ - name: `${crew.name} (Cloned)`, + name: crew.name, description: crew.description, profile_id: profile.user.id, }) From f4f2bc50e3d54541f090ac5eca11aeb0737bcbe9 Mon Sep 17 00:00:00 2001 From: Biwas Bhandari Date: Thu, 5 Dec 2024 11:17:46 +0545 Subject: [PATCH 3/5] fix: refetch agent --- src/app/crews/[id]/manage/page.tsx | 163 +++++++++++++++------- src/components/agents/AgentManagement.tsx | 2 +- 2 files changed, 111 insertions(+), 54 deletions(-) diff --git a/src/app/crews/[id]/manage/page.tsx b/src/app/crews/[id]/manage/page.tsx index ea2c6ddb..64b37a85 100644 --- a/src/app/crews/[id]/manage/page.tsx +++ b/src/app/crews/[id]/manage/page.tsx @@ -1,6 +1,6 @@ "use client"; -import { useState, useEffect } from "react"; +import { useState, useEffect, useCallback } from "react"; import { useParams, useRouter } from "next/navigation"; import { supabase } from "@/utils/supabase/client"; import AgentManagement from "@/components/agents/AgentManagement"; @@ -8,7 +8,13 @@ import TaskManagement from "@/components/tasks/TaskManagement"; import { Card, CardContent } from "@/components/ui/card"; import { Agent, CrewWithCron, Task } from "@/types/supabase"; import { Switch } from "@/components/ui/switch"; -import { TooltipProvider, Tooltip, TooltipTrigger, TooltipContent } from "@/components/ui/tooltip"; + +import { + TooltipProvider, + Tooltip, + TooltipTrigger, + TooltipContent, +} from "@/components/ui/tooltip"; import { HelpCircle, Trash2 } from "lucide-react"; import { Button } from "@/components/ui/button"; import { useToast } from "@/hooks/use-toast"; @@ -44,16 +50,45 @@ export default function CrewDetails() { const [editForm, setEditForm] = useState({ name: "", description: "", - is_public: false + is_public: false, }); const [cronInput, setCronInput] = useState(""); const [cronEnabled, setCronEnabled] = useState(false); const [cronId, setCronId] = useState(0); + const fetchAgents = useCallback(async () => { + try { + const { data, error } = await supabase + .from("agents") + .select("*") + .eq("crew_id", id); + + if (error) throw error; + + setAgents(data || []); + } catch (error) { + console.error("Error fetching agents:", error); + toast({ + title: "Error", + description: "Failed to fetch agents.", + variant: "destructive", + }); + } + }, [id]); + + useEffect(() => { + if (id) { + fetchAgents(); + } + }, [id, fetchAgents]); + // Fetch current user useEffect(() => { async function fetchUser() { - const { data: { user }, error } = await supabase.auth.getUser(); + const { + data: { user }, + error, + } = await supabase.auth.getUser(); if (error) { console.error("Error fetching user:", error); return; @@ -69,21 +104,17 @@ export default function CrewDetails() { useEffect(() => { async function fetchData() { try { - const [crewResponse, agentsResponse, tasksResponse] = await Promise.all([ - supabase - .from("crews") - .select(`*, crons(id, enabled, input, created_at)`) - .eq("id", id) - .single(), - supabase - .from("agents") - .select("*") - .eq("crew_id", id), - supabase - .from("tasks") - .select("*") - .eq("crew_id", id) - ]); + const [crewResponse, agentsResponse, tasksResponse] = await Promise.all( + [ + supabase + .from("crews") + .select(`*, crons(id, enabled, input, created_at)`) + .eq("id", id) + .single(), + supabase.from("agents").select("*").eq("crew_id", id), + supabase.from("tasks").select("*").eq("crew_id", id), + ] + ); if (crewResponse.error) throw crewResponse.error; if (agentsResponse.error) throw agentsResponse.error; @@ -96,7 +127,7 @@ export default function CrewDetails() { setEditForm({ name: crewData.name, description: crewData.description || "", - is_public: crewData.is_public || false + is_public: crewData.is_public || false, }); if (crewData.crons?.[0]?.input) { setCronId(crewData.crons[0].id); @@ -111,7 +142,7 @@ export default function CrewDetails() { toast({ title: "Error", description: "Failed to load crew data. Please refresh the page.", - variant: "destructive" + variant: "destructive", }); } } @@ -132,7 +163,7 @@ export default function CrewDetails() { .update({ name: editForm.name, description: editForm.description, - is_public: editForm.is_public + is_public: editForm.is_public, }) .eq("id", crew.id); @@ -153,22 +184,24 @@ export default function CrewDetails() { name: editForm.name, description: editForm.description, is_public: editForm.is_public, - cron: crew.cron ? { - ...crew.cron, - input: cronInput - } : null + cron: crew.cron + ? { + ...crew.cron, + input: cronInput, + } + : null, }); toast({ title: "Success", - description: "Crew settings updated successfully." + description: "Crew settings updated successfully.", }); } catch (error) { console.error("Error saving settings:", error); toast({ title: "Error", description: "Failed to save crew settings. Please try again.", - variant: "destructive" + variant: "destructive", }); } finally { setIsSaving(false); @@ -187,7 +220,7 @@ export default function CrewDetails() { crew_id: crew.id, enabled: true, profile_id: currentUser, - input: "" + input: "", }) .select() .single(); @@ -201,7 +234,7 @@ export default function CrewDetails() { setCronEnabled(true); toast({ title: "Success", - description: "Autonomous running enabled." + description: "Autonomous running enabled.", }); } } else if (cronId) { @@ -220,15 +253,18 @@ export default function CrewDetails() { toast({ title: "Success", - description: `Autonomous running ${checked ? "enabled" : "disabled"}.` + description: `Autonomous running ${ + checked ? "enabled" : "disabled" + }.`, }); } } catch (error) { console.error("Error toggling autonomous mode:", error); toast({ title: "Error", - description: "Failed to update autonomous running status. Please try again.", - variant: "destructive" + description: + "Failed to update autonomous running status. Please try again.", + variant: "destructive", }); } }; @@ -250,7 +286,7 @@ export default function CrewDetails() { toast({ title: "Success", - description: "Crew deleted successfully" + description: "Crew deleted successfully", }); router.push("/crews"); @@ -259,7 +295,7 @@ export default function CrewDetails() { toast({ title: "Error", description: "Failed to delete crew. Please try again.", - variant: "destructive" + variant: "destructive", }); } finally { setIsDeleting(false); @@ -267,7 +303,11 @@ export default function CrewDetails() { }; if (!crew) { - return
Loading...
; + return ( +
+ Loading... +
+ ); } return ( @@ -282,15 +322,24 @@ export default function CrewDetails() { setEditForm(prev => ({ ...prev, name: e.target.value }))} + onChange={(e) => + setEditForm((prev) => ({ ...prev, name: e.target.value })) + } className="w-full px-3 py-2 border rounded-md" />
- +