Very awful code

This commit is contained in:
2025-11-11 20:39:42 +01:00
parent 03a8b837b6
commit 02c2543b3a
3 changed files with 66 additions and 29 deletions
+25 -19
View File
@@ -11,7 +11,7 @@ const id = (prefix = "t") =>
`${prefix}_${Math.random().toString(36).slice(2, 9)}`;
export default function Workspace() {
const [tasks, setTasks] = useState<Task[]>([]);
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 (
<AppSidebar workspace={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>
</div>
</SidebarTrigger>
<TaskView
tasks={tasks}
setTasks={setTasks}
createTask={createTask}
tags={{
website: { color: "yellow", name: "Website" },
api: { color: "purple", name: "API" },
app: { color: "blue", name: "App" },
}}
/>
<Router route={route} setRoute={setRoute}>
{(route) => (
<>
<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>
</div>
</SidebarTrigger>
<TaskView
tasks={workspace.entityData[workspace.route].setTasks}
setTasks={workspace.entityData[workspace.route].tasks}
createTask={createTask}
tags={{
website: { color: "yellow", name: "Website" },
api: { color: "purple", name: "API" },
app: { color: "blue", name: "App" },
}}
/>
</>
)}
</Router>
</AppSidebar>
);
}
+4 -5
View File
@@ -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 (
+37 -5
View File
@@ -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<string, any>;
route: string;
setRoute: SetState<string>;
};
function useTasks() {
return useState<Task[]>([]);
}
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,
};