From 1131c5733013dc88cd4f71c377df2cc487cbb68a Mon Sep 17 00:00:00 2001 From: Phillip Dykman Date: Tue, 5 Nov 2024 19:14:36 -0800 Subject: [PATCH] Fix race condition when editing the "Check" field in the note (#967) Co-authored-by: Acylation <532117255@qq.com> --- src/ui/views/Board/BoardView.svelte | 4 ++-- src/ui/views/Board/components/Board/CardList.svelte | 10 ++++------ src/ui/views/Board/components/Board/types.ts | 2 +- src/ui/views/Calendar/CalendarView.svelte | 8 ++++---- src/ui/views/Calendar/components/Calendar/Day.svelte | 2 +- .../Calendar/components/Calendar/EventList.svelte | 6 ++---- 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/ui/views/Board/BoardView.svelte b/src/ui/views/Board/BoardView.svelte index e8dc071e..0c51acef 100644 --- a/src/ui/views/Board/BoardView.svelte +++ b/src/ui/views/Board/BoardView.svelte @@ -71,10 +71,10 @@ const handleRecordCheck = (checkField: string): OnRecordCheck => - (record) => { + (record, checked) => { api.updateRecord( updateRecordValues(record, { - [checkField]: !record.values[checkField], + [checkField]: checked, }), fields ); diff --git a/src/ui/views/Board/components/Board/CardList.svelte b/src/ui/views/Board/components/Board/CardList.svelte index bf6a0db0..bf5e8f84 100644 --- a/src/ui/views/Board/components/Board/CardList.svelte +++ b/src/ui/views/Board/components/Board/CardList.svelte @@ -37,8 +37,6 @@ export let onDrop: OnRecordDrop; export let includeFields: DataField[]; export let checkField: string | undefined; - const checked = (item: DataRecord): boolean => - checkField ? (item.values[checkField] as boolean) : false; export let customHeader: DataField | undefined; export let boardEditing: boolean; @@ -103,10 +101,10 @@ {#if checkField} { - onRecordCheck(item); - }} + checked={checkField !== undefined + ? !!item.values[checkField] + : false} + on:check={({ detail: checked }) => onRecordCheck(item, checked)} /> {/if} diff --git a/src/ui/views/Board/components/Board/types.ts b/src/ui/views/Board/components/Board/types.ts index 65dedfd6..fdf17a64 100644 --- a/src/ui/views/Board/components/Board/types.ts +++ b/src/ui/views/Board/components/Board/types.ts @@ -9,7 +9,7 @@ export type Column = { }; export type OnRecordClick = (record: DataRecord) => void; -export type OnRecordCheck = (record: DataRecord) => void; +export type OnRecordCheck = (record: DataRecord, checked: boolean) => void; export type OnRecordAdd = (column: string) => void; export type OnRecordDrop = ( record: DataRecord, diff --git a/src/ui/views/Calendar/CalendarView.svelte b/src/ui/views/Calendar/CalendarView.svelte index b840d5af..96601292 100644 --- a/src/ui/views/Calendar/CalendarView.svelte +++ b/src/ui/views/Calendar/CalendarView.svelte @@ -125,11 +125,11 @@ } } - function handleRecordCheck(record: DataRecord) { + function handleRecordCheck(record: DataRecord, checked: boolean) { if (booleanField) { api.updateRecord( updateRecordValues(record, { - [booleanField.name]: !record.values[booleanField.name], + [booleanField.name]: checked, }), fields ); @@ -272,8 +272,8 @@ onRecordChange={(record) => { handleRecordChange(date, record); }} - onRecordCheck={(record) => { - handleRecordCheck(record); + onRecordCheck={(record, checked) => { + handleRecordCheck(record, checked); }} onRecordAdd={() => { handleRecordAdd(date); diff --git a/src/ui/views/Calendar/components/Calendar/Day.svelte b/src/ui/views/Calendar/components/Calendar/Day.svelte index 7b7d3d40..fb2547bc 100644 --- a/src/ui/views/Calendar/components/Calendar/Day.svelte +++ b/src/ui/views/Calendar/components/Calendar/Day.svelte @@ -35,7 +35,7 @@ /** * onRecordCheck runs when the user Checks / Unchecks a calendar event. */ - export let onRecordCheck: (record: DataRecord) => void; + export let onRecordCheck: (record: DataRecord, checked: boolean) => void; /** * onRecordChange runs when the user changes the checked state. diff --git a/src/ui/views/Calendar/components/Calendar/EventList.svelte b/src/ui/views/Calendar/components/Calendar/EventList.svelte index 57c1191a..dff2b53c 100644 --- a/src/ui/views/Calendar/components/Calendar/EventList.svelte +++ b/src/ui/views/Calendar/components/Calendar/EventList.svelte @@ -17,7 +17,7 @@ export let checkField: string | undefined; export let onRecordClick: (record: DataRecord) => void; - export let onRecordCheck: (record: DataRecord) => void; + export let onRecordCheck: (record: DataRecord, checked: boolean) => void; export let onRecordChange: (record: DataRecord) => void; function asOptionalBoolean(value: Optional): Optional { @@ -62,9 +62,7 @@ checked={checkField !== undefined ? asOptionalBoolean(record.values[checkField]) : undefined} - on:check={() => { - onRecordCheck(record); - }} + on:check={({ detail: checked }) => onRecordCheck(record, checked)} >