From fdb59c925b17b4780f63b5797cb7bc8be205fb2c Mon Sep 17 00:00:00 2001 From: Ishaan Dey Date: Sat, 4 May 2024 01:50:33 -0700 Subject: [PATCH] ai enable button --- frontend/components/editor/index.tsx | 16 +++++++- frontend/components/editor/sidebar/index.tsx | 19 ++++++--- frontend/components/ui/customToggle.tsx | 43 ++++++++++++++++++++ 3 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 frontend/components/ui/customToggle.tsx diff --git a/frontend/components/editor/index.tsx b/frontend/components/editor/index.tsx index c157ad9..2e23b60 100644 --- a/frontend/components/editor/index.tsx +++ b/frontend/components/editor/index.tsx @@ -70,6 +70,7 @@ export default function CodeEditor({ }>({ options: [], instance: undefined }) const [terminals, setTerminals] = useState([]) const [provider, setProvider] = useState() + const [ai, setAi] = useState(false) const clerk = useClerk() const room = useRoom() @@ -150,6 +151,15 @@ export default function CodeEditor({ } useEffect(() => { + if (!ai) { + setGenerate((prev) => { + return { + ...prev, + show: false, + } + }) + return + } if (generate.show) { editorRef.current?.changeViewZones(function (changeAccessor) { if (!generateRef.current) return @@ -217,6 +227,8 @@ export default function CodeEditor({ decorations.instance?.clear() } + if (!ai) return + if (decorations.instance) { decorations.instance.set(decorations.options) } else { @@ -426,7 +438,7 @@ export default function CodeEditor({ <>
- {generate.show ? ( + {generate.show && ai ? ( [...prev, { id, name, type: "folder", children: [] }]) } }} + ai={ai} + setAi={setAi} /> void @@ -29,6 +33,8 @@ export default function Sidebar({ handleDeleteFolder: (folder: TFolder) => void socket: Socket addNew: (name: string, type: "file" | "folder") => void + ai: boolean + setAi: React.Dispatch> }) { const [creatingNew, setCreatingNew] = useState<"file" | "folder" | null>(null) @@ -98,11 +104,12 @@ export default function Sidebar({ )}
-
- {/*
- {connected ? "Connected" : "Not connected"} -
*/} -
+ {/*
*/} + + + AI Copilot + + {/*
*/} ) } diff --git a/frontend/components/ui/customToggle.tsx b/frontend/components/ui/customToggle.tsx new file mode 100644 index 0000000..776b6bf --- /dev/null +++ b/frontend/components/ui/customToggle.tsx @@ -0,0 +1,43 @@ +import * as React from "react" +import { Plus } from "lucide-react" +import { cn } from "@/lib/utils" +import { Button } from "./button" + +const Toggle = ({ + children, + className, + value, + setValue, +}: { + children: React.ReactNode + className?: string + value: boolean + setValue: React.Dispatch> +}) => { + if (value) + return ( + + ) + else + return ( + + ) +} + +export default Toggle