Skip to content

Latest commit

 

History

History
589 lines (418 loc) · 12.5 KB

File metadata and controls

589 lines (418 loc) · 12.5 KB

Marketplace Listings Implementation - Issue #23

Overview

Complete implementation of the secondary market for carbon credits with filtering, sorting, search, and pagination functionality.

Complexity

Medium (150 pts)

Implementation Status

COMPLETE - All requirements implemented and ready for testing


Files Created

1. Type Definitions

File: lib/types/marketplace.ts

  • MarketplaceListing interface - Core listing data structure
  • MarketplaceListResponse interface - API response structure
  • SortOption type - Sort options (price-asc, price-desc, date-newest, date-oldest)
  • Component prop interfaces for all marketplace components
  • TypeScript strict mode compliant

2. Mock API Data

File: lib/api/mock/marketplaceListings.ts

  • 12 diverse mock listings with realistic data
  • getMockMarketplaceListings() function with:
    • Project type filtering
    • Search functionality (project name, seller name, location)
    • Sorting by price and date
    • Server-side pagination (9 items per page)
  • Simulates real API behavior

3. Components

Organism: MarketplaceGrid

File: components/organisms/MarketplaceGrid/MarketplaceGrid.tsx

  • Responsive 3-column grid (1 col mobile, 2 col tablet, 3 col desktop)
  • Empty state with icon and message
  • ARIA live region for screen reader announcements
  • Identifies user's own listings

Molecule: ListingCard

File: components/molecules/ListingCard.tsx

  • Project name and type badge
  • Seller avatar and information
  • Quantity and pricing breakdown
  • Vintage year and verification status
  • Relative time display ("2 days ago")
  • Visual indicator for own listings (blue border)
  • "View Details" button
  • Hover effects and transitions
  • Fully accessible with ARIA labels

Molecule: MarketplaceFilters

File: components/molecules/MarketplaceFilters.tsx

  • Search input with icon and clear button
  • Project type filter dropdown
  • Sort by dropdown (price/date)
  • Active filters display with remove buttons
  • Responsive layout (stacked on mobile, side-by-side on desktop)
  • Accessible with proper labels

4. Pages

Main Marketplace Page

File: app/marketplace/page.tsx

  • Client-side rendered with URL state management
  • Filters, sort, and search with URL params
  • Pagination with URL params
  • Results count display
  • Smooth scroll to top on page change
  • Responsive layout
  • WCAG 2.1 AA compliant

Listing Detail Page

File: app/marketplace/[id]/page.tsx

  • Dynamic route for individual listings
  • Full listing details display
  • Seller information card
  • Project details card
  • Sticky pricing sidebar
  • Purchase button (placeholder for future implementation)
  • Back navigation
  • 404 handling for invalid listing IDs

Features Implemented

✅ Grid of Available Credit Listings

  • Responsive 3-column grid layout
  • Displays: seller, quantity, price, project name, type, location
  • Visual distinction for user's own listings

✅ Filter by Project Type

  • Dropdown with all available project types
  • "All Project Types" option to clear filter
  • Updates URL params
  • Resets to page 1 on filter change

✅ Sort by Price and Date

  • Sort options:
    • Newest First (default)
    • Oldest First
    • Price: Low to High
    • Price: High to Low
  • Updates URL params
  • Resets to page 1 on sort change

✅ Search Functionality

  • Real-time search across:
    • Project name
    • Seller name
    • Location
  • Search input with clear button
  • Updates URL params
  • Resets to page 1 on search

✅ Pagination

  • Server-side pagination (9 items per page)
  • URL params for page number
  • Previous/Next buttons
  • Page numbers with ellipsis for large ranges
  • Compact mobile view (shows "Page X of Y")
  • Full desktop view (shows all page numbers)
  • Smooth scroll to top on page change
  • Preserves filters/sort/search across pages

✅ Click Listing → Detail Page

  • Dynamic route /marketplace/[id]
  • Full listing details
  • Seller information
  • Project metadata
  • Pricing breakdown
  • Purchase action button
  • Back navigation

