Spaces:
Sleeping
Sleeping
| // static/initiation.js | |
| const questionElement = document.getElementById('initiation-question'); | |
| const answerElement = document.getElementById('initiation-answer'); | |
| const questions = [ | |
| "¿Cuál es el recuerdo más lejano y vívido que tenés? Describilo con todos los detalles que puedas.", | |
| "Si pudieras tener una conversación de una hora con cualquier persona, viva o muerta, ¿a quién elegirías y cuál sería la primera pregunta que le harías?", | |
| "¿Qué es algo que creías con total certeza hace cinco años y que ahora ves de forma completamente diferente?", | |
| "Describí un momento en tu vida en el que sentiste una conexión profunda con algo más grande que vos (la naturaleza, el arte, la música, etc.).", | |
| "Si el miedo no fuera un factor, ¿qué cambio radical harías en tu vida ahora mismo?" | |
| ]; | |
| let currentQuestionIndex = 0; | |
| function displayQuestion() { | |
| if (currentQuestionIndex < questions.length) { | |
| questionElement.textContent = questions[currentQuestionIndex]; | |
| answerElement.value = ''; | |
| } else { | |
| // Secuencia completada | |
| window.location.href = '/'; | |
| } | |
| } | |
| async function submitInitiationAnswer() { | |
| const answer = answerElement.value; | |
| if (answer.trim() === '') { | |
| alert('La reflexión no puede estar vacía.'); | |
| return; | |
| } | |
| try { | |
| const response = await fetch('/initiation/answer', { | |
| method: 'POST', | |
| headers: { 'Content-Type': 'application/json' }, | |
| body: JSON.stringify({ | |
| question: questions[currentQuestionIndex], | |
| answer: answer | |
| }) | |
| }); | |
| if (response.ok) { | |
| currentQuestionIndex++; | |
| displayQuestion(); | |
| } else { | |
| const errorData = await response.json(); | |
| alert(`Error: ${errorData.detail || 'No se pudo guardar la respuesta.'}`); | |
| } | |
| } catch (error) { | |
| alert('No se pudo conectar con el servidor.'); | |
| } | |
| } | |
| document.addEventListener('DOMContentLoaded', displayQuestion); | |