Sara
Sara4w ago

useQuery function to trigger toast

Mind if i ask if there's a mutation somewhere, that updates the query?
13 Replies
Slimy
Slimy4w ago
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.
Sara
SaraOP4w ago
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
Slimy
Slimy4w ago
The toast is not available on the server. It's only client side.
Sara
SaraOP4w ago
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
Slimy
Slimy4w ago
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).
Sara
SaraOP4w ago
Amazing, which still means using optimistic updates can be your deal breaker here
Slimy
Slimy4w ago
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
Sara
SaraOP4w ago
Sara
SaraOP4w ago
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
Slimy
Slimy4w ago
local store = cookies in this case or nah ?
Sara
SaraOP4w ago
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
Slimy
Slimy4w ago
Good, TY for the help. I will try it
Sara
SaraOP4w ago
Or, last resort, passing down into components, where the updates are run on prop update

Did you find this page helpful?