feat(rail): edit title & open user notes

This commit is contained in:
Fernando López Guevara
2024-01-06 11:38:34 -03:00
parent a93ebd3861
commit 2e23b3ae06
12 changed files with 129 additions and 23 deletions

View File

@@ -67,5 +67,29 @@ export function useWidget() {
},
});
return { addWidget, replaceWidget, removeWidget };
const renameWidget = useMutation({
mutationFn: async ({ id, title }: { id: string; title: string }) => {
// Cancel any outgoing refetches
await queryClient.cancelQueries({ queryKey: ['widgets'] });
// Snapshot the previous value
const prevWidgets = queryClient.getQueryData(['widgets']);
// Optimistically update to the new value
queryClient.setQueryData(['widgets'], (prev: Widget[]) =>
prev.filter((t) => t.id !== id)
);
// Update in database
await ark.renameWidget(id, title);
// Return a context object with the snapshotted value
return { prevWidgets };
},
onSettled: () => {
queryClient.invalidateQueries({ queryKey: ['widgets'] });
},
});
return { addWidget, replaceWidget, removeWidget, renameWidget };
}