Skip to content

refactor(ui): extract domain hooks and analytics wrappers - #54

Merged
chake111 merged 1 commit into
mainfrom
codex/add-domain-management-to-hooks
Apr 20, 2026
Merged

chake111 merged 1 commit into
mainfrom
codex/add-domain-management-to-hooks

Conversation

@chake111

Copy link
Copy Markdown
Owner

Motivation

  • Centralize and encapsulate UI domain state (search flow, history, favorites, preferences) to reduce duplication and keep pages thin.
  • Unify localStorage handling and authenticated sync for favorites and preferences, and provide a single place for pagination/filters logic and history suggestions.
  • Provide small domain-level tracking wrappers to simplify event parameter assembly and reduce repeated inline tracking code.

Description

  • Added domain hooks: ui/hooks/use-search-flow.ts (search query, request/response, filters, pagination), ui/hooks/use-history.ts (history CRUD, paging, localStorage sync), ui/hooks/use-favorites.ts (local storage + /api/favorites sync, replace/remove helpers), and ui/hooks/use-preferences.ts (storage, reset, serialization, derived reset state).
  • Refactored pages to consume the new hooks: ui/app/[locale]/page.tsx uses useSearchFlow and useHistory, ui/app/[locale]/favorites/page.tsx uses useFavorites, and ui/app/[locale]/preferences/page.tsx uses usePreferences.
  • Kept core tracking implementation in ui/lib/track.ts and added small wrapper functions trackSearch, trackFavorite, trackCompare, and trackDetailView to standardize event payload construction used by pages.
  • Migrated existing FAVORITES_STORAGE_KEY and PREFERENCES_STORAGE_KEY logic into the corresponding hooks and removed duplicated state/IO from pages.

Testing

  • Ran TypeScript checks with cd ui && npm run typecheck, which completed successfully.
  • Ran linter with cd ui && npm run lint, which failed due to a missing ESLint flat config (project lacks eslint.config.*), so lint errors are unrelated to the introduced code shape.

Codex Task

@vercel

vercel Bot commented Apr 20, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ai-tool-picker Ready Ready Preview, Comment Apr 20, 2026 7:37am

@chake111
chake111 merged commit fbfb085 into main Apr 20, 2026
2 of 3 checks passed

This branch was successfully deployed

1 active deployment
Preview e55eaf3e Deployed Apr 20, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant