diff --git a/TODO.md b/TODO.md index 163c2842..991a38f7 100644 --- a/TODO.md +++ b/TODO.md @@ -6,7 +6,7 @@ - [x] Projects should be sorted by latest thread update - [x] Submitting new messages should scroll to bottom — [#13](https://github.com/OpenKnots/okcode/issues/13) - [ ] Thread archiving — [#10](https://github.com/OpenKnots/okcode/issues/10) -- [ ] New projects should go on top — [#11](https://github.com/OpenKnots/okcode/issues/11) +- [x] New projects should go on top — [#11](https://github.com/OpenKnots/okcode/issues/11) ## Bigger things diff --git a/apps/web/src/components/Sidebar.logic.test.ts b/apps/web/src/components/Sidebar.logic.test.ts index b1d3b3aa..8793d78f 100644 --- a/apps/web/src/components/Sidebar.logic.test.ts +++ b/apps/web/src/components/Sidebar.logic.test.ts @@ -670,6 +670,46 @@ describe("sortProjectsForSidebar", () => { ]); }); + it("sorts a newly created project (no threads) above an older project with thread activity", () => { + const sorted = sortProjectsForSidebar( + [ + makeProject({ + id: ProjectId.makeUnsafe("project-1"), + name: "Old active project", + createdAt: "2026-01-01T00:00:00.000Z", + updatedAt: "2026-01-01T00:00:00.000Z", + }), + makeProject({ + id: ProjectId.makeUnsafe("project-2"), + name: "New project", + createdAt: "2026-03-09T10:10:00.000Z", + updatedAt: "2026-03-09T10:10:00.000Z", + }), + ], + [ + makeThread({ + projectId: ProjectId.makeUnsafe("project-1"), + messages: [ + { + id: "message-1" as never, + role: "user", + text: "recent activity", + createdAt: "2026-03-09T10:05:00.000Z", + streaming: false, + completedAt: "2026-03-09T10:05:00.000Z", + }, + ], + }), + ], + "updated_at", + ); + + expect(sorted.map((project) => project.id)).toEqual([ + ProjectId.makeUnsafe("project-2"), + ProjectId.makeUnsafe("project-1"), + ]); + }); + it("returns the project timestamp when no threads are present", () => { const timestamp = getProjectSortTimestamp( makeProject({ updatedAt: "2026-03-09T10:10:00.000Z" }),