92 lines
3.0 KiB
TypeScript
Raw Normal View History

2024-10-23 10:51:50 +01:00
"use client"
2024-04-30 22:48:36 -04:00
2024-10-23 10:51:50 +01:00
import Logo from "@/assets/logo.svg"
import { Button } from "@/components/ui/button"
import { ThemeSwitcher } from "@/components/ui/theme-switcher"
import UserButton from "@/components/ui/userButton"
import { Sandbox, User } from "@/lib/types"
import { Pencil, Users } from "lucide-react"
import Image from "next/image"
import Link from "next/link"
import { useState } from "react"
import { Avatars } from "../live/avatars"
import DeployButtonModal from "./deploy"
2024-11-17 12:35:56 -05:00
import DownloadButton from "./downloadButton"
2024-10-23 10:51:50 +01:00
import EditSandboxModal from "./edit"
import RunButtonModal from "./run"
import ShareSandboxModal from "./share"
2024-04-08 23:40:42 -04:00
2024-04-27 00:28:00 -04:00
export default function Navbar({
userData,
sandboxData,
2024-05-01 01:53:49 -04:00
shared,
2024-04-27 00:28:00 -04:00
}: {
2024-10-23 10:51:50 +01:00
userData: User
sandboxData: Sandbox
shared: { id: string; name: string; avatarUrl: string }[]
2024-04-27 00:28:00 -04:00
}) {
2024-10-23 10:51:50 +01:00
const [isEditOpen, setIsEditOpen] = useState(false)
const [isShareOpen, setIsShareOpen] = useState(false)
const [isRunning, setIsRunning] = useState(false)
2024-04-30 22:48:36 -04:00
2024-10-23 10:51:50 +01:00
const isOwner = sandboxData.userId === userData.id
2024-05-05 00:06:10 -07:00
2024-04-08 23:40:42 -04:00
return (
2024-04-30 22:48:36 -04:00
<>
<EditSandboxModal
open={isEditOpen}
setOpen={setIsEditOpen}
data={sandboxData}
/>
<ShareSandboxModal
open={isShareOpen}
setOpen={setIsShareOpen}
data={sandboxData}
2024-05-01 01:53:49 -04:00
shared={shared}
2024-04-30 22:48:36 -04:00
/>
2024-05-11 18:13:01 -07:00
<div className="h-14 shrink-0 px-2 w-full flex items-center justify-between border-b border-border">
2024-04-30 22:48:36 -04:00
<div className="flex items-center space-x-4">
<Link
href="/"
className="ring-offset-2 transition-all ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring rounded-md"
>
<Image src={Logo} alt="Logo" width={36} height={36} />
</Link>
<div className="text-sm font-medium flex items-center">
{sandboxData.name}
2024-05-05 00:06:10 -07:00
{isOwner ? (
<button
onClick={() => setIsEditOpen(true)}
className="h-7 w-7 ml-2 flex items-center justify-center bg-transparent hover:bg-muted-foreground/25 cursor-pointer rounded-md ring-offset-2 transition-all ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
>
<Pencil className="w-4 h-4" />
</button>
) : null}
</div>
</div>
2024-07-23 17:30:35 -04:00
<RunButtonModal
isRunning={isRunning}
setIsRunning={setIsRunning}
sandboxData={sandboxData}
2024-07-23 17:30:35 -04:00
/>
2024-05-05 14:33:09 -07:00
<div className="flex items-center h-full space-x-4">
2024-05-03 14:58:56 -07:00
<Avatars />
2024-05-05 00:06:10 -07:00
{isOwner ? (
2024-07-23 17:30:35 -04:00
<>
2024-10-23 10:51:50 +01:00
<DeployButtonModal data={sandboxData} userData={userData} />
<Button variant="outline" onClick={() => setIsShareOpen(true)}>
<Users className="w-4 h-4 mr-2" />
Share
</Button>
2024-11-17 12:35:56 -05:00
<DownloadButton name={sandboxData.name} />
</>
2024-05-05 00:06:10 -07:00
) : null}
2024-10-23 10:51:50 +01:00
<ThemeSwitcher />
2024-04-30 22:48:36 -04:00
<UserButton userData={userData} />
</div>
2024-04-08 23:40:42 -04:00
</div>
2024-04-30 22:48:36 -04:00
</>
2024-10-23 10:51:50 +01:00
)
}