Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions 404.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,32 @@
<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js"></script>
</head>
<body>
<!-- Botones de control en la parte superior -->
<div id="progress-buttons">
<button id="save-progress">Guardar progreso</button>
<button id="load-progress">Cargar progreso</button>
<!-- Input oculto para cargar progreso (.json) -->
<input type="file" id="file-input" accept=".json" style="display:none">
<header class="main-header">
<button id="open-sidebar" class="sidebar-toggle" aria-label="Abrir menú">&#9776;</button>
<span id="collection-title">Colección</span>
</header>

<button id="load-csv-button">Cargar Nuevo CSV</button>
<!-- Input oculto para cargar nuevo CSV -->
<input type="file" id="csv-file-input" accept=".csv" style="display:none">
<aside id="sidebar" class="sidebar">
<button id="close-sidebar" class="sidebar-toggle close-sidebar" aria-label="Cerrar menú">&#9776;</button>
<div class="menu-section">
<a href="home.html" id="home-link">Inicio</a>
<button id="change-collection-button">Cambiar colección</button>
</div>
<div class="menu-section">
<button id="save-progress">Guardar progreso</button>
<button id="load-progress">Cargar progreso</button>
<input type="file" id="file-input" accept=".json" style="display:none">

<button id="change-collection-button">Cambiar colección</button>
<button id="load-csv-button">Cargar CSV</button>
<input type="file" id="csv-file-input" accept=".csv" style="display:none">

<button id="reset-progress-button">Reiniciar Progreso</button>
<button id="config-button">Configuración</button>
</div>
<button id="reset-progress-button">Reiniciar Progreso</button>
</div>
<div class="menu-section">
<button id="config-button">Configuración</button>
<button id="login-button">Iniciar sesión</button>
</div>
</aside>
<div class="quiz-container">
<div id="quiz"></div>
<!-- Elemento para mostrar mensajes de estado (opcional) -->
Expand Down
38 changes: 38 additions & 0 deletions home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!-- home.html -->
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<base href="/">
<title>Inicio - Quiz Interactivo</title>
<link rel="stylesheet" href="styles.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js"></script>
</head>
<body>
<header class="main-header">
<button id="open-sidebar" class="sidebar-toggle" aria-label="Abrir menú">&#9776;</button>
<span id="collection-title">Colección</span>
</header>

<aside id="sidebar" class="sidebar">
<button id="close-sidebar" class="sidebar-toggle close-sidebar" aria-label="Cerrar menú">&#9776;</button>
<div class="menu-section">
<a href="home.html" id="home-link">Inicio</a>
<a href="quiz.html" id="start-quiz-link">Comenzar Quiz</a>
<button id="change-collection-button">Cambiar colección</button>
</div>
<div class="menu-section">
<button id="config-button">Configuración</button>
<button id="login-button">Iniciar sesión</button>
</div>
</aside>

<main class="home-main">
<h1>¿Qué estudiaremos hoy?</h1>
<div id="collections-carousel" class="collections-carousel"></div>
</main>

<script src="home.js"></script>
</body>
</html>
71 changes: 71 additions & 0 deletions home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const SUPABASE_URL = 'https://infuklajuugncqkarlnp.supabase.co';
const SUPABASE_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImluZnVrbGFqdXVnbmNxa2FybG5wIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTAwNTIwNzMsImV4cCI6MjA2NTYyODA3M30.-rb8x3G7T0FN6U2GMz1LD_tulNFG9jKyvdv5iDoDidg';

let sidebar = null;
let openSidebarButton = null;
let closeSidebarButton = null;
let collectionTitleSpan = null;

window.addEventListener('DOMContentLoaded', () => {
sidebar = document.getElementById('sidebar');
openSidebarButton = document.getElementById('open-sidebar');
closeSidebarButton = document.getElementById('close-sidebar');
collectionTitleSpan = document.getElementById('collection-title');

openSidebarButton.addEventListener('click', openSidebar);
closeSidebarButton.addEventListener('click', closeSidebar);
document.addEventListener('click', handleDocumentClick);

loadCollections();
});

function openSidebar() {
sidebar.classList.add('open');
document.body.classList.add('sidebar-open');
}

function closeSidebar() {
sidebar.classList.remove('open');
document.body.classList.remove('sidebar-open');
}

function handleDocumentClick(event) {
if (!sidebar.classList.contains('open')) return;
if (window.innerWidth > 768) return;
if (sidebar.contains(event.target) || openSidebarButton.contains(event.target)) return;
closeSidebar();
}

async function loadCollections() {
try {
const res = await fetch(`${SUPABASE_URL}/rest/v1/colecciones?select=*`, {
headers: {
apikey: SUPABASE_KEY,
Authorization: `Bearer ${SUPABASE_KEY}`
}
});
const data = await res.json();
renderCollections(data);
if (data.length > 0) {
collectionTitleSpan.textContent = data[0].nombre;
}
} catch (e) {
console.error('Error al cargar colecciones:', e);
}
}

function renderCollections(cols) {
const container = document.getElementById('collections-carousel');
container.innerHTML = '';
cols.forEach(col => {
const card = document.createElement('a');
card.href = `/collections/${col.id}`;
card.className = 'collection-card';
card.innerHTML = `
<strong class="collection-materia">${col.materia}</strong>
<h3>${col.nombre}</h3>
<p>${col.descripcion}</p>
`;
container.appendChild(card);
});
}
36 changes: 23 additions & 13 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,32 @@
<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js"></script>
</head>
<body>
<!-- Botones de control en la parte superior -->
<div id="progress-buttons">
<button id="save-progress">Guardar progreso</button>
<button id="load-progress">Cargar progreso</button>
<!-- Input oculto para cargar progreso (.json) -->
<input type="file" id="file-input" accept=".json" style="display:none">
<header class="main-header">
<button id="open-sidebar" class="sidebar-toggle" aria-label="Abrir menú">&#9776;</button>
<span id="collection-title">Colección</span>
</header>

<button id="load-csv-button">Cargar Nuevo CSV</button>
<!-- Input oculto para cargar nuevo CSV -->
<input type="file" id="csv-file-input" accept=".csv" style="display:none">
<aside id="sidebar" class="sidebar">
<button id="close-sidebar" class="sidebar-toggle close-sidebar" aria-label="Cerrar menú">&#9776;</button>
<div class="menu-section">
<a href="home.html" id="home-link">Inicio</a>
<button id="change-collection-button">Cambiar colección</button>
</div>
<div class="menu-section">
<button id="save-progress">Guardar progreso</button>
<button id="load-progress">Cargar progreso</button>
<input type="file" id="file-input" accept=".json" style="display:none">

<button id="change-collection-button">Cambiar colección</button>
<button id="load-csv-button">Cargar CSV</button>
<input type="file" id="csv-file-input" accept=".csv" style="display:none">

<button id="reset-progress-button">Reiniciar Progreso</button>
<button id="config-button">Configuración</button>
</div>
<button id="reset-progress-button">Reiniciar Progreso</button>
</div>
<div class="menu-section">
<button id="config-button">Configuración</button>
<button id="login-button">Iniciar sesión</button>
</div>
</aside>
<div class="quiz-container">
<div id="quiz"></div>
<!-- Elemento para mostrar mensajes de estado (opcional) -->
Expand Down
54 changes: 53 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ let quizContainerDiv = null; // <-- NUEVO: Referencia al contenedor principal
let timeProgressDiv = null;
let timeBarDiv = null;
let timeRemainingSpan = null;
let sidebar = null;
let openSidebarButton = null;
let closeSidebarButton = null;
let collectionTitleSpan = null;

let initialTotalRepetitions = 0;
let questionStartTime = null;
Expand Down Expand Up @@ -87,6 +91,11 @@ document.addEventListener('DOMContentLoaded', function() {
collectionModal = document.getElementById('collection-modal');
confirmCollectionButton = document.getElementById('confirm-collection-button');

sidebar = document.getElementById('sidebar');
openSidebarButton = document.getElementById('open-sidebar');
closeSidebarButton = document.getElementById('close-sidebar');
collectionTitleSpan = document.getElementById('collection-title');

// Referencias para el modal de configuración
configButton = document.getElementById('config-button');
configModalOverlay = document.getElementById('config-modal-overlay');
Expand All @@ -102,7 +111,8 @@ document.addEventListener('DOMContentLoaded', function() {
!timeProgressDiv || !timeBarDiv || !timeRemainingSpan || !collectionSelect ||
!changeCollectionButton || !collectionModalOverlay || !collectionModal || !confirmCollectionButton ||
!configButton || !configModalOverlay || !configModal || !configRepsOnErrorInput ||
!configInitialRepsInput || !configThemeSelect || !saveConfigButton || !closeModalButton || !closeModalXButton) {
!configInitialRepsInput || !configThemeSelect || !saveConfigButton || !closeModalButton || !closeModalXButton ||
!sidebar || !openSidebarButton || !closeSidebarButton || !collectionTitleSpan) {
console.error("Error: No se encontraron elementos esenciales del DOM (quiz, status, inputs, o elementos del modal).");
if(quizDiv) quizDiv.innerHTML = "<p class='error-message'>Error crítico: Faltan elementos HTML esenciales para el quiz o la configuración.</p>";
return;
Expand Down Expand Up @@ -147,6 +157,9 @@ function setupEventListeners() {
closeConfigModal();
}
});

openSidebarButton?.addEventListener('click', openSidebar);
closeSidebarButton?.addEventListener('click', closeSidebar);
}

// --- Carga de Datos (CSV y Estado) ---
Expand Down Expand Up @@ -220,21 +233,26 @@ async function loadCollections() {
localStorage.setItem(COLLECTION_STORAGE_KEY, pathId);
updateUrlForCollection(pathId, true);
await loadQuestionsFromCollection(pathId);
updateCollectionTitleById(pathId);
return;
} else {
updateUrlForCollection(null, true);
openCollectionModal();
updateCollectionTitleById(null);
}
} else if (saved && collectionSelect.querySelector(`option[value="${saved}"]`)) {
collectionSelect.value = saved;
updateUrlForCollection(saved, true);
if (saved !== 'custom') {
await loadQuestionsFromCollection(saved);
}
updateCollectionTitleById(saved);
} else if (availableCollections.length > 0) {
collectionSelect.value = availableCollections[0].id;
updateUrlForCollection(null, true);
openCollectionModal();
updateCollectionTitleById(null);
updateCollectionTitleById(availableCollections[0].id);
} else {
updateUrlForCollection(null, true);
openCollectionModal();
Expand Down Expand Up @@ -294,15 +312,48 @@ function closeCollectionModal() {
if (collectionModalOverlay) collectionModalOverlay.classList.add('hidden');
}

function openSidebar() {
sidebar?.classList.add('open');
document.body.classList.add('sidebar-open');
document.addEventListener('click', handleDocumentClick);
}

function closeSidebar() {
sidebar?.classList.remove('open');
document.body.classList.remove('sidebar-open');
document.removeEventListener('click', handleDocumentClick);
}

function handleDocumentClick(event) {
if (!sidebar?.classList.contains('open')) return;
if (window.innerWidth > 768) return;
if (sidebar.contains(event.target) || openSidebarButton.contains(event.target)) {
return;
}
closeSidebar();
}

function updateCollectionTitleById(id) {
if (!collectionTitleSpan) return;
if (id === 'custom') {
collectionTitleSpan.textContent = 'Personalizado';
} else {
const col = availableCollections.find(c => c.id === id);
collectionTitleSpan.textContent = col ? col.nombre : 'Colección';
}
}

function confirmCollectionSelection() {
const id = collectionSelect.value;
if (id !== 'custom') {
localStorage.setItem(COLLECTION_STORAGE_KEY, id);
updateUrlForCollection(id);
loadQuestionsFromCollection(id);
updateCollectionTitleById(id);
} else {
localStorage.setItem(COLLECTION_STORAGE_KEY, 'custom');
updateUrlForCollection('custom');
updateCollectionTitleById('custom');
}
closeCollectionModal();
}
Expand Down Expand Up @@ -1438,6 +1489,7 @@ function handleCsvFileSelect(event) {
collectionSelect.value = 'custom';
localStorage.setItem(COLLECTION_STORAGE_KEY, 'custom');
updateUrlForCollection('custom');
updateCollectionTitleById('custom');
}
}
};
Expand Down
Loading