Desperate for help with Trpc resolver.

How can i get resolve({ default: base64Data }); to only trigger once trpc has returned success or failure. class MyUploadAdapter { private loader: any; private mutation: any; constructor(loader, mutation) { this.loader = loader; this.mutation = mutation; } private async _uploadFile(file: File) { return new Promise((resolve, reject) => { const reader = new FileReader(); reader.onload = async () => { const base64Data = reader.result?.toString().split(',')[1] || ''; // mutate will automatically handle success and failure. try { await this.mutation.mutate({ base64Data, }); resolve({ default: base64Data }); // Since mutate will handle success and failure, // you don't need to manually check for errors or success here. // Instead, just resolve with the base64Data, // and CKEditor will handle the result. } catch (error) { // The error is caught here but it has already been handled by the onError handler. reject(error); } }; reader.readAsDataURL(file); }); } }
T
Tom331d ago
i think youre looking for mutation.mutateAsync()
G
gnarley_farley.331d ago
thanks man i'll try that i actually messed up my conditional logic. I managed to get it working using state and then finally overriding the else to use the the resolver aswell. Gonna need to go back and try sort it.
G
gnarley_farley.331d ago
Very ugly implementation
T
Tom331d ago
I’m about to go to bed but I’m a little unclear what you’re trying to do here
G
gnarley_farley.331d ago
basically im sending off a base64 url to a trpc endpoint. getting image optimizedm uploaded to supabase then returning a image url. But this particular code is for ckeditor seems to be the way they have gone about it
T
Tom331d ago
I’m on my phone and can’t open the text file
G
gnarley_farley.331d ago
No worries tom if you have a chance later have a squizz. Think I got it now, need a cleaner version eventually but will figure it out. Thanks
Y
Yiannis331d ago
If you just want something to run once the mutation is done why don’t you use the onSuccess or the onSettled functions? (They go in at the object that is the second parameter of useMutation)
G
gnarley_farley.329d ago
Thanks, had a bit of a brainfart but got it in the end.
Y
Yiannis329d ago
We have all been there fore sure
Want results from more Discord servers?
Add your server
More Posts
useRouter queryHow do y'all handle typescript with nextjs's query params? Currently I'm doing ```const cartId = quPassword hashing on EDGE?I'm making an app and noticing that vercel's serverless functions are taking very much time to complAuth.js Muti-device SupportI'm implementing auth right now in a site that the user will likely be switching from mobile to deskNextJS should I use a headless CMS?Hello I am working on a project that is a multi user blog where anyone can create a post and commenHow to define this exact relation on prismaGiven this two models, how could I implement a relation between them, where a duel has 2 user Ids inHow much do y'all charge for your apps?I have created two complete custom apps for clients, took 40-60 hours a piece. Just curious how y'aDrizzle client side vs server side?hi can someone help explain to me a bit about drizzle? as far as i can tell, its doing client side at3-turbo + next-i18n + tRPC doesn't work on Vercel only locallyHi. I tried to implement server side localisation in tRPC according to this article https://levelupAnyone have an exampe of two nextjs applications in a single repo?Basically I want to have a website for the customer facing site and another for the admin portal to Recommendations for validation library?in t3 docs under other recommendations section, there is no validation library there https://createsuperplanet conection fails in production modeI need help with next auth / planetscale connection. my app works fine in localhost but does not conQuestion about next auth.Hey all, The stack and full stack development in javascript in general is new for me. I finding my Why does `npm create t3-app@latest` use the /pages directory. How can I use the app router?I want to build an application which uses the latest nextjs app router, however the `create t3-app@lnextjs13 do get request with searchbarHi, I am currently building a nextjs 13 project, trying to get in touch with the app router and servHow to sent a mutation procedure from the clientupdateUserStats:protectedProcedure .input(z.object({ id:z.string().nonempty(), pServer Actions high level questions (scale, request library, exposing to other clients)**1) how are you supposed to scale a backend if your business logic is in react components?** if thiupload thing jesthow to i set up testing with jest on components that include uploadthing? [2:40 PM] seems like it keNextJS and Bare MetalWhat all features would break/may not work if I decide to deploy to NEXTjs to bare metal instead of Cloud storage solutions for collaborating on local filesI want to collaborate on .md files (via Obsidian. for developer documentaion) and video recordings wcold startsI’m having an issue with my first queries after the db going idle taking about 11s to 12s which is c