From 58ddde6b1ebfd269aaffff444c0e9c69305a2dc5 Mon Sep 17 00:00:00 2001 From: Lars Date: Wed, 15 Apr 2026 11:39:39 +0200 Subject: [PATCH] feat: Add time input fields for activity log and enhance time handling - Introduced start_time and end_time fields in the activity log entry form, allowing users to input specific times for activities. - Implemented utility functions to format and validate time inputs from the API and user input, ensuring proper handling of time data. - Updated the activity display to show formatted start and end times, improving clarity for users reviewing their activity logs. --- frontend/src/pages/ActivityPage.jsx | 72 ++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/frontend/src/pages/ActivityPage.jsx b/frontend/src/pages/ActivityPage.jsx index ec68925..50ea792 100644 --- a/frontend/src/pages/ActivityPage.jsx +++ b/frontend/src/pages/ActivityPage.jsx @@ -38,6 +38,29 @@ function dedupeActivitiesById(rows) { return [...m.values()].sort(compareActivities) } +/** activity_log: Spalten start_time / end_time sind TIME (Uhrzeit zum Kalendertag date), nicht volles Timestamp. */ +function timeInputValueFromApi(t) { + if (t == null || t === '') return '' + const s = String(t) + if (s.includes('T') && s.length >= 16) return s.slice(11, 16) + const m = s.match(/^(\d{1,2}):(\d{2})/) + if (!m) return '' + return `${m[1].padStart(2, '0')}:${m[2]}` +} + +function timePayloadFromInput(v) { + const s = v == null ? '' : String(v).trim() + if (!s) return null + if (/^\d{2}:\d{2}$/.test(s)) return `${s}:00` + if (/^\d{2}:\d{2}:\d{2}$/.test(s)) return s + return s +} + +function formatTimeForList(t) { + const v = timeInputValueFromApi(t) + return v || '' +} + const ACTIVITY_TYPES = [ 'Traditionelles Krafttraining','Matrial Arts','Outdoor Spaziergang', 'Innenräume Spaziergang','Laufen','Radfahren','Schwimmen', @@ -76,6 +99,8 @@ const ACTIVITY_LOG_PAYLOAD_KEYS = new Set([ function empty() { return { date: dayjs().format('YYYY-MM-DD'), + start_time: '', + end_time: '', activity_type: 'Traditionelles Krafttraining', duration_min: '', kcal_active: '', hr_avg: '', hr_max: '', rpe: '', notes: '', @@ -282,6 +307,30 @@ function EntryForm({ set('date',e.target.value)}/> +
+ + set('start_time', e.target.value ? timePayloadFromInput(e.target.value) || '' : '')} + /> + zum Datum oben +
+
+ + set('end_time', e.target.value ? timePayloadFromInput(e.target.value) || '' : '')} + /> + optional +
0) { const metrics = buildMetricsPayload(sessionDetail.schema, metricDraft) @@ -837,7 +902,12 @@ export default function ActivityPage() {
{dayjs(e.date).format('dd, DD. MMMM YYYY')} - {e.start_time && e.start_time.length>10 && ` · ${e.start_time.slice(11,16)}`} + {(formatTimeForList(e.start_time) || formatTimeForList(e.end_time)) && ( + + {formatTimeForList(e.start_time) && ` · Start ${formatTimeForList(e.start_time)}`} + {formatTimeForList(e.end_time) && ` · Ende ${formatTimeForList(e.end_time)}`} + + )}
{e.duration_min && ⏱ {Math.round(e.duration_min)} Min}