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