asdf
This commit is contained in:
@@ -195,7 +195,10 @@ const History = () => {
|
||||
|
||||
const filteredForOptions = getFilteredApplicationsForOptions();
|
||||
|
||||
const uniqueProperties = [...new Set(completedApplications.map(app => app.propertyName))].filter(Boolean);
|
||||
const uniqueProperties = [...new Set([
|
||||
...completedApplications.map(app => app.propertyName),
|
||||
...mowingLogs.map(log => log.property_name)
|
||||
])].filter(Boolean);
|
||||
const uniqueProducts = [...new Set(
|
||||
filteredForOptions.flatMap(app =>
|
||||
app.productDetails ? app.productDetails.map(p => p.name) : []
|
||||
@@ -274,7 +277,58 @@ const History = () => {
|
||||
const totalApplications = completedApplications.length;
|
||||
const totalAreaTreated = completedApplications.reduce((sum, app) => sum + (app.totalSectionArea || 0), 0);
|
||||
const totalDuration = applicationLogs.reduce((sum, log) => sum + (log.gpsTrack?.duration || 0), 0);
|
||||
const totalMowingSessions = mowingLogs.length;
|
||||
// Derive filtered + sorted mowing logs using shared filters (date/property)
|
||||
const filteredMowingLogs = (mowingLogs || []).filter((log) => {
|
||||
// Date filter (use session_date when available, fallback to created_at)
|
||||
if (dateFilter !== 'all') {
|
||||
const dStr = log.session_date || log.created_at;
|
||||
const logDate = dStr ? new Date(dStr) : null;
|
||||
if (!logDate) return false;
|
||||
const now = new Date();
|
||||
switch (dateFilter) {
|
||||
case 'today':
|
||||
if (logDate.toDateString() !== now.toDateString()) return false;
|
||||
break;
|
||||
case 'week': {
|
||||
const weekAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000);
|
||||
if (logDate < weekAgo) return false;
|
||||
break;
|
||||
}
|
||||
case 'month': {
|
||||
const monthAgo = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000);
|
||||
if (logDate < monthAgo) return false;
|
||||
break;
|
||||
}
|
||||
case 'custom':
|
||||
if (dateRangeStart) {
|
||||
const startDate = new Date(dateRangeStart);
|
||||
startDate.setHours(0, 0, 0, 0);
|
||||
if (logDate < startDate) return false;
|
||||
}
|
||||
if (dateRangeEnd) {
|
||||
const endDate = new Date(dateRangeEnd);
|
||||
endDate.setHours(23, 59, 59, 999);
|
||||
if (logDate > endDate) return false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Property filter (property_name from API)
|
||||
if (propertyFilter !== 'all' && (log.property_name || '') !== propertyFilter) return false;
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
const sortedMowingLogs = [...filteredMowingLogs].sort((a, b) => {
|
||||
const aDate = a.session_date || a.created_at || 0;
|
||||
const bDate = b.session_date || b.created_at || 0;
|
||||
return new Date(bDate) - new Date(aDate);
|
||||
});
|
||||
|
||||
const totalMowingSessions = sortedMowingLogs.length;
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
@@ -686,7 +740,7 @@ const History = () => {
|
||||
<p className="text-sm text-gray-500">{totalMowingSessions} session{totalMowingSessions!==1?'s':''}</p>
|
||||
</div>
|
||||
<div className="divide-y">
|
||||
{mowingLogs.map((log) => {
|
||||
{sortedMowingLogs.map((log) => {
|
||||
const durationMin = Math.round((log.duration_seconds || log.durationSeconds || log.gpsTrack?.duration || 0) / 60);
|
||||
const avg = (log.average_speed_mph || log.averageSpeed || 0).toFixed?.(1) || Number(log.averageSpeed || 0).toFixed(1);
|
||||
const distFeet = Math.round(((log.total_distance_meters || log.gpsTrack?.totalDistance || 0) * 3.28084) || 0);
|
||||
|
||||
Reference in New Issue
Block a user