80 lines
2.5 KiB
TypeScript
Raw Normal View History

2024-05-11 18:13:01 -07:00
"use client";
2024-04-30 22:48:36 -04:00
2024-05-11 18:13:01 -07:00
import Image from "next/image";
import Logo from "@/assets/logo.svg";
import { Pencil, Users } from "lucide-react";
import Link from "next/link";
import { Sandbox, User } from "@/lib/types";
import UserButton from "@/components/ui/userButton";
import { Button } from "@/components/ui/button";
import { useState } from "react";
import EditSandboxModal from "./edit";
import ShareSandboxModal from "./share";
import { Avatars } from "../live/avatars";
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-05-11 18:13:01 -07:00
userData: User;
sandboxData: Sandbox;
2024-05-01 01:53:49 -04:00
shared: {
2024-05-11 18:13:01 -07:00
id: string;
name: string;
}[];
2024-04-27 00:28:00 -04:00
}) {
2024-05-11 18:13:01 -07:00
const [isEditOpen, setIsEditOpen] = useState(false);
const [isShareOpen, setIsShareOpen] = useState(false);
2024-04-30 22:48:36 -04:00
2024-05-11 18:13:01 -07: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-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 ? (
<Button variant="outline" onClick={() => setIsShareOpen(true)}>
<Users className="w-4 h-4 mr-2" />
Share
</Button>
) : null}
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-05-11 18:13:01 -07:00
);
2024-04-08 23:40:42 -04:00
}