added instant sync and fixed saving debounce
This commit is contained in:
@@ -42,13 +42,22 @@ export const TaskDetail: Component<TaskDetailProps> = (props) => {
|
||||
});
|
||||
|
||||
let debounceTimer: number | undefined;
|
||||
let pendingContent: string | null = null;
|
||||
|
||||
const updateTaskContent = (html: string) => {
|
||||
pendingContent = html;
|
||||
clearTimeout(debounceTimer);
|
||||
debounceTimer = setTimeout(() => {
|
||||
updateTask(props.task.id, { content: html });
|
||||
if (pendingContent !== null) {
|
||||
updateTask(props.task.id, { content: pendingContent });
|
||||
pendingContent = null;
|
||||
}
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
// Removed onCleanup to avoid lockup
|
||||
|
||||
|
||||
const updateTitle = (val: string) => {
|
||||
setTitle(val);
|
||||
updateTask(props.task.id, { title: val });
|
||||
@@ -87,7 +96,16 @@ export const TaskDetail: Component<TaskDetailProps> = (props) => {
|
||||
const currentUrgency = () => calculateUrgencyFromDate(props.task.dueDate).toString();
|
||||
|
||||
return (
|
||||
<Sheet open={props.isOpen} onOpenChange={(open) => !open && props.onClose()}>
|
||||
<Sheet open={props.isOpen} onOpenChange={(open) => {
|
||||
if (!open) {
|
||||
// Flash save before closing to avoid lockup
|
||||
if (pendingContent !== null) {
|
||||
updateTask(props.task.id, { content: pendingContent });
|
||||
pendingContent = null;
|
||||
}
|
||||
props.onClose();
|
||||
}
|
||||
}}>
|
||||
<SheetContent
|
||||
hideCloseButton
|
||||
onOpenAutoFocus={(e) => {
|
||||
|
||||
Reference in New Issue
Block a user