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:
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user