diff --git a/src/app/workspace/page.tsx b/src/app/workspace/page.tsx index 4a60eea..517fd54 100644 --- a/src/app/workspace/page.tsx +++ b/src/app/workspace/page.tsx @@ -11,7 +11,7 @@ const id = (prefix = "t") => `${prefix}_${Math.random().toString(36).slice(2, 9)}`; export default function Workspace() { - const [tasks, setTasks] = useState([]); + const [route, setRoute] = useState(""); const workspace = useWorkspace(); const createTask = (status: string) => { @@ -20,28 +20,34 @@ export default function Workspace() { title: "New task", status: status, }; - setTasks((c) => [...c, task]); + workspace.entityData[workspace.route].setTasks((c: Task[]) => [...c, task]); }; return ( - -
-
- Workspace -
-
-
- + + {(route) => ( + <> + +
+
+ Workspace +
+
+
+ + + )} +
); } diff --git a/src/components/sidebar/Entity.tsx b/src/components/sidebar/Entity.tsx index 34c68cb..9a7d75a 100644 --- a/src/components/sidebar/Entity.tsx +++ b/src/components/sidebar/Entity.tsx @@ -9,15 +9,14 @@ import { } from "../ui/sidebar"; import { Collapsible, CollapsibleContent } from "../ui/collapsible"; import { ChevronDown } from "lucide-react"; +import { Entity } from "@/hooks/workspace"; -export interface Entity { - id: string; - name: string; +export interface SidebarEntity extends Entity { kind: "group" | "todo"; - children?: Entity[]; + children?: SidebarEntity[]; } -export default function EntitySwitch({ entity }: { entity: Entity }) { +export default function EntitySwitch({ entity }: { entity: SidebarEntity }) { switch (entity.kind) { case "group": return ( diff --git a/src/hooks/workspace.ts b/src/hooks/workspace.ts index 7aac325..dd1a9a2 100644 --- a/src/hooks/workspace.ts +++ b/src/hooks/workspace.ts @@ -1,17 +1,42 @@ -import { Entity } from "@/components/sidebar/Entity"; -import { SetState } from "@/lib/types"; -import { useState } from "react"; +import { SidebarEntity } from "@/components/sidebar/Entity"; +import { SetState, Task } from "@/lib/types"; +import { useEffect, useState } from "react"; + +export interface Entity { + id: string; + name: string; +} export type Workspace = { name: string; - entities: Entity[]; + entities: SidebarEntity[]; + entityData: Record; route: string; setRoute: SetState; }; +function useTasks() { + return useState([]); +} + export default function useWorkspace(): Workspace { - const [route, setRoute] = useState(""); + const [route, setRoute] = useState("alpha_tasks"); + const [tasks, setTasks] = useTasks(); + + useEffect(() => { + setTasks([ + { id: "1", title: "Buy groceries", status: "todo" }, + { id: "2", title: "Plan sprint", status: "todo" }, + { + id: "3", + title: "Build App", + description: "A simple description", + tags: ["website", "api", "app"], + status: "inprogress", + }, + ]); + }, []); return { name: "Personal Workspace", @@ -24,6 +49,13 @@ export default function useWorkspace(): Workspace { }, ], + entityData: { + alpha_tasks: { + tasks, + setTasks, + }, + }, + route, setRoute, };