How does the convex dashboard animate data change?
When we update the document in convex dashboard, the dashboard is able to animate the changed cell. and this works across all clients. How is it able to detect a data change (assuming the dashboard uses convex as the backend)
9 Replies
@ari is very good at React. Snippet:
Also
import { usePrevious } from "react-use"
Outside of the react tricks, as you mentioned the real magic here is that the dashboard is powered by convex, so the "system" query that loads of documents for the data page gets re-run whenever any of your clients change the data the query is subscribed to
The underlying Convex code for system queries is open-source! https://github.com/get-convex/convex-backend/blob/main/npm-packages/system-udfs/convex/_system/frontend/paginatedTableDocuments.ts
❤️
I noticed you have condition checks to prevent highlighting if row is being rendered for the first time but in the dashboard, if i add a new document (a row is being rendered for the first time), it is highlighted -- is there a way you are distinguishing between a new document being added vs rows being rendered for the first time?
Row highlighting happens in the component that renders all the cells, so that one does highlight the entire row on mount
The code in the cell component is making sure we don't highlight the entire row and all the cells inside of it when a new document is added
ahh thank you!
I am still curious how you could distinguish between the row rendering for the first time (say on refresh, or when you open the page) vs a row being added via document adding? because I see that when i refresh the page, no highlights go off.
(Sorry for so many questions!! really appreciate the help)
No worries at all! Are you building something similar to the data page on the convex dashboard?
Here's a snippet from how we decide to highlight new rows:
yeah similar ! im building ~ something like an airtable ~ and wanted to do fun animations when data changes
thank you so much!!!
ahhh you use the creationtime!
smart smart
Yup, being a little creative with that one -- since it can be hard to know if the document was added or just got added to the result of your convex query (we're using pagination on the data page, so new rows appear all the time)
I might actually snag your idea from the other thread you made so that we start animating when documents get deleted, hope you don't mind 😉
of course i dont mind! ❤️ thank you for the helppp