Que te permita renombrar los chats fix #96
This commit is contained in:
@@ -111,12 +111,6 @@ export async function create_conversation(planId: string) {
|
||||
)
|
||||
|
||||
if (error) throw error
|
||||
|
||||
// LOG de depuración: Mira qué estructura trae 'data'
|
||||
console.log('Respuesta creación conv:', data)
|
||||
|
||||
// Si data es { id: "..." }, devolvemos data.
|
||||
// Si data viene envuelto, asegúrate de retornar el objeto con el id.
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -181,3 +175,20 @@ export async function getConversationByPlan(planId: string) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
return data ?? []
|
||||
}
|
||||
|
||||
export async function update_conversation_title(
|
||||
conversacionId: string,
|
||||
nuevoTitulo: string,
|
||||
) {
|
||||
const supabase = supabaseBrowser()
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from('conversaciones_plan')
|
||||
.update({ nombre: nuevoTitulo }) // Asegúrate que la columna se llame 'title' o 'nombre'
|
||||
.eq('id', conversacionId)
|
||||
.select()
|
||||
.single()
|
||||
|
||||
if (error) throw error
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
getConversationByPlan,
|
||||
library_search,
|
||||
update_conversation_status,
|
||||
update_conversation_title,
|
||||
} from '../api/ai.api'
|
||||
|
||||
// eslint-disable-next-line node/prefer-node-protocol
|
||||
@@ -35,8 +36,6 @@ export function useAIPlanChat() {
|
||||
|
||||
// CAMBIO AQUÍ: Accedemos a la estructura correcta según tu consola
|
||||
currentId = response.conversation_plan.id
|
||||
|
||||
console.log('Nuevo ID extraído:', currentId)
|
||||
}
|
||||
|
||||
// 2. Ahora enviamos el mensaje con el ID garantizado
|
||||
@@ -56,11 +55,8 @@ export function useChatHistory(conversacionId?: string) {
|
||||
return useQuery({
|
||||
queryKey: ['chat-history', conversacionId],
|
||||
queryFn: async () => {
|
||||
console.log('--- EJECUTANDO QUERY FN ---')
|
||||
console.log('ID RECIBIDO:', conversacionId)
|
||||
return get_chat_history(conversacionId!)
|
||||
},
|
||||
// Simplificamos el enabled para probar
|
||||
enabled: Boolean(conversacionId),
|
||||
})
|
||||
}
|
||||
@@ -102,3 +98,16 @@ export function useAISubjectChat() {
|
||||
export function useLibrarySearch() {
|
||||
return useMutation({ mutationFn: library_search })
|
||||
}
|
||||
|
||||
export function useUpdateConversationTitle() {
|
||||
const qc = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ id, nombre }: { id: string; nombre: string }) =>
|
||||
update_conversation_title(id, nombre),
|
||||
onSuccess: (_, variables) => {
|
||||
// Invalidamos para que la lista de chats se refresque
|
||||
qc.invalidateQueries({ queryKey: ['conversation-by-plan'] })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user