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
+10 -4
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,11 +20,14 @@ 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}>
<Router route={route} setRoute={setRoute}>
{(route) => (
<>
<SidebarTrigger className="w-full px-4"> <SidebarTrigger className="w-full px-4">
<div className="px-4"> <div className="px-4">
<header className="w-full border-b-2 pb-3 pt-2 hover:bg-accent/20"> <header className="w-full border-b-2 pb-3 pt-2 hover:bg-accent/20">
@@ -33,8 +36,8 @@ export default function Workspace() {
</div> </div>
</SidebarTrigger> </SidebarTrigger>
<TaskView <TaskView
tasks={tasks} tasks={workspace.entityData[workspace.route].setTasks}
setTasks={setTasks} setTasks={workspace.entityData[workspace.route].tasks}
createTask={createTask} createTask={createTask}
tags={{ tags={{
website: { color: "yellow", name: "Website" }, website: { color: "yellow", name: "Website" },
@@ -42,6 +45,9 @@ export default function Workspace() {
app: { color: "blue", name: "App" }, 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,
}; };