Skip to content

refactor: implement component architecture and custom hooks#3

Open
modojodo wants to merge 1 commit intorefactor/nextjs-app-router-patternsfrom
feature/performance-optimizations
Open

refactor: implement component architecture and custom hooks#3
modojodo wants to merge 1 commit intorefactor/nextjs-app-router-patternsfrom
feature/performance-optimizations

Conversation

@modojodo
Copy link
Copy Markdown
Owner

Depends on #2

Component Architecture & Custom Hooks Refactor

Overview

This PR refactors the advocate search functionality into a clean, maintainable component architecture with custom hooks and improved user experience.

Key Changes

Component Architecture

  • Extracted sub-components: SearchFilters, AdvocateTable, LoadingState, ErrorState, EmptyState
  • Reusable table headers: SortableHeader and StaticHeader components
  • Separation of concerns: Each component has a single responsibility

Custom Hooks

  • useAdvocates: Data fetching with loading/error states
  • useAdvocateFilters: Client-side filtering, sorting, and search logic
  • useSearchParams: URL parameter management and updates

URL State Management

  • Shareable URLs: Search state preserved in URL parameters
  • State persistence: Filters restored on page refresh
  • No page reloads: Uses router.replace() for smooth navigation

User Experience

  • Loading states: Clean loading indicators
  • Empty states: User-friendly "no results" message
  • Clear search button: Easy way to clear search input
  • Instant filtering: Real-time search without API calls

Benefits

  • Maintainable: Logic separated by concern, easier to modify
  • Testable: Each hook/component can be tested independently
  • Reusable: Hooks and components can be used in other parts of the app
  • User-friendly: Better loading states, error handling, and navigation
  • Developer-friendly: Clean, readable code with clear separation of concerns

Documentation

Added comprehensive DISCUSSION.md documenting server-side improvements for future scale with hundreds of thousands of advocates.

- Extract reusable logic into custom hooks (useAdvocates, useAdvocateFilters, useSearchParams)
- Break down large components into focused sub-components
- Add URL search params for shareable links and state persistence
- Implement proper loading, error, and empty states
- Create reusable table header components (SortableHeader, StaticHeader)
- Add clear search button for better UX
- Document server-side improvements in DISCUSSION.md
- Remove unused variables and clean up imports

Improves maintainability, reusability, and user experience while keeping
client-side filtering approach for current dataset size.
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