"use client" import { Button } from "@/components/ui/button" import CustomButton from "@/components/ui/customButton" import { Sandbox } from "@/lib/types" import { Code2, FolderDot, HelpCircle, Plus, Users } from "lucide-react" import { useRouter, useSearchParams } from "next/navigation" import { useEffect, useState } from "react" import { toast } from "sonner" import AboutModal from "./about" import NewProjectModal from "./newProject" import DashboardProjects from "./projects" import DashboardSharedWithMe from "./shared" type TScreen = "projects" | "shared" | "settings" | "search" export default function Dashboard({ sandboxes, shared, }: { sandboxes: Sandbox[] shared: { id: string name: string type: "react" | "node" author: string sharedOn: Date authorAvatarUrl?: string }[] }) { const [screen, setScreen] = useState("projects") const [newProjectModalOpen, setNewProjectModalOpen] = useState(false) const [aboutModalOpen, setAboutModalOpen] = useState(false) const activeScreen = (s: TScreen) => { if (screen === s) return "justify-start" else return "justify-start font-normal text-muted-foreground" } const searchParams = useSearchParams() const q = searchParams.get("q") const router = useRouter() useEffect(() => { // update the dashboard to show a new project router.refresh() }, []) return ( <>
{ if (sandboxes.length >= 8) { toast.error("You reached the maximum # of sandboxes.") return } setNewProjectModalOpen(true) }} className="mb-4" > New Project {/* */}
{screen === "projects" ? ( <> {sandboxes ? ( ) : null} ) : screen === "shared" ? ( ({ ...item, authorAvatarUrl: item.authorAvatarUrl || "", }))} /> ) : screen === "settings" ? null : null}
) }