From 77209f610b638f066bae37e267a42b0b46cf535d Mon Sep 17 00:00:00 2001 From: dev Date: Sat, 7 Nov 2026 12:40:06 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=BF=D0=BE=D0=B2=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=BE=D0=B5=20=D0=BF=D0=BE=D1=8F=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BF=D0=BE=D0=B4=D1=81=D0=BA=D0=B0=D0=B7=D0=BE=D0=BA?= =?UTF-8?q?=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8F=20=D0=BD=D0=B0=20=D0=B3?= =?UTF-8?q?=D0=BB=D0=B0=D0=B2=D0=BD=D0=BE=D0=B9=20=D1=81=D1=82=D1=80=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=86=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/index.js | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/public/js/index.js b/public/js/index.js index dc01b20..3e4a901 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -10,6 +10,8 @@ const moduleField = document.getElementById('moduleField'); const moduleNames = new Map(); const moduleAttachments = new Map(); let moduleSearchTimer = null; +let moduleSearchSeq = 0; +let moduleOptionsKey = ''; const toast = document.getElementById('toast'); const camVideo = document.getElementById('camVideo'); const camCanvas = document.getElementById('camCanvas'); @@ -248,8 +250,20 @@ if (params.get('nameInput')) { field.innerHTML = `
${escName(studentName)}
`; } +function rememberModules(list) { + list.forEach(m => { + moduleNames.set(m.name, m.id); + moduleAttachments.set(m.name.toLowerCase(), m.has_attachments === true); + }); +} + function renderModuleOptions(list) { - list.forEach(m => { moduleNames.set(m.name, m.id); moduleAttachments.set(m.name.toLowerCase(), m.has_attachments === true); }); + rememberModules(list); + const value = (moduleInput.value || '').trim().toLowerCase(); + if (value && list.some(m => String(m.name).trim().toLowerCase() === value)) return; + const key = list.map(m => m.name).join('\n'); + if (key === moduleOptionsKey) return; + moduleOptionsKey = key; moduleInputList.innerHTML = ''; list.forEach(m => { const opt = document.createElement('option'); @@ -298,7 +312,7 @@ async function resolveModuleId(name) { const cached = findModuleId(n); if (cached) return cached; const list = await fetchModules(n, 5); - if (list) renderModuleOptions(list); + if (list) rememberModules(list); const lower = n.toLowerCase(); const exact = (list || []).find(m => m.name.toLowerCase() === lower); return exact ? exact.id : null; @@ -307,9 +321,10 @@ async function resolveModuleId(name) { (async () => { await initDateTime(); try { + const seq = moduleSearchSeq; const list = await fetchModules('', MODULE_LIST_LIMIT); if (list) { - renderModuleOptions(list); + if (seq === moduleSearchSeq) renderModuleOptions(list); if (list.length) { moduleInput.required = true; moduleField.style.display = ''; @@ -547,17 +562,25 @@ moduleInput.addEventListener('input', () => { updateAttachHint(); clearTimeout(moduleSearchTimer); const q = moduleInput.value.trim(); + const seq = ++moduleSearchSeq; moduleSearchTimer = setTimeout(async () => { const list = await fetchModules(q, q ? 20 : MODULE_LIST_LIMIT); + if (seq !== moduleSearchSeq) return; if (list) renderModuleOptions(list); updateAttachHint(); }, 250); }); +moduleInput.addEventListener('change', () => { + clearTimeout(moduleSearchTimer); + moduleSearchSeq++; + updateAttachHint(); +}); moduleInput.addEventListener('focus', async () => { - if (!moduleInput.value.trim()) { - const list = await fetchModules('', MODULE_LIST_LIMIT); - if (list) renderModuleOptions(list); - } + if (moduleInput.value.trim()) return; + const seq = ++moduleSearchSeq; + const list = await fetchModules('', MODULE_LIST_LIMIT); + if (seq !== moduleSearchSeq) return; + if (list) renderModuleOptions(list); }); (async () => {