Skip to content

Frontend reads categories from the API (#91, 3/5) - #242

Draft
NotThaDev wants to merge 4 commits into
feature/91-rules-analyticsfrom
feature/91-frontend-categories
Draft

NotThaDev wants to merge 4 commits into
feature/91-rules-analyticsfrom
feature/91-frontend-categories

Conversation

@NotThaDev

@NotThaDev NotThaDev commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Part 3 of 5 for #91, stacked on #229.

What

  • CategoriesProvider / useCategories() (frontend/stores/categories): the server layout fetches GET /api/categories once and passes it in.
    • It returns categories, byId (an unknown id falls back to Other), byKey, other and the groups per tab.
  • Removed from the frontend: the TransactionCategory enum, the expense/income/movement lists, CategoryColorMap, the selector group definitions and formatCategoryLabel.
    • Names, groups, kinds, icons and colors now come from the DB.
    • createCategoryColors(hex) derives the badge colors.
  • components/common/category/iconRegistry.ts: a curated Lucide map (seed icons plus extras for the PR 4 picker). It is the only category list left in code, because Lucide icons must be imported statically.
  • Transactions, filters (?categoryId=), rules, import and analytics send and read ids.
    • Rule drafts convert legacy enum-name condition values to ids on open and always save ids.
  • lib/models/Category.ts also has the create/update/delete/usage calls used by PR 4.

Why

  • Selector groups come from the DB group column, in seed order; custom categories go last in a "Custom" group.
  • Income/expense tabs come from kind: Expense, Saving and Transfer in the expense tab; Income, Saving and Transfer in the income tab. This matches the old lists.
  • The only hardcoded keys left are the active/passive income labels in analytics/utils.ts, which mirror the backend split.

Screenshots

Transactions page with the category selector open (desktop 800 px, mobile 375 px).

Category selector, desktop
Category selector, mobile

Tested

  • bun run lint and bun run build pass. The project has no frontend unit tests.
  • Worktree API + frontend on an isolated Postgres DB:
    • dashboard, transactions, analytics and rules show system and custom ("Pets") categories by name, color and icon;
    • the filter by categoryId works, as does changing a transaction to the custom category in the drawer;
    • a rule with a legacy "Coffe" condition shows its name, and saving it stores "1"; a new rule targeting Pets saves targetCategoryId 1000;
    • import preview shows category names; no console errors; no horizontal scroll at 375 px.

Notes

  • Old bookmarks with ?category= lose the filter (the param is now categoryId).
  • Inside a group, categories are in id order instead of the old hand-picked order.

Out of scope

  • Categories management page (PR 4), cleanup of the legacy fields and the backfill (PR 5).

🤖 Generated with Claude Code

#91)

A CategoriesProvider in the app layout serves GET /api/categories through
useCategories(). Names, groups, kinds, icons and colors come from the DB; only a
curated Lucide icon registry stays in code. Transactions, rules, import and
analytics send and read category ids; legacy rule condition names are converted
to ids when a rule is saved.
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