feat(don): optimistic update checkbox
Build and Push Image / build-backend (push) Successful in 23s
Build and Push Image / build-frontend (push) Successful in 1m46s
Build and Push Image / push (push) Successful in 40s

This commit is contained in:
2026-09-13 20:53:46 +07:00 Unverified
parent 621205435a
commit 0c63e7daef
2 changed files with 28 additions and 4 deletions
+2 -2
View File
@@ -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();
}} }}
+26 -2
View File
@@ -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}
/> />
); );
}, },