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)}`; `${prefix}_${Math.random().toString(36).slice(2, 9)}`;
export default function Workspace() { export default function Workspace() {
const [tasks, setTasks] = useState<Task[]>([]); const [route, setRoute] = useState("");
const workspace = useWorkspace(); const workspace = useWorkspace();
const createTask = (status: string) => { const createTask = (status: string) => {
@@ -20,28 +20,34 @@ export default function Workspace() {
title: "New task", title: "New task",
status: status, status: status,
}; };
setTasks((c) => [...c, task]); workspace.entityData[workspace.route].setTasks((c: Task[]) => [...c, task]);
}; };
return ( return (
<AppSidebar workspace={workspace}> <AppSidebar workspace={workspace}>
<SidebarTrigger className="w-full px-4"> <Router route={route} setRoute={setRoute}>
<div className="px-4"> {(route) => (
<header className="w-full border-b-2 pb-3 pt-2 hover:bg-accent/20"> <>
Workspace <SidebarTrigger className="w-full px-4">
</header> <div className="px-4">
</div> <header className="w-full border-b-2 pb-3 pt-2 hover:bg-accent/20">
</SidebarTrigger> Workspace
<TaskView </header>
tasks={tasks} </div>
setTasks={setTasks} </SidebarTrigger>
createTask={createTask} <TaskView
tags={{ tasks={workspace.entityData[workspace.route].setTasks}
website: { color: "yellow", name: "Website" }, setTasks={workspace.entityData[workspace.route].tasks}
api: { color: "purple", name: "API" }, createTask={createTask}
app: { color: "blue", name: "App" }, tags={{
}} website: { color: "yellow", name: "Website" },
/> api: { color: "purple", name: "API" },
app: { color: "blue", name: "App" },
}}
/>
</>
)}
</Router>
</AppSidebar> </AppSidebar>
); );
} }
+4 -5
View File
@@ -9,15 +9,14 @@ 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";
export interface Entity { export interface SidebarEntity extends Entity {
id: string;
name: string;
kind: "group" | "todo"; kind: "group" | "todo";
children?: Entity[]; children?: SidebarEntity[];
} }
export default function EntitySwitch({ entity }: { entity: Entity }) { export default function EntitySwitch({ entity }: { entity: SidebarEntity }) {
switch (entity.kind) { switch (entity.kind) {
case "group": case "group":
return ( return (
+37 -5
View File
@@ -1,17 +1,42 @@
import { Entity } from "@/components/sidebar/Entity"; import { SidebarEntity } from "@/components/sidebar/Entity";
import { SetState } from "@/lib/types"; import { SetState, Task } from "@/lib/types";
import { useState } from "react"; import { useEffect, useState } from "react";
export interface Entity {
id: string;
name: string;
}
export type Workspace = { export type Workspace = {
name: string; name: string;
entities: Entity[]; entities: SidebarEntity[];
entityData: Record<string, any>;
route: string; route: string;
setRoute: SetState<string>; setRoute: SetState<string>;
}; };
function useTasks() {
return useState<Task[]>([]);
}
export default function useWorkspace(): Workspace { 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 { return {
name: "Personal Workspace", name: "Personal Workspace",
@@ -24,6 +49,13 @@ export default function useWorkspace(): Workspace {
}, },
], ],
entityData: {
alpha_tasks: {
tasks,
setTasks,
},
},
route, route,
setRoute, setRoute,
}; };