useQuery function to trigger toast
Mind if i ask if there's a mutation somewhere, that updates the query?
13 Replies
I have multiples AIs that can run at the same time. It create tasks in the background and I want to give update to the user about the task. I've though about querying my tasks in a context and triggering a toast/sonner when it updates. The mutations to change status/progress/etc is done on the server.
Hi, so i was trying to reply in the other thread but this is fine.
My idea was is to use "withOptimisticUpdates" on mutation that updates the target query, in which you can run the toast function in, which technically serves your purpose here.
But I'm not 100% sure if it's going to work in ssr, but you can try and find out kind of situation
The toast is not available on the server. It's only client side.
Awesome!
Well then could you try if the optimistic update works on mutation in ssr? Or your mutation that does the update?
If not, i have another idea
It's almost 2am for me btw, and I'm running on redbul, so i might go silent soon
Here's the current process : user start AI task -> server receving settings,data,etc, create taks -> server updates the tasks status as the ai progress -> server store the result/error -> client use convex realtime to update the user via toast/sonner (where I am).
Amazing, which still means using optimistic updates can be your deal breaker here
If the user was going to stay on the page it would be fine but I can't have an user wait 2-3 minutes waiting
Optimistic Updates | Convex Developer Hub
Make your React app more responsive with optimistic UI updates
You see the how the function declaration is done? You could pass the updates into the local store or even not do anything at all but run the toast function inside the mutation call
local store = cookies in this case or nah ?
Local storage
But they are temporary
If this doesn't work, seriously I'm sad to say this but your last bet is s useEffect
Or, a hook that runs the function haha
Good, TY for the help. I will try it
Or, last resort, passing down into components, where the updates are run on prop update