75 lines
2.4 KiB
TypeScript
75 lines
2.4 KiB
TypeScript
"use client";
|
|
|
|
import Router from "@/components/Router";
|
|
import AppSidebar, { SidebarTrigger } from "@/components/sidebar/AppSidebar";
|
|
import { useWorkspace } from "@/hooks/workspace";
|
|
import { ChevronRight } from "lucide-react";
|
|
import Cookies from "js-cookie";
|
|
import { useEffect, useState } from "react";
|
|
import { Route } from "@/lib/types";
|
|
import { Button } from "@/components/ui/button";
|
|
import {
|
|
createDefaultWorkspace,
|
|
saveWorkspaceToLocalStorage,
|
|
} from "@/lib/workspace";
|
|
|
|
export default function Workspace() {
|
|
const [currentWorkspace, setCurrentWorkspace] = useState<string>();
|
|
|
|
const { workspace, loadWorkspace, updateEntity, setWorkspace } =
|
|
useWorkspace();
|
|
|
|
const [route, setRoute] = useState<Route>({});
|
|
|
|
useEffect(() => {
|
|
setCurrentWorkspace(Cookies.get("workspace"));
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
loadWorkspace(currentWorkspace);
|
|
if (currentWorkspace) Cookies.set("workspace", currentWorkspace);
|
|
else Cookies.remove("workspace");
|
|
}, [currentWorkspace]);
|
|
|
|
if (!workspace) {
|
|
return (
|
|
<main
|
|
className="flex h-svh items-center justify-center bg-gradient-to-br from-blue-50 to-indigo-100 dark:from-slate-900 dark:to-slate-800"
|
|
onClick={() => {
|
|
const w = createDefaultWorkspace();
|
|
saveWorkspaceToLocalStorage(w);
|
|
setCurrentWorkspace(w.id);
|
|
}}
|
|
>
|
|
<div className="text-center space-y-6">
|
|
<h1 className="text-4xl font-bold">Welcome to Drift</h1>
|
|
<p className="text-lg text-muted-foreground">
|
|
Your personal productivity workspace
|
|
</p>
|
|
<Button size="lg" className="text-base">
|
|
Create a new workspace
|
|
</Button>
|
|
</div>
|
|
</main>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<AppSidebar workspace={workspace} setRoute={setRoute}>
|
|
<SidebarTrigger className="w-full px-4">
|
|
<div className="px-4">
|
|
<header className="w-full border-b pb-3 pt-2 hover:bg-accent/20 flex items-center text-foreground/90 gap-2">
|
|
<span className="font-semibold">{workspace.name}</span>
|
|
<ChevronRight className="h-5 text-muted-foreground" />
|
|
<span className="text-muted-foreground">
|
|
{workspace.entities[route.entity || ""]?.name || "Select an item"}
|
|
</span>
|
|
</header>
|
|
</div>
|
|
</SidebarTrigger>
|
|
|
|
<Router workspace={workspace} route={route} updateEntity={updateEntity} />
|
|
</AppSidebar>
|
|
);
|
|
}
|