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);
});
}
}
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);
});
}
}