diff --git a/app/src/lib/store.test.ts b/app/src/lib/store.test.ts index 2b52252..937399c 100644 --- a/app/src/lib/store.test.ts +++ b/app/src/lib/store.test.ts @@ -124,3 +124,37 @@ describe("area lens", () => { expect(spawned.area).toBe("work"); }); }); + +describe("someday tasks that belong to a project", () => { + const somedayIds = () => store.tasksByStatus(store.getState(), "someday").map((t) => t.id); + + test("stay off the Someday list while their project is live", () => { + const proj = store.createProject({ name: "Move to USA" }); + const loose = store.createTask({ title: "learn the cello", status: "someday" }); + const step = store.createTask({ title: "ship the boxes", status: "someday", project_id: proj.id }); + + expect(somedayIds()).toContain(loose.id); + expect(somedayIds()).not.toContain(step.id); + // still counted on the project, so it is reachable from the Projects list + expect(store.openTaskCount(store.getState(), proj.id)).toBe(1); + }); + + test("come back to Someday when the project is dropped or completed", () => { + const proj = store.createProject({ name: "Old idea" }); + const step = store.createTask({ title: "parked step", status: "someday", project_id: proj.id }); + expect(somedayIds()).not.toContain(step.id); + + store.updateProject(proj.id, { status: "completed" }); + expect(somedayIds()).toContain(step.id); + + store.updateProject(proj.id, { status: "active" }); + store.dropProject(proj.id); + expect(somedayIds()).toContain(step.id); + }); + + test("other lists are unaffected by project membership", () => { + const proj = store.createProject({ name: "Things to Buy" }); + const next = store.createTask({ title: "buy towel", status: "next", project_id: proj.id }); + expect(store.tasksByStatus(store.getState(), "next").map((t) => t.id)).toContain(next.id); + }); +}); diff --git a/app/src/lib/store.ts b/app/src/lib/store.ts index 79d5363..ac28427 100644 --- a/app/src/lib/store.ts +++ b/app/src/lib/store.ts @@ -369,8 +369,22 @@ function byManualOrder(a: Task, b: Task): number { return a.sort_order - b.sort_order || byPriorityDue(a, b); } +/** + * A someday task that belongs to a project lives on that project's page, not in + * the Someday list — otherwise a project's parked steps drown the real + * someday/maybe ideas. Tasks whose project is gone, dropped or completed stay + * in Someday so they can never become invisible. + */ +function shownOnProjectPage(s: State, t: Task): boolean { + if (!t.project_id) return false; + const p = s.projects.find((x) => x.id === t.project_id); + return !!p && p.status !== "dropped" && p.status !== "completed"; +} + export function tasksByStatus(s: State, status: Task["status"]): Task[] { - return inArea(s, s.tasks).filter((t) => t.status === status).sort(byManualOrder); + return inArea(s, s.tasks) + .filter((t) => t.status === status && !(status === "someday" && shownOnProjectPage(s, t))) + .sort(byManualOrder); } /**