"use client" import { Button } from "@/components/ui/button" import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover" import { useTerminal } from "@/context/TerminalContext" import { Sandbox, User } from "@/lib/types" import { Globe } from "lucide-react" import { useEffect, useState } from "react" export default function DeployButtonModal({ userData, data, }: { userData: User data: Sandbox }) { const { deploy, getAppExists } = useTerminal() const [isDeploying, setIsDeploying] = useState(false) const [isDeployed, setIsDeployed] = useState(false) const [deployButtonVisible, setDeployButtonEnabled] = useState(false) useEffect(() => { const checkDeployment = async () => { if (getAppExists) { const exists = await getAppExists(data.id) setDeployButtonEnabled(exists.success) setIsDeployed((exists.success && exists.exists) ?? false) } } checkDeployment() }, [data.id, getAppExists]) const handleDeploy = () => { if (isDeploying) { console.log("Stopping deployment...") setIsDeploying(false) } else { console.log("Starting deployment...") setIsDeploying(true) deploy(() => { setIsDeploying(false) setIsDeployed(true) }) } } return ( <> {deployButtonVisible && ( )}

Domains

} domain={`${data.id}.gitwit.app`} timestamp="Deployed 1m ago" user={userData.name} isDeployed={isDeployed} />
) } function DeploymentOption({ icon, domain, timestamp, user, isDeployed, }: { icon: React.ReactNode domain: string timestamp: string user: string isDeployed: boolean }) { return (
{icon}
{isDeployed ? ( {domain} ) : ( {domain} )}

{isDeployed ? `${timestamp} • ${user}` : "Never deployed"}

) }