Fixed entities
This commit is contained in:
@@ -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>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user