Fixed entities
This commit is contained in:
@@ -5,6 +5,7 @@ import AppSidebar, { SidebarTrigger } from "@/components/sidebar/AppSidebar";
|
|||||||
import TaskView from "@/components/view/TaskView";
|
import TaskView from "@/components/view/TaskView";
|
||||||
import useWorkspace from "@/hooks/workspace";
|
import useWorkspace from "@/hooks/workspace";
|
||||||
import { Task } from "@/lib/types";
|
import { Task } from "@/lib/types";
|
||||||
|
import { ChevronRight } from "lucide-react";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
const id = (prefix = "t") =>
|
const id = (prefix = "t") =>
|
||||||
@@ -20,7 +21,7 @@ export default function Workspace() {
|
|||||||
title: "New task",
|
title: "New task",
|
||||||
status: status,
|
status: status,
|
||||||
};
|
};
|
||||||
workspace.entityData[workspace.route].setTasks((c: Task[]) => [...c, task]);
|
workspace.entities[workspace.route].setTasks((c: Task[]) => [...c, task]);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -30,14 +31,16 @@ export default function Workspace() {
|
|||||||
<>
|
<>
|
||||||
<SidebarTrigger className="w-full px-4">
|
<SidebarTrigger className="w-full px-4">
|
||||||
<div className="px-4">
|
<div className="px-4">
|
||||||
<header className="w-full border-b-2 pb-3 pt-2 hover:bg-accent/20">
|
<header className="w-full border-b-2 pb-3 pt-2 hover:bg-accent/20 flex items-center text-foreground/90">
|
||||||
Workspace
|
{workspace.name}
|
||||||
|
<ChevronRight className="h-5" />
|
||||||
|
{workspace.entities[workspace.route].name}
|
||||||
</header>
|
</header>
|
||||||
</div>
|
</div>
|
||||||
</SidebarTrigger>
|
</SidebarTrigger>
|
||||||
<TaskView
|
<TaskView
|
||||||
tasks={workspace.entityData[workspace.route].setTasks}
|
tasks={workspace.entities[workspace.route].tasks}
|
||||||
setTasks={workspace.entityData[workspace.route].tasks}
|
setTasks={workspace.entities[workspace.route].setTasks}
|
||||||
createTask={createTask}
|
createTask={createTask}
|
||||||
tags={{
|
tags={{
|
||||||
website: { color: "yellow", name: "Website" },
|
website: { color: "yellow", name: "Website" },
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ export default function AppSidebar({
|
|||||||
</SidebarHeader>
|
</SidebarHeader>
|
||||||
<SidebarContent>
|
<SidebarContent>
|
||||||
<SidebarMenu>
|
<SidebarMenu>
|
||||||
{workspace.entities.map((entity, i) => (
|
{workspace.entityLayout.map((entity, i) => (
|
||||||
<EntitySwitch entity={entity} key={i} />
|
<EntitySwitch entity={entity} workspace={workspace} key={i} />
|
||||||
))}
|
))}
|
||||||
</SidebarMenu>
|
</SidebarMenu>
|
||||||
</SidebarContent>
|
</SidebarContent>
|
||||||
|
|||||||
@@ -9,16 +9,27 @@ import {
|
|||||||
} from "../ui/sidebar";
|
} from "../ui/sidebar";
|
||||||
import { Collapsible, CollapsibleContent } from "../ui/collapsible";
|
import { Collapsible, CollapsibleContent } from "../ui/collapsible";
|
||||||
import { ChevronDown } from "lucide-react";
|
import { ChevronDown } from "lucide-react";
|
||||||
import { Entity } from "@/hooks/workspace";
|
import { Workspace } from "@/hooks/workspace";
|
||||||
|
|
||||||
export interface SidebarEntity extends Entity {
|
export type SidebarEntity =
|
||||||
kind: "group" | "todo";
|
| {
|
||||||
children?: SidebarEntity[];
|
kind: "group";
|
||||||
|
name: string;
|
||||||
|
children: SidebarEntity[];
|
||||||
}
|
}
|
||||||
|
| {
|
||||||
|
kind?: "item";
|
||||||
|
id: string;
|
||||||
|
};
|
||||||
|
|
||||||
export default function EntitySwitch({ entity }: { entity: SidebarEntity }) {
|
export default function EntitySwitch({
|
||||||
switch (entity.kind) {
|
entity,
|
||||||
case "group":
|
workspace,
|
||||||
|
}: {
|
||||||
|
entity: SidebarEntity;
|
||||||
|
workspace: Workspace;
|
||||||
|
}) {
|
||||||
|
if (entity.kind === "group") {
|
||||||
return (
|
return (
|
||||||
<Collapsible defaultOpen className="group/collapsible">
|
<Collapsible defaultOpen className="group/collapsible">
|
||||||
<SidebarGroup>
|
<SidebarGroup>
|
||||||
@@ -34,7 +45,7 @@ export default function EntitySwitch({ entity }: { entity: SidebarEntity }) {
|
|||||||
<SidebarGroupContent>
|
<SidebarGroupContent>
|
||||||
<SidebarMenu>
|
<SidebarMenu>
|
||||||
{entity.children?.map((entity, i) => (
|
{entity.children?.map((entity, i) => (
|
||||||
<EntitySwitch entity={entity} key={i} />
|
<EntitySwitch entity={entity} workspace={workspace} key={i} />
|
||||||
))}
|
))}
|
||||||
</SidebarMenu>
|
</SidebarMenu>
|
||||||
</SidebarGroupContent>
|
</SidebarGroupContent>
|
||||||
@@ -42,10 +53,16 @@ export default function EntitySwitch({ entity }: { entity: SidebarEntity }) {
|
|||||||
</SidebarGroup>
|
</SidebarGroup>
|
||||||
</Collapsible>
|
</Collapsible>
|
||||||
);
|
);
|
||||||
case "todo":
|
} else {
|
||||||
return (
|
return (
|
||||||
<SidebarMenuItem>
|
<SidebarMenuItem>
|
||||||
<SidebarMenuButton>{entity.name}</SidebarMenuButton>
|
<SidebarMenuButton
|
||||||
|
onClick={() => {
|
||||||
|
workspace.setRoute(entity.id);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{workspace.entities[entity.id].name}
|
||||||
|
</SidebarMenuButton>
|
||||||
</SidebarMenuItem>
|
</SidebarMenuItem>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-17
@@ -2,19 +2,21 @@ import { SidebarEntity } from "@/components/sidebar/Entity";
|
|||||||
import { SetState, Task } from "@/lib/types";
|
import { SetState, Task } from "@/lib/types";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
export interface Entity {
|
export type Entity = {
|
||||||
id: string;
|
|
||||||
name: string;
|
name: string;
|
||||||
}
|
kind: "todo";
|
||||||
|
setTasks: SetState<Task[]>;
|
||||||
|
tasks: Task[];
|
||||||
|
};
|
||||||
|
|
||||||
export type Workspace = {
|
export interface Workspace {
|
||||||
name: string;
|
name: string;
|
||||||
entities: SidebarEntity[];
|
entityLayout: SidebarEntity[];
|
||||||
entityData: Record<string, any>;
|
entities: Record<string, Entity>;
|
||||||
|
|
||||||
route: string;
|
route: string;
|
||||||
setRoute: SetState<string>;
|
setRoute: SetState<string>;
|
||||||
};
|
}
|
||||||
|
|
||||||
function useTasks() {
|
function useTasks() {
|
||||||
return useState<Task[]>([]);
|
return useState<Task[]>([]);
|
||||||
@@ -40,21 +42,32 @@ export default function useWorkspace(): Workspace {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
name: "Personal Workspace",
|
name: "Personal Workspace",
|
||||||
entities: [
|
entities: {
|
||||||
{
|
|
||||||
id: "alpha",
|
|
||||||
name: "Project alpha",
|
|
||||||
kind: "group",
|
|
||||||
children: [{ id: "alpha_tasks", name: "Tasks", kind: "todo" }],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
|
|
||||||
entityData: {
|
|
||||||
alpha_tasks: {
|
alpha_tasks: {
|
||||||
|
name: "Alpha tasks",
|
||||||
|
kind: "todo",
|
||||||
|
tasks,
|
||||||
|
setTasks,
|
||||||
|
},
|
||||||
|
beta_tasks: {
|
||||||
|
name: "Beta tasks",
|
||||||
|
kind: "todo",
|
||||||
tasks,
|
tasks,
|
||||||
setTasks,
|
setTasks,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
entityLayout: [
|
||||||
|
{
|
||||||
|
kind: "group",
|
||||||
|
name: "Project alpha",
|
||||||
|
children: [{ id: "alpha_tasks" }],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
kind: "group",
|
||||||
|
name: "Project beta",
|
||||||
|
children: [{ id: "beta_tasks" }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
route,
|
route,
|
||||||
setRoute,
|
setRoute,
|
||||||
|
|||||||
Reference in New Issue
Block a user