128 lines
3.8 KiB
TypeScript
Raw Normal View History

2024-05-07 21:19:32 -07:00
"use client";
2024-04-16 16:25:21 -04:00
2024-05-07 21:19:32 -07:00
import CustomButton from "@/components/ui/customButton";
import { Button } from "@/components/ui/button";
2024-04-16 16:25:21 -04:00
import {
Code2,
FolderDot,
HelpCircle,
Plus,
Settings,
Users,
2024-05-07 21:19:32 -07:00
} from "lucide-react";
import { useState } from "react";
import { Sandbox } from "@/lib/types";
import DashboardProjects from "./projects";
import DashboardSharedWithMe from "./shared";
import NewProjectModal from "./newProject";
import Link from "next/link";
import { useSearchParams } from "next/navigation";
import AboutModal from "./about";
import { toast } from "sonner";
2024-04-16 16:25:21 -04:00
2024-05-07 21:19:32 -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-07 21:19:32 -07:00
sandboxes: Sandbox[];
2024-05-01 02:49:25 -04:00
shared: {
2024-05-07 21:19:32 -07:00
id: string;
name: string;
type: "react" | "node";
author: string;
sharedOn: Date;
}[];
2024-05-01 02:49:25 -04:00
}) {
2024-05-07 21:19:32 -07:00
const [screen, setScreen] = useState<TScreen>("projects");
2024-04-16 16:25:21 -04:00
2024-05-07 21:19:32 -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-07 21:19:32 -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-07 21:19:32 -07:00
const searchParams = useSearchParams();
const q = searchParams.get("q");
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-07 21:19:32 -07:00
toast.error("You reached the maximum # of sandboxes.");
return;
2024-05-05 12:55:34 -07:00
}
2024-05-07 21:19:32 -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"
className="justify-start font-normal text-muted-foreground"
>
<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-01 08:53:37 -04:00
<DashboardProjects sandboxes={sandboxes} q={q} />
) : 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-07 21:19:32 -07:00
);
2024-04-16 16:25:21 -04:00
}