From f8703963fdbcd590ca7eca203bb533533343aaf7 Mon Sep 17 00:00:00 2001 From: "T.Landgraf" Date: Tue, 15 Sep 2026 14:28:00 +0200 Subject: [PATCH] Add autofill for end time and break duration with labels indicating auto-filled values --- src/App.tsx | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index abf2c40..2f163ad 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -11,6 +11,8 @@ interface DayRecord { workedHrs: number; overtimeMinutes: number; notWorking?: boolean; + endAutofilled?: boolean; + breakAutofilled?: boolean; } type Records = Partial>; @@ -18,10 +20,13 @@ type Records = Partial>; const STORAGE_KEY = 'workTrackerRecords'; const CARRYOVER_KEY = 'workTrackerCarryover'; -const DEFAULT_RECORD: DayRecord = { start: '', end: '', breakMins: 0, workedHrs: 0, overtimeMinutes: 0, notWorking: false }; +const DEFAULT_RECORD: DayRecord = { start: '', end: '', breakMins: 0, workedHrs: 0, overtimeMinutes: 0, notWorking: false, endAutofilled: false, breakAutofilled: false }; const WEEKDAYS: Workday[] = ['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag']; +const STANDARD_WORK_MINUTES = 8 * 60; +const STANDARD_BREAK_MINUTES = 60; + const loadRecords = (): Records => { try { const raw = localStorage.getItem(STORAGE_KEY); @@ -100,6 +105,32 @@ function App() { return fromMinutes(start + 8 * 60 - balance + record.breakMins); } + const handleStartChange = (value: string) => { + const start = toMinutes(value); + if (start === null) { + updateRecord({ start: value, endAutofilled: false, breakAutofilled: false }); + return; + } + updateRecord({ + start: value, + breakMins: STANDARD_BREAK_MINUTES, + end: fromMinutes(start + STANDARD_WORK_MINUTES + STANDARD_BREAK_MINUTES), + endAutofilled: true, + breakAutofilled: true, + }); + }; + + const autofillLabel = (label: string, autofilled?: boolean) => ( + + {label} + {autofilled && ( + + {' '}(automatisch ausgefüllt) + + )} + + ); + const handleSave = () => { if (record.notWorking) { updateRecord({ workedHrs: 0, overtimeMinutes: 0 }); @@ -148,7 +179,7 @@ function App() { onClick={() => { const nowWorking = !record.notWorking; if (nowWorking) { - updateRecord({ notWorking: true, start: '', end: '', breakMins: 0, workedHrs: 0, overtimeMinutes: 0 }); + updateRecord({ notWorking: true, start: '', end: '', breakMins: 0, workedHrs: 0, overtimeMinutes: 0, endAutofilled: false, breakAutofilled: false }); } else { updateRecord({ notWorking: false }); } @@ -160,23 +191,23 @@ function App() { updateRecord({ start: value })} + onChange={handleStartChange} format="24h" clearable disabled={record.notWorking} /> updateRecord({ end: value })} + label={autofillLabel("Arbeitsende", record.endAutofilled)} + onChange={(value) => updateRecord({ end: value, endAutofilled: false })} format="24h" clearable disabled={record.notWorking} /> updateRecord({ breakMins: Number(val) })} + onChange={(val) => updateRecord({ breakMins: Number(val), breakAutofilled: false })} onKeyDown={(event) => { if (event.key === 'Enter') handleSave(); }}