feat(don): optimistic update checkbox
This commit is contained in:
@@ -126,8 +126,8 @@ export function SidebarLink({
|
|||||||
<Checkbox
|
<Checkbox
|
||||||
className="mr-2"
|
className="mr-2"
|
||||||
checked={checked}
|
checked={checked}
|
||||||
onCheckedChange={async () => {
|
onCheckedChange={async (checked) => {
|
||||||
setChecked((x) => !x);
|
setChecked(checked === true);
|
||||||
await toggleCheck(submission.id);
|
await toggleCheck(submission.id);
|
||||||
stop();
|
stop();
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -48,6 +48,30 @@ function colorFor(date: Date) {
|
|||||||
return lePalette[seed % lePalette.length];
|
return lePalette[seed % lePalette.length];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ArtifactCheckbox({
|
||||||
|
checked,
|
||||||
|
submissionId,
|
||||||
|
}: {
|
||||||
|
checked: boolean;
|
||||||
|
submissionId: string;
|
||||||
|
}) {
|
||||||
|
const [value, setValue] = useState(checked);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setValue(checked);
|
||||||
|
}, [checked]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Checkbox
|
||||||
|
checked={value}
|
||||||
|
onCheckedChange={async (checked) => {
|
||||||
|
setValue(checked === true);
|
||||||
|
await toggleCheck(submissionId);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const columns: ColumnDef<
|
const columns: ColumnDef<
|
||||||
typeof donations.$inferSelect & {
|
typeof donations.$inferSelect & {
|
||||||
checked: boolean | null;
|
checked: boolean | null;
|
||||||
@@ -78,9 +102,9 @@ const columns: ColumnDef<
|
|||||||
const { artifactSubmissionId, checked } = row.row.original;
|
const { artifactSubmissionId, checked } = row.row.original;
|
||||||
if (checked === null || !artifactSubmissionId) return;
|
if (checked === null || !artifactSubmissionId) return;
|
||||||
return (
|
return (
|
||||||
<Checkbox
|
<ArtifactCheckbox
|
||||||
checked={checked}
|
checked={checked}
|
||||||
onCheckedChange={() => toggleCheck(artifactSubmissionId)}
|
submissionId={artifactSubmissionId}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user