✅ Responsive Design

  • Mobile-first approach
  • Breakpoints: sm (640px), md (768px), lg (1024px)
  • Grid adapts: 1 col → 2 col → 3 col
  • Filters stack on mobile, side-by-side on desktop
  • Touch-friendly button sizes (min 44x44px)

✅ Accessible (WCAG 2.1 AA)

  • Semantic HTML structure
  • ARIA labels and roles
  • ARIA live regions for dynamic content
  • Keyboard navigation support
  • Focus management
  • Screen reader friendly
  • Color contrast compliance
  • Alt text for icons

✅ TypeScript Strict

  • No any types
  • Proper type definitions
  • Type-safe props
  • Validated with getDiagnostics (0 errors)

Edge Cases Handled

No Listings

  • Empty state with icon and message
  • Helpful text suggesting filter adjustment

Seller is Current User

  • Visual indicator (blue border on card)
  • "Your Listing" badge
  • Passed via currentUserId prop (ready for auth integration)

Stale Prices

  • Timestamps displayed ("Listed 2 days ago")
  • Ready for real-time price updates via API

Invalid Listing ID

  • 404 page with helpful message
  • Back to marketplace button

No Search Results

  • Empty state displayed
  • Active filters shown with remove buttons

URL State Management

  • All filters/sort/search/page in URL
  • Shareable URLs
  • Browser back/forward support
  • Direct URL access works

URL Parameters

The marketplace page uses URL parameters for state management:

/marketplace?type=Reforestation&sort=price-asc&search=amazon&page=2
  • type - Project type filter (optional)
  • sort - Sort option (optional, default: date-newest)
  • search - Search query (optional)
  • page - Page number (optional, default: 1)

Integration Points

Authentication (TODO)

Replace currentUserId={null} in app/marketplace/page.tsx with actual user ID from auth context:

import { useAuth } from "@/contexts/AuthContext";

const { userId } = useAuth();

<MarketplaceGrid
  listings={data.listings}
  currentUserId={userId}
/>

Purchase Flow (TODO)

Implement purchase handler in app/marketplace/[id]/page.tsx:

const handlePurchase = () => {
  router.push(`/marketplace/${listing.id}/purchase`);
};

Real API (TODO)

Replace mock data in app/marketplace/page.tsx:

import { fetchMarketplaceListings } from '@/lib/api/marketplace';

const data = await fetchMarketplaceListings({
  page: currentPage,
  projectType: selectedType,
  sortBy,
  searchQuery,
});

Testing Checklist

Functionality

  • Listings grid loads and displays correctly
  • Filter by project type works
  • Sort by price (asc/desc) works
  • Sort by date (newest/oldest) works
  • Search filters listings correctly
  • Pagination works (prev/next/page numbers)
  • Click listing navigates to detail page
  • Detail page displays all information
  • Back button returns to marketplace
  • URL params update correctly
  • Browser back/forward works
  • Direct URL access works
  • Empty states display correctly

Responsive Design

  • Mobile (< 640px): 1 column grid
  • Tablet (640-1024px): 2 column grid
  • Desktop (> 1024px): 3 column grid
  • Filters stack on mobile
  • Filters side-by-side on desktop
  • Touch targets are 44x44px minimum
  • Text is readable at all sizes

Accessibility

  • Keyboard navigation works
  • Screen reader announces changes
  • Focus indicators visible
  • ARIA labels present
  • Color contrast passes WCAG AA
  • Semantic HTML used
  • Form inputs have labels

Performance

  • Page loads quickly
  • No layout shift
  • Smooth transitions
  • Efficient re-renders

Screen Recording Script

Setup

  1. Open browser to http://localhost:3000/marketplace
  2. Ensure dev server is running
  3. Start screen recording

Demo Flow (2-3 minutes)

1. Initial Load (10 seconds)

  • Show marketplace page loading
  • Point out grid layout with 9 listings
  • Highlight responsive design

2. Filtering (20 seconds)

  • Click project type dropdown
  • Select "Renewable Energy"
  • Show filtered results
  • Point out results count update

3. Sorting (20 seconds)

  • Click sort dropdown
  • Select "Price: Low to High"
  • Show listings reorder
  • Select "Price: High to Low"
  • Show listings reorder again

4. Search (20 seconds)

  • Type "amazon" in search box
  • Show filtered results
  • Click clear button (X)
  • Show all results return

