Router triggered 2 times
Can somebody tell me why this is being triggered 2 times instead than one?
api.user.doTraduzioneLatino.useQuery({ email: email ?? '', text: textAreaLatinoRef.current?.value ?? '' }, {
enabled: doTraduzioneLatino === true,
onSuccess: (data) => {
setDoTraduzioneLatino(false);
console.log(data);
setTraduzioneLatino(data);
}
});
api.user.doTraduzioneLatino.useQuery({ email: email ?? '', text: textAreaLatinoRef.current?.value ?? '' }, {
enabled: doTraduzioneLatino === true,
onSuccess: (data) => {
setDoTraduzioneLatino(false);
console.log(data);
setTraduzioneLatino(data);
}
});
doTraduzioneLatino: publicProcedure
.input(z.object({
text: z.string(),
email: z.string()
}))
.query(async ({ input }) => {
const { text, email } = input;
const user = await prisma.users.findUnique({
where: {
email: email
}
});
if (user == null) {
await prisma.$disconnect();
return 'User not found';
} else {
await prisma.users.update({
where: {
email: email
},
data: {
remaining_tokens: user.remaining_tokens - 1,
remaining_traductions: user.remaining_traductions - 1
}
});
await prisma.$disconnect();
}
console.log(`Testo da tradurre: ${text}`)
const completion = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [{role: "user", content: `{$text}`}],
temperature: 0.5,
});
return completion.data.choices[0].message.content;
}),
doTraduzioneLatino: publicProcedure
.input(z.object({
text: z.string(),
email: z.string()
}))
.query(async ({ input }) => {
const { text, email } = input;
const user = await prisma.users.findUnique({
where: {
email: email
}
});
if (user == null) {
await prisma.$disconnect();
return 'User not found';
} else {
await prisma.users.update({
where: {
email: email
},
data: {
remaining_tokens: user.remaining_tokens - 1,
remaining_traductions: user.remaining_traductions - 1
}
});
await prisma.$disconnect();
}
console.log(`Testo da tradurre: ${text}`)
const completion = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [{role: "user", content: `{$text}`}],
temperature: 0.5,
});
return completion.data.choices[0].message.content;
}),
0 Replies