Skip to content

Conversation

@jask1m
Copy link
Collaborator

@jask1m jask1m commented Dec 16, 2025

In the admin dashboard, the search experience for user dashboard only filters candidates upon clicking Enter. This PR improves the search experience by filtering realtime on each query keystroke. This workaround also reduces the frequency of API calls to the initial load and delete requests rather than at each search filter (because filtering happens on client now).

  • Implemented instant search that filters users as they type in the search box
  • Fetch all users once on page load using page: -1 parameter instead of paginated requests
  • Updated backend to support page: -1 for fetching all users without pagination

Testing:
Sign in with: (email: test@one.sce, pw: sce)
link: https://unstultifying-barrable-patty.ngrok-free.dev/

* Implemented instant search that filters users as they type in the search box
* Fetch all users once on page load using page: -1 parameter instead of paginated requests
* Updated backend to support page: -1 for fetching all users without pagination
@jask1m jask1m force-pushed the feature/live-user-search branch from c583f2c to eb7c637 Compare December 16, 2025 08:40
Copy link
Collaborator

@evanugarte evanugarte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

holy vibecoded 😭✌️

Comment on lines +91 to +99
let filtered = allUsers;
if (query.trim()) {
const searchTerm = query.trim().toLowerCase();
filtered = allUsers.filter(user => {
return (
user.firstName?.toLowerCase().includes(searchTerm) ||
user.lastName?.toLowerCase().includes(searchTerm) ||
user.email?.toLowerCase().includes(searchTerm)
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not have the backend do this filtering? thats what wee did before this pr

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I filter here on client so I can do a live search result update as user edits query, rather than making an API after a user clicks enter each time.

Comment on lines +104 to +129
if (currentSortOrder !== 'none') {
filtered = [...filtered].sort((a, b) => {
const aVal = a[currentSortColumn];
const bVal = b[currentSortColumn];

// Handle null/undefined
if (aVal == null && bVal == null) return 0;
if (aVal == null) return 1;
if (bVal == null) return -1;

// Compare based on type
let comparison = 0;
if (typeof aVal === 'string') {
comparison = aVal.localeCompare(bVal);
} else if (typeof aVal === 'number') {
comparison = aVal - bVal;
} else {
// Handle dates
const dateA = new Date(aVal);
const dateB = new Date(bVal);
comparison = dateA.getTime() - dateB.getTime();
}

return currentSortOrder === 'asc' ? comparison : -comparison;
});
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100% the job of the backend, not here

Comment on lines +152 to +156
if (pageNum === -1) {
// Fetch all users (no pagination)
skip = 0;
limit = 0; // MongoDB uses 0 to mean "no limit"
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a situation where we want to fetch every user ever

the pagination approach we have seems fine to me

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rationale for this was that the initial load fetches all users and the client will handle filtering. I think the other approach to get the ux I want for search would be to debounce api calls as user types query but filtering on client seemed more appropriate.

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.

3 participants