5.2 KiB
5.2 KiB
Cleanup Tracking Implementation
Overview
Implemented the "Mark as Cleaned" functionality to allow authenticated users to mark litter reports as cleaned up, providing visual feedback on the map and tracking cleanup progress.
Features Implemented
1. Database Schema
- ✅
cleaned_attimestamp field in reports table (already existed) - ✅
cleaned_by_user_idfield to track who marked it as cleaned (already existed) - ✅ Database migration already in place
- ✅ Foreign key relationship to users table
2. Backend API
- ✅ POST
/api/reports/:id/mark-cleanedendpoint (already existed) - ✅ Authorization check (requires authentication)
- ✅ Service method
markAsCleaned()in ReportService - ✅ Controller method in ReportController
3. Frontend Service
- ✅
markAsCleaned()method in reportService - ✅ API call to backend endpoint
4. Map Visualization
- ✅ Green markers with checkmark icon for cleaned reports
- ✅ Slightly transparent appearance to distinguish from active reports
- ✅ Popup shows "✓ Cleaned up" status and cleanup date
- ✅ Filter toggle to show/hide cleaned reports
5. Report Details Modal
- ✅ Display cleaned status with green badge
- ✅ Show cleanup date and user information
- ✅ "Mark as Cleaned" button for authenticated users
- ✅ Hide action buttons for already cleaned reports
6. Filters
- ✅ Added
showCleanedboolean to FilterState type - ✅ Toggle in MapFilters component to show/hide cleaned reports
- ✅ Default behavior: show all reports (cleaned and uncleaned)
- ✅ Filter logic in MapView component
User Flow
-
Viewing Cleaned Reports
- Cleaned reports appear as green markers with checkmark icons
- Slightly transparent to distinguish from active reports
- Popup shows cleanup date
-
Marking a Report as Cleaned
- User clicks on a report marker
- Report detail modal opens
- If authenticated and not already cleaned, "Mark as Cleaned" button appears
- Click button to mark as cleaned
- Report updates immediately with green badge
- Map marker changes to green with checkmark
-
Filtering Cleaned Reports
- Open map filters panel
- Toggle "Show Cleaned Reports" switch
- When off, cleaned reports are hidden from the map
- When on (default), all reports are visible
Technical Details
Type Definitions
interface Report {
// ... other fields
cleanedAt?: Date;
cleanedByUserId?: string;
}
interface FilterState {
// ... other fields
showCleaned?: boolean;
}
API Endpoint
POST /api/reports/:id/mark-cleaned
Authorization: Bearer <token>
Response: Updated report with cleanedAt and cleanedByUserId
Marker Styling
- Uncleaned reports: Color-coded by litter type (blue, gray, green, etc.)
- Cleaned reports: Green color with checkmark icon, 70% opacity
Testing Recommendations
-
Authentication
- Verify only authenticated users can mark reports as cleaned
- Test with signed-in and signed-out states
-
Visual Feedback
- Confirm green markers appear for cleaned reports
- Verify checkmark icon displays correctly
- Test marker opacity difference
-
Filter Functionality
- Toggle show/hide cleaned reports
- Verify filter persists during map interactions
- Test with combination of other filters
-
Report Details
- Verify cleaned badge appears in modal
- Check cleanup date formatting
- Confirm action buttons hide after marking as cleaned
-
Data Persistence
- Mark report as cleaned
- Refresh page
- Verify report remains marked as cleaned
Future Enhancements
-
Analytics
- Track total number of cleaned reports
- Show cleanup statistics on dashboard
- Display cleanup trends over time
-
User Contributions
- Show cleanup count on user profiles
- Add cleanup achievements/badges
- Leaderboard for most cleanups
-
Verification
- Allow users to upload "after" photos
- Community verification of cleanup claims
- Dispute mechanism for false cleanup claims
-
Notifications
- Notify report creator when their report is cleaned
- Alert nearby users about cleanup activities
- Celebrate cleanup milestones
Files Modified
Frontend
src/types/index.ts- Added showCleaned to FilterStatesrc/components/map/MapView.tsx- Updated marker styling and filteringsrc/components/map/MapFilters.tsx- Added cleaned reports togglesrc/components/report/ReportDetailModal.tsx- Display cleaned statussrc/pages/MapPage.tsx- Wire up markAsCleaned handler
Backend (Already Implemented)
server/prisma/schema.prisma- Database schema with cleaned fieldsserver/src/services/reportService.ts- markAsCleaned methodserver/src/controllers/reportController.ts- markAsCleaned endpointserver/src/routes/reportRoutes.ts- Route definitionserver/prisma/migrations/20251116222516_add_cleaned_fields/migration.sql- Database migration
Conclusion
The cleanup tracking system is now fully functional, allowing the community to track their impact and see which areas have been addressed. The visual distinction between cleaned and uncleaned reports helps users focus their efforts on areas that still need attention.