Fixed entities

This commit is contained in:
2025-11-11 21:03:34 +01:00
parent 02c2543b3a
commit 74015e1f0a
4 changed files with 94 additions and 61 deletions
+2 -2
View File
@@ -51,8 +51,8 @@ export default function AppSidebar({
</SidebarHeader>
<SidebarContent>
<SidebarMenu>
{workspace.entities.map((entity, i) => (
<EntitySwitch entity={entity} key={i} />
{workspace.entityLayout.map((entity, i) => (
<EntitySwitch entity={entity} workspace={workspace} key={i} />
))}
</SidebarMenu>
</SidebarContent>
+54 -37
View File
@@ -9,44 +9,61 @@ import {
} from "../ui/sidebar";
import { Collapsible, CollapsibleContent } from "../ui/collapsible";
import { ChevronDown } from "lucide-react";
import { Entity } from "@/hooks/workspace";
import { Workspace } from "@/hooks/workspace";
export interface SidebarEntity extends Entity {
kind: "group" | "todo";
children?: SidebarEntity[];
}
export type SidebarEntity =
| {
kind: "group";
name: string;
children: SidebarEntity[];
}
| {
kind?: "item";
id: string;
};
export default function EntitySwitch({ entity }: { entity: SidebarEntity }) {
switch (entity.kind) {
case "group":
return (
<Collapsible defaultOpen className="group/collapsible">
<SidebarGroup>
<SidebarGroupLabel asChild>
<SidebarMenuButton asChild>
<CollapsibleTrigger>
{entity.name}
<ChevronDown className="ml-auto transition-transform group-data-[state=open]/collapsible:rotate-180" />
</CollapsibleTrigger>
</SidebarMenuButton>
</SidebarGroupLabel>
<CollapsibleContent>
<SidebarGroupContent>
<SidebarMenu>
{entity.children?.map((entity, i) => (
<EntitySwitch entity={entity} key={i} />
))}
</SidebarMenu>
</SidebarGroupContent>
</CollapsibleContent>
</SidebarGroup>
</Collapsible>
);
case "todo":
return (
<SidebarMenuItem>
<SidebarMenuButton>{entity.name}</SidebarMenuButton>
</SidebarMenuItem>
);
export default function EntitySwitch({
entity,
workspace,
}: {
entity: SidebarEntity;
workspace: Workspace;
}) {
if (entity.kind === "group") {
return (
<Collapsible defaultOpen className="group/collapsible">
<SidebarGroup>
<SidebarGroupLabel asChild>
<SidebarMenuButton asChild>
<CollapsibleTrigger>
{entity.name}
<ChevronDown className="ml-auto transition-transform group-data-[state=open]/collapsible:rotate-180" />
</CollapsibleTrigger>
</SidebarMenuButton>
</SidebarGroupLabel>
<CollapsibleContent>
<SidebarGroupContent>
<SidebarMenu>
{entity.children?.map((entity, i) => (
<EntitySwitch entity={entity} workspace={workspace} key={i} />
))}
</SidebarMenu>
</SidebarGroupContent>
</CollapsibleContent>
</SidebarGroup>
</Collapsible>
);
} else {
return (
<SidebarMenuItem>
<SidebarMenuButton
onClick={() => {
workspace.setRoute(entity.id);
}}
>
{workspace.entities[entity.id].name}
</SidebarMenuButton>
</SidebarMenuItem>
);
}
}