Add total litter collected display to user profile

- Updated backend userService to calculate total litter collected across all attended events
- Added totalLitterCollected field to UserProfile interface
- Added new statistics card showing total litter collected in kg
- Updated profile grid layout to accommodate 5 statistics cards
- Displays litter collected with 1 decimal place precision
This commit is contained in:
2025-11-18 19:03:43 +00:00
parent 3d7b84f376
commit 3a6db92699
22 changed files with 1462 additions and 128 deletions

View File

@@ -46,11 +46,24 @@ export class ApiClient {
});
if (!response.ok) {
const error: ApiError = await response.json();
let error: ApiError;
try {
error = await response.json();
} catch {
// If response is not JSON, create a generic error
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
throw new Error(error.message || 'An error occurred');
}
return response.json();
// Handle empty responses (like DELETE)
const contentType = response.headers.get('content-type');
if (contentType && contentType.includes('application/json')) {
return response.json();
}
// For non-JSON responses, return empty object
return {} as T;
}
async get<T>(endpoint: string, options?: RequestInit): Promise<T> {