130 lines
3.9 KiB
TypeScript
Raw Normal View History

2024-05-26 19:02:47 -07:00
"use client"
2024-04-16 16:25:21 -04:00
2024-05-26 19:02:47 -07:00
import { Button } from "@/components/ui/button"
2024-10-21 13:57:45 -06:00
import CustomButton from "@/components/ui/customButton"
2024-05-26 19:02:47 -07:00
import { Sandbox } from "@/lib/types"
2024-10-21 13:57:45 -06:00
import { Code2, FolderDot, HelpCircle, Plus, Users } from "lucide-react"
2024-05-26 19:02:47 -07:00
import { useRouter, useSearchParams } from "next/navigation"
2024-10-21 13:57:45 -06:00
import { useEffect, useState } from "react"
2024-05-26 19:02:47 -07:00
import { toast } from "sonner"
2024-10-21 13:57:45 -06:00
import AboutModal from "./about"
import NewProjectModal from "./newProject"
import DashboardProjects from "./projects"
import DashboardSharedWithMe from "./shared"
2024-04-16 16:25:21 -04:00
2024-05-26 19:02:47 -07:00
type TScreen = "projects" | "shared" | "settings" | "search"
2024-04-16 16:25:21 -04:00
2024-05-01 02:49:25 -04:00
export default function Dashboard({
sandboxes,
shared,
}: {
2024-05-26 19:02:47 -07:00
sandboxes: Sandbox[]
2024-05-01 02:49:25 -04:00
shared: {
2024-05-26 19:02:47 -07:00
id: string
name: string
type: "react" | "node"
author: string
sharedOn: Date
}[]
2024-05-01 02:49:25 -04:00
}) {
2024-05-26 19:02:47 -07:00
const [screen, setScreen] = useState<TScreen>("projects")
2024-04-16 16:25:21 -04:00
2024-05-26 19:02:47 -07:00
const [newProjectModalOpen, setNewProjectModalOpen] = useState(false)
const [aboutModalOpen, setAboutModalOpen] = useState(false)
2024-04-16 16:25:21 -04:00
const activeScreen = (s: TScreen) => {
2024-05-26 19:02:47 -07:00
if (screen === s) return "justify-start"
else return "justify-start font-normal text-muted-foreground"
}
2024-04-16 16:25:21 -04:00
2024-05-26 19:02:47 -07:00
const searchParams = useSearchParams()
const q = searchParams.get("q")
const router = useRouter()
2024-10-21 13:57:45 -06:00
useEffect(() => {
// update the dashboard to show a new project
router.refresh()
}, [])
2024-05-01 08:53:37 -04:00
2024-04-16 16:25:21 -04:00
return (
<>
<NewProjectModal
open={newProjectModalOpen}
setOpen={setNewProjectModalOpen}
/>
2024-05-05 00:06:10 -07:00
<AboutModal open={aboutModalOpen} setOpen={setAboutModalOpen} />
<div className="flex grow w-full">
<div className="w-56 shrink-0 border-r border-border p-4 justify-between flex flex-col">
<div className="flex flex-col">
<CustomButton
2024-05-05 12:55:34 -07:00
onClick={() => {
if (sandboxes.length >= 8) {
2024-05-26 19:02:47 -07:00
toast.error("You reached the maximum # of sandboxes.")
return
2024-05-05 12:55:34 -07:00
}
2024-05-26 19:02:47 -07:00
setNewProjectModalOpen(true)
2024-05-05 12:55:34 -07:00
}}
className="mb-4"
>
<Plus className="w-4 h-4 mr-2" />
New Project
</CustomButton>
<Button
variant="ghost"
onClick={() => setScreen("projects")}
className={activeScreen("projects")}
>
<FolderDot className="w-4 h-4 mr-2" />
My Projects
</Button>
<Button
variant="ghost"
onClick={() => setScreen("shared")}
className={activeScreen("shared")}
>
<Users className="w-4 h-4 mr-2" />
Shared With Me
</Button>
2024-05-01 08:53:37 -04:00
{/* <Button
variant="ghost"
onClick={() => setScreen("settings")}
className={activeScreen("settings")}
>
<Settings className="w-4 h-4 mr-2" />
Settings
2024-05-01 08:53:37 -04:00
</Button> */}
</div>
<div className="flex flex-col">
2024-05-07 21:19:32 -07:00
<a target="_blank" href="https://github.com/ishaan1013/sandbox">
2024-05-01 08:53:37 -04:00
<Button
variant="ghost"
2024-05-26 19:02:47 -07:00
className="justify-start w-full font-normal text-muted-foreground"
2024-05-01 08:53:37 -04:00
>
<Code2 className="w-4 h-4 mr-2" />
GitHub Repository
</Button>
2024-05-07 21:19:32 -07:00
</a>
<Button
2024-05-05 00:06:10 -07:00
onClick={() => setAboutModalOpen(true)}
variant="ghost"
className="justify-start font-normal text-muted-foreground"
>
<HelpCircle className="w-4 h-4 mr-2" />
About
</Button>
</div>
2024-04-16 16:25:21 -04:00
</div>
{screen === "projects" ? (
2024-05-22 19:35:19 -07:00
<>
{sandboxes ? (
<DashboardProjects sandboxes={sandboxes} q={q} />
) : null}
</>
) : screen === "shared" ? (
2024-05-01 02:49:25 -04:00
<DashboardSharedWithMe shared={shared} />
) : screen === "settings" ? null : null}
2024-04-16 16:25:21 -04:00
</div>
</>
2024-05-26 19:02:47 -07:00
)
2024-04-16 16:25:21 -04:00
}