add ai generations limit + random bug fixes
This commit is contained in:
@ -5,9 +5,13 @@ import { Button } from "../ui/button"
|
||||
import { Check, Loader2, RotateCw, Sparkles, X } from "lucide-react"
|
||||
import { Socket } from "socket.io-client"
|
||||
import { Editor } from "@monaco-editor/react"
|
||||
import { User } from "@/lib/types"
|
||||
import { toast } from "sonner"
|
||||
import { usePathname, useRouter } from "next/navigation"
|
||||
// import monaco from "monaco-editor"
|
||||
|
||||
export default function GenerateInput({
|
||||
user,
|
||||
socket,
|
||||
width,
|
||||
data,
|
||||
@ -15,6 +19,7 @@ export default function GenerateInput({
|
||||
onExpand,
|
||||
onAccept,
|
||||
}: {
|
||||
user: User
|
||||
socket: Socket
|
||||
width: number
|
||||
data: {
|
||||
@ -28,6 +33,8 @@ export default function GenerateInput({
|
||||
onExpand: () => void
|
||||
onAccept: (code: string) => void
|
||||
}) {
|
||||
const pathname = usePathname()
|
||||
const router = useRouter()
|
||||
const inputRef = useRef<HTMLInputElement>(null)
|
||||
|
||||
const [code, setCode] = useState("")
|
||||
@ -50,6 +57,12 @@ export default function GenerateInput({
|
||||
}: {
|
||||
regenerate?: boolean
|
||||
}) => {
|
||||
if (user.generations >= 30) {
|
||||
toast.error(
|
||||
"You reached the maximum # of generations. Contact @ishaandey_ on X/Twitter to reset :)"
|
||||
)
|
||||
}
|
||||
|
||||
setLoading({ generate: !regenerate, regenerate })
|
||||
setCurrentPrompt(input)
|
||||
socket.emit(
|
||||
@ -72,6 +85,7 @@ export default function GenerateInput({
|
||||
}
|
||||
|
||||
setCode(res.result.response)
|
||||
router.refresh()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -34,8 +34,7 @@ import Sidebar from "./sidebar"
|
||||
import EditorTerminal from "./terminal"
|
||||
import { Button } from "../ui/button"
|
||||
import GenerateInput from "./generate"
|
||||
import { TFile, TFileData, TFolder, TTab } from "./sidebar/types"
|
||||
import { Sandbox, User } from "@/lib/types"
|
||||
import { Sandbox, User, TFile, TFileData, TFolder, TTab } from "@/lib/types"
|
||||
import { processFileType, validateName } from "@/lib/utils"
|
||||
import { Cursors } from "./live/cursors"
|
||||
|
||||
@ -455,6 +454,7 @@ export default function CodeEditor({
|
||||
<div className="z-50 p-1" ref={generateWidgetRef}>
|
||||
{generate.show && ai ? (
|
||||
<GenerateInput
|
||||
user={userData}
|
||||
socket={socket}
|
||||
width={generate.width - 90}
|
||||
data={{
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
import Image from "next/image"
|
||||
import { getIconForFile } from "vscode-icons-js"
|
||||
import { TFile, TTab } from "./types"
|
||||
import { TFile, TTab } from "@/lib/types"
|
||||
import { useEffect, useRef, useState } from "react"
|
||||
import {
|
||||
ContextMenu,
|
||||
|
@ -3,7 +3,7 @@
|
||||
import Image from "next/image"
|
||||
import { useEffect, useRef, useState } from "react"
|
||||
import { getIconForFolder, getIconForOpenFolder } from "vscode-icons-js"
|
||||
import { TFile, TFolder, TTab } from "./types"
|
||||
import { TFile, TFolder, TTab } from "@/lib/types"
|
||||
import SidebarFile from "./file"
|
||||
import {
|
||||
ContextMenu,
|
||||
|
@ -3,7 +3,7 @@
|
||||
import { FilePlus, FolderPlus, Loader2, Search, Sparkles } from "lucide-react"
|
||||
import SidebarFile from "./file"
|
||||
import SidebarFolder from "./folder"
|
||||
import { TFile, TFolder, TTab } from "./types"
|
||||
import { TFile, TFolder, TTab } from "@/lib/types"
|
||||
import { useState } from "react"
|
||||
import New from "./new"
|
||||
import { Socket } from "socket.io-client"
|
||||
|
@ -1,21 +0,0 @@
|
||||
export type TFolder = {
|
||||
id: string
|
||||
type: "folder"
|
||||
name: string
|
||||
children: (TFile | TFolder)[]
|
||||
}
|
||||
|
||||
export type TFile = {
|
||||
id: string
|
||||
type: "file"
|
||||
name: string
|
||||
}
|
||||
|
||||
export type TTab = TFile & {
|
||||
saved: boolean
|
||||
}
|
||||
|
||||
export type TFileData = {
|
||||
id: string
|
||||
data: string
|
||||
}
|
Reference in New Issue
Block a user