5. Active Filters (15 seconds)

  • Apply project type filter
  • Apply search query
  • Show active filters chips
  • Click X on filter chip to remove
  • Show results update

6. Pagination (20 seconds)

  • Scroll to bottom
  • Click "Next" button
  • Show page 2 loads
  • Show URL updates
  • Click page number
  • Show smooth scroll to top

7. Detail Page (30 seconds)

  • Click "View Details" on a listing
  • Show detail page loads
  • Highlight seller information
  • Highlight project details
  • Highlight pricing sidebar
  • Click "Purchase Credits" button
  • Show placeholder alert

8. Back Navigation (10 seconds)

  • Click "Back to Marketplace"
  • Show return to listings
  • Show filters/page preserved

9. Responsive Demo (20 seconds)

  • Resize browser to mobile width
  • Show 1 column grid
  • Show stacked filters
  • Show mobile pagination
  • Resize to desktop
  • Show 3 column grid

10. Accessibility Demo (15 seconds)

  • Tab through page with keyboard
  • Show focus indicators
  • Show ARIA live region updates
  • Show semantic structure

Closing (10 seconds)

  • Return to marketplace overview
  • Show URL with params
  • End recording

PR Submission Checklist

Before Submitting

  • Pull latest main branch
  • Create feature branch: feat/issue-23-marketplace-listings
  • Atomic commits with Conventional Commits format
  • Code follows project patterns
  • TypeScript strict mode (0 errors)
  • No console errors
  • Build passes: pnpm build
  • Lint passes: pnpm lint
  • Screen recording created

PR Requirements

  • Link issue: "Closes #23"
  • Fill out PR template completely
  • Attach screen recording
  • Request maintainer review

Commands to Run

Development

# Start dev server
pnpm dev

# Visit marketplace
http://localhost:3000/marketplace

Testing

# Build
pnpm build

# Lint
pnpm lint

Git Workflow

# Create branch
git checkout -b feat/issue-23-marketplace-listings

# Commit changes
git add .
git commit -m "feat(marketplace): implement listings page with filters and pagination"

# Push branch
git push origin feat/issue-23-marketplace-listings

Architecture Decisions

Why Client-Side Rendering?

  • Real-time filtering/sorting without page reloads
  • Better UX with instant feedback
  • URL state management for shareability
  • Follows existing patterns (blog page, comparison tool)

Why URL Parameters?

  • Shareable filtered/sorted views
  • Browser back/forward support
  • Bookmarkable searches
  • SEO friendly (when SSR is added)

Why Mock Data?

  • Enables development without backend
  • Consistent test data
  • Easy to swap for real API
  • Follows project pattern

Why 9 Items Per Page?

  • Perfect 3x3 grid on desktop
  • Good balance of content vs. scrolling
  • Matches common pagination patterns

Future Enhancements

Phase 2

  • Real-time price updates via WebSocket
  • Favorite/watchlist functionality
  • Price alerts
  • Advanced filters (price range, vintage year range)
  • Bulk purchase
  • Seller ratings and reviews

Phase 3

  • Server-side rendering for SEO
  • Infinite scroll option
  • Map view of projects
  • Comparison tool integration
  • Export listings to CSV/PDF

Notes for Maintainers

Code Quality

  • All components follow atomic design principles
  • Consistent with existing codebase patterns
  • Reuses existing atoms/molecules where possible
  • TypeScript strict mode throughout
  • No external dependencies added

Accessibility

  • Tested with keyboard navigation
  • ARIA attributes properly used
  • Color contrast verified
  • Semantic HTML structure
  • Screen reader friendly

Performance

  • Efficient re-renders with React hooks
  • Memoized calculations
  • Optimized bundle size
  • No unnecessary dependencies

Maintainability

  • Clear file structure
  • Comprehensive comments
  • Type-safe interfaces
  • Easy to extend
  • Well-documented

Contact

For questions or issues with this implementation, please:

  1. Check this documentation first
  2. Review the code comments
  3. Test locally following the checklist
  4. Create a GitHub issue if problems persist

Implementation Date: February 23, 2026 Status: ✅ Ready for PR Estimated Review Time: 30-45 minutes