Skip to content

feat: add category picker to the task form - #36

Merged
TechnicPotato merged 1 commit into
mainfrom
category-picker
Dec 2, 2026
Merged

TechnicPotato merged 1 commit into
mainfrom
category-picker

Conversation

@TechnicPotato

Copy link
Copy Markdown
Owner

Summary

Phase 3, step 6a: the add-task form gets a category picker, so a task can be put in an existing category when it's created. It defaults to Uncategorised.

Creating, renaming and deleting categories from the UI is the next PR (6b). Until then, categories can only be created through POST /api/categories, so the picker on the live site will list only Uncategorised.

How it works

  • NewTaskForm (new, server component) loads the categories and passes them to AddTaskForm as a prop. It has its own <Suspense> boundary, so the form and the task list stream in independently, and neither waits for the other.
  • AddTaskForm (client component) shows a <select name="categoryId">.
    • The empty option is Uncategorised and is sent as null, the same way an empty due date is.
    • Validation errors for categoryId show under the field.
    • "Category not found." (a category deleted after the page loaded) shows as a form error.
  • After a successful submit, router.refresh() re-runs the server components, so categories added in 6b will appear in the picker with no extra code.

Loading the categories in a server component, rather than with a useEffect fetch in the form, avoids an extra request from the browser and a picker that briefly appears empty. Loading them in page.tsx would have made the whole page wait for the data.

Refactor

UNCATEGORISED_LABEL moved from lib/categories/schemas.ts to a new, dependency-free lib/categories/constants.ts. The client form can now use it without pulling Zod into the browser bundle. The picker, the task list and the reserved-name validation rule all use this one definition.

Testing

  • Typecheck, lint and format check are clean, and all tests pass. There are no UI tests yet; they're planned for Phase 6.
  • Checked manually: a task created with a category picked shows that category's name, and one created without shows Uncategorised.

Not in this PR

  • Category management UI: create, rename and delete (6b).
  • Grouping and filtering by category (step 7).

@TechnicPotato
TechnicPotato merged commit 9e59869 into main Dec 2, 2026
4 checks passed
@TechnicPotato
TechnicPotato deleted the category-picker branch December 2, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant