Improve text input behavior by saving notes on field exit

Modify the description input to save changes when the user exits the field or presses Enter, rather than on every keystroke.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 55837015-10e9-4be9-b857-7f5e6be73772
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: 82396d53-6364-463b-a204-6415846d2fa6
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1cc377db-7ea0-49f2-97ce-c3e87e0228cc/55837015-10e9-4be9-b857-7f5e6be73772/76CtCxD
Replit-Helium-Checkpoint-Created: true
This commit is contained in:
SylvainP1 2026-04-21 10:48:41 +00:00
parent 2586c0eb09
commit 3f8e83b6ad

View File

@ -172,14 +172,16 @@ export default function TimesheetDetailPage() {
saveTimerRef.current = setTimeout(() => doSave(), 800); saveTimerRef.current = setTimeout(() => doSave(), 800);
}; };
const handleSetDescription = (lineId: number, dateStr: string, desc: string) => { const handleChangeDescription = (lineId: number, dateStr: string, desc: string) => {
const key = `${lineId}-${dateStr}`; const key = `${lineId}-${dateStr}`;
setLocalDescriptions(prev => ({ ...prev, [key]: desc })); setLocalDescriptions(prev => ({ ...prev, [key]: desc }));
setHasUnsavedChanges(true); setHasUnsavedChanges(true);
dirtyKeysRef.current.add(key); dirtyKeysRef.current.add(key);
};
const handleSaveDescription = () => {
if (saveTimerRef.current) clearTimeout(saveTimerRef.current); if (saveTimerRef.current) clearTimeout(saveTimerRef.current);
saveTimerRef.current = setTimeout(() => doSave(), 800); saveTimerRef.current = setTimeout(() => doSave(), 300);
}; };
useEffect(() => { useEffect(() => {
@ -500,7 +502,13 @@ export default function TimesheetDetailPage() {
type="text" type="text"
placeholder="Note (optionnel)" placeholder="Note (optionnel)"
value={desc} value={desc}
onChange={(e) => handleSetDescription(line.id, day.dateStr, e.target.value)} onChange={(e) => handleChangeDescription(line.id, day.dateStr, e.target.value)}
onBlur={handleSaveDescription}
onKeyDown={(e) => {
if (e.key === "Enter") {
e.currentTarget.blur();
}
}}
onClick={(e) => e.stopPropagation()} onClick={(e) => e.stopPropagation()}
className="w-full text-xs bg-transparent border-none outline-none placeholder:text-muted-foreground/50" className="w-full text-xs bg-transparent border-none outline-none placeholder:text-muted-foreground/50"
/> />