This document details the implementation of the electives search and filtering feature for the StrellerMinds Frontend application. The feature provides comprehensive search, filtering, and pagination capabilities for elective courses using mock data and in-memory processing.
- Real-time search with 300ms debouncing for optimal performance
- Multi-field search across elective name, description, instructor, and tags
- Case-insensitive matching for better user experience
- Clear search functionality with visual feedback
- Category filter - Dropdown with all available categories
- Credit hours filter - Options for 1-5+ credits
- Difficulty level filter - Beginner, Intermediate, Advanced
- Expandable filter panel to save screen space
- Active filter display with individual removal options
- Clear all filters functionality
- Client-side pagination with configurable items per page (6 items)
- Smart pagination controls with ellipsis for large page counts
- Page state preservation in URL parameters
- Smooth scrolling to top when changing pages
- Query parameter synchronization for all filters and pagination
- Shareable URLs that preserve filter state
- Browser history integration without page reloads
- Deep linking support for specific filter combinations
src/
├── app/electives/
│ ├── page.tsx # Main electives page component
│ ├── loading.tsx # Loading skeleton UI
│ └── error.tsx # Error boundary component
├── components/
│ ├── ElectiveCard.tsx # Individual elective display
│ ├── ElectiveFilters.tsx # Search and filter controls
│ └── ElectivePagination.tsx # Pagination component
└── lib/
└── electives-data.ts # Mock data and interfaces
interface ElectiveData {
id: string;
name: string;
description: string;
category: string;
creditHours: number;
instructor: string;
level: 'Beginner' | 'Intermediate' | 'Advanced';
duration: string;
prerequisites?: string[];
studentsEnrolled: number;
rating: number;
reviewCount: number;
imageUrl?: string;
tags: string[];
dateAdded: string;
popularity: number;
isActive: boolean;
}const { filteredElectives, totalPages, totalResults } = useMemo(() => {
// Chain multiple filters efficiently
let filtered = allElectives.filter((elective) => elective.isActive);
// Apply search, category, credit hours, and level filters
// Calculate pagination
return { filteredElectives, totalPages, totalResults };
}, [
searchTerm,
selectedCategory,
selectedCreditHours,
selectedLevel,
currentPage,
]);useEffect(() => {
const timer = setTimeout(() => {
onFilterChange.search(debouncedSearchTerm);
}, 300);
return () => clearTimeout(timer);
}, [debouncedSearchTerm, onFilterChange]);- Memoized filter functions prevent unnecessary recalculations
- Optimized component structure minimizes re-render scope
- Smart state management reduces cascading updates
The search functionality implements a comprehensive multi-field search:
if (searchTerm) {
const searchLower = searchTerm.toLowerCase();
filtered = filtered.filter(
(elective) =>
elective.name.toLowerCase().includes(searchLower) ||
elective.description.toLowerCase().includes(searchLower) ||
elective.instructor.toLowerCase().includes(searchLower) ||
elective.tags.some((tag) => tag.toLowerCase().includes(searchLower)),
);
}Search Features:
- Partial matching - Finds results containing the search term
- Multi-field search - Searches across name, description, instructor, and tags
- Case-insensitive - Works regardless of input case
- Tag search - Includes hashtag-style tags in search results
Filters are applied in sequence for optimal performance:
- Base filter - Only active electives
- Search filter - Text-based matching
- Category filter - Exact category matching
- Credit hours filter - Numeric matching with special "5+" handling
- Level filter - Exact level matching
- Pagination - Data slicing for current page
The application maintains filter state in URL parameters:
// URL format: /electives?search=blockchain&category=Development&credits=3&level=Advanced&page=2
useEffect(() => {
const params = new URLSearchParams();
if (searchTerm) params.set('search', searchTerm);
if (selectedCategory) params.set('category', selectedCategory);
if (selectedCreditHours) params.set('credits', selectedCreditHours);
if (selectedLevel) params.set('level', selectedLevel);
if (currentPage > 1) params.set('page', currentPage.toString());
const queryString = params.toString();
const newUrl = queryString ? `/electives?${queryString}` : '/electives';
window.history.replaceState({}, '', newUrl);
}, [
searchTerm,
selectedCategory,
selectedCreditHours,
selectedLevel,
currentPage,
]);- Mobile-first approach with responsive grid layouts
- Collapsible filters on smaller screens
- Touch-friendly controls for mobile devices
- Adaptive pagination that works on all screen sizes
- ARIA labels for screen readers
- Keyboard navigation support
- Focus management for interactive elements
- Semantic HTML structure
- Color contrast compliance
- Empty state with helpful messaging and clear filters action
- Error boundaries for graceful failure handling
- Loading states with skeleton UI
- Input validation with maximum length limits
- Graceful degradation when JavaScript is disabled
- Active filter indicators with count badges
- Hover states for interactive elements
- Loading animations during state changes
- Clear visual hierarchy with proper typography
- Consistent color coding for categories and levels
The implementation includes 12 diverse elective courses across various categories:
- Ethics & Philosophy - Blockchain Ethics and Governance
- Economics - Cryptocurrency Economics
- Design - Web3 User Experience Design
- Development - Advanced DeFi Protocol Development
- Art & Creativity - NFT Art Creation and Marketplace
- Law & Regulation - Blockchain and Legal Frameworks
- Trading & Finance - Advanced Cryptocurrency Trading
- Governance - DAO Creation and Governance
- Sustainability - Sustainable Blockchain Technologies
- Virtual Reality - Metaverse and Virtual Worlds
- Security - Blockchain Security Auditing
- Media & Communication - Cryptocurrency Journalism
Each elective includes comprehensive metadata for realistic filtering and search scenarios.
- Search for "blockchain" - should return multiple results
- Search for instructor names - should filter by instructor
- Search for tags like "DeFi" or "NFT" - should match tag-based results
- Empty search - should show all electives
- Select different categories - should filter appropriately
- Choose credit hour ranges - should match credit requirements
- Select difficulty levels - should filter by level
- Combine multiple filters - should apply all filters simultaneously
- Navigate through pages - should maintain filter state
- Change filters - should reset to page 1
- Direct URL access - should load correct page with filters
- Share filtered URL - should load with same filters applied
- Browser back/forward - should maintain state
- Refresh page - should preserve current filter state
- Initial load time - Optimized with skeleton loading
- Search response time - 300ms debounce prevents excessive filtering
- Filter application - Instant with useMemo optimization
- Memory usage - Efficient with proper cleanup and memoization
- Bundle size impact - Minimal additional dependencies
- Server-side filtering for larger datasets
- Advanced search operators (AND, OR, NOT)
- Saved search preferences with local storage
- Sort functionality (by rating, popularity, date)
- Infinite scroll as alternative to pagination
- Search analytics and popular searches
- Filter presets for common combinations
- Export functionality for filtered results
- Current implementation handles hundreds of electives efficiently
- For thousands of items, consider virtual scrolling or server-side pagination
- Search indexing would improve performance for large datasets
- Caching strategies could optimize repeated filter operations
The electives search and filtering implementation provides a comprehensive, performant, and user-friendly solution for browsing educational content. The architecture is scalable, maintainable, and follows React/Next.js best practices while delivering an excellent user experience across all devices.