Skip to content

Commit 45a0c0f

Browse files
fix dispatch not updating the value straight away
1 parent 2a9c688 commit 45a0c0f

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/api/ui/views/task.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { Literal, Literals } from "expression/literal";
1414
import {
1515
EditableAction,
1616
EditableListField,
17+
editableReducer,
1718
EditableState,
1819
TextEditable,
1920
useEditableDispatch,
@@ -231,8 +232,8 @@ export function ListItemFields({
231232
value: defVal,
232233
raw: Literals.toString(defVal),
233234
};
234-
const [fieldValue] = useState<Literal>(item.$infields[ifield?.key]?.value || defField.value!);
235-
const [state2, dispatch] = useEditableDispatch<Literal>({
235+
const fieldValue = item.$infields[ifield?.key]?.value || defField.value!;
236+
let [state2, dispatch] = useEditableDispatch<Literal>(() => ({
236237
content: fieldValue,
237238
isEditing: false,
238239
updater: useStableCallback(
@@ -266,11 +267,12 @@ export function ListItemFields({
266267
},
267268
[item.$infields]
268269
),
269-
});
270+
}));
270271
if (ifield.key == settings.taskCompletionText) {
271272
//@ts-ignore huh?
272273
completedRef.current = dispatch;
273274
}
275+
state2 = editableReducer<Literal>(state2, { type: "content-changed", newValue: fieldValue });
274276
return (
275277
<EditableListField
276278
props={state2}

0 commit comments

Comments
 (0)