Files
2026-06-16 11:59:29 +02:00

166 lines
3.2 KiB
PHP

<?php
require_once __DIR__ . '/includes/config.php';
require_once __DIR__ . '/includes/auth.php';
requireLogin();
$lang = $_GET['lang'] ?? 'latijn';
$list = $_GET['list'] ?? 'test';
?>
<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="UTF-8">
<title>Woordjes oefenen</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#222">
<link rel="manifest" href="/manifest.json">
<link rel="stylesheet" href="/assets/css/style.css">
<link rel="apple-touch-icon" sizes="180x180" href="/assets/img/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/assets/img/favicon.ico">
<link rel="icon" type="image/png" sizes="16x16" href="/assets/img/favicon-16x16.png">
</head>
<body>
<div class="container">
<div class="card">
<h1>Oefenen</h1>
<p>
Vertaal:
<strong id="question">laden...</strong>
</p>
<input id="answer" autocomplete="off" placeholder="Typ je antwoord">
<button onclick="check()">Controleer</button>
<p id="result"></p>
<p id="stats"></p>
</div>
</div>
<div class="bottom-bar">
<a href="/dashboard.php">Dashboard</a>
<a href="/logout.php">Logout</a>
</div>
<script type="module">
import { initDB } from "/assets/js/db.js";
import {
importList,
getNextWord,
answerWord,
getSessionStats
} from "/assets/js/offline-engine.js";
import { syncQueue } from "/assets/js/sync.js";
await initDB();
const lang = "<?= $lang ?>";
const list = "<?= $list ?>";
let currentWord = null;
/**
* INIT: import woordenlijst naar IndexedDB
*/
await importList(lang, list);
/**
* WORD LOAD
*/
async function loadWord() {
currentWord = await getNextWord(lang, list);
if (!currentWord) {
document.getElementById("question").innerText =
"Geen woorden gevonden";
return;
}
document.getElementById("question").innerText =
currentWord.question;
document.getElementById("answer").value = "";
document.getElementById("result").innerText = "";
updateStats();
}
/**
* CHECK ANSWER
*/
window.check = async function () {
const input = document.getElementById("answer").value;
if (!currentWord) return;
const res = await answerWord(currentWord, input);
const result = document.getElementById("result");
if (res.correct) {
result.innerText = "Goed";
result.style.color = "green";
} else {
result.innerText =
`Fout — correct antwoord: ${res.correctAnswer}`;
result.style.color = "red";
}
await updateStats();
setTimeout(() => {
loadWord();
}, 800);
};
/**
* SESSION STATS
*/
async function updateStats() {
const stats =
await getSessionStats();
document.getElementById("stats").innerText =
`Sessie → Goed: ${stats.correct} | Fout: ${stats.wrong}`;
}
/**
* ENTER SUPPORT
*/
document.getElementById("answer").addEventListener("keydown", (e) => {
if (e.key === "Enter") {
check();
}
});
/**
* INIT FIRST WORD
*/
loadWord();
/**
* SYNC WHEN ONLINE
*/
window.addEventListener("online", () => {
syncQueue();
});
</script>
</body>
</html>