From 5980aaab419aebfb94e9fb38d08bd6ef26cf700f Mon Sep 17 00:00:00 2001 From: orfelorfel23 Date: Sun, 26 Apr 2026 11:22:08 +0200 Subject: [PATCH] Move Wettkampf question count to admin-configured setting per set --- public/js/admin.js | 31 ++++++++++++++++++++++++++----- public/js/app.js | 38 ++++++++++++++------------------------ server/index.js | 2 +- 3 files changed, 41 insertions(+), 30 deletions(-) diff --git a/public/js/admin.js b/public/js/admin.js index f42d344..332f06c 100644 --- a/public/js/admin.js +++ b/public/js/admin.js @@ -59,19 +59,22 @@ function LoginPage({ onLogin }) { function ConfigPage({ config, setConfig, saveConfig }) { const [newSetName, setNewSetName] = useState(''); const [newSetTableId, setNewSetTableId] = useState(''); + const [newSetWettkampfCount, setNewSetWettkampfCount] = useState(''); const [msg, setMsg] = useState(''); const [debugResult, setDebugResult] = useState(null); const addSet = () => { if (!newSetName || !newSetTableId) return; + const wkCount = parseInt(newSetWettkampfCount) || null; const updated = { ...config, - sets: [...(config.sets || []), { id: Date.now().toString(36), name: newSetName, tableId: parseInt(newSetTableId) }], + sets: [...(config.sets || []), { id: Date.now().toString(36), name: newSetName, tableId: parseInt(newSetTableId), wettkampfCount: wkCount }], }; setConfig(updated); saveConfig(updated); setNewSetName(''); setNewSetTableId(''); + setNewSetWettkampfCount(''); setMsg('Fragenset hinzugefügt!'); setTimeout(() => setMsg(''), 3000); }; @@ -82,6 +85,16 @@ function ConfigPage({ config, setConfig, saveConfig }) { saveConfig(updated); }; + const updateSetWettkampfCount = (setId, val) => { + const wkCount = parseInt(val) || null; + const updated = { + ...config, + sets: config.sets.map((s) => s.id === setId ? { ...s, wettkampfCount: wkCount } : s), + }; + setConfig(updated); + saveConfig(updated); + }; + const updateAnswersTable = (val) => { const updated = { ...config, answersTableId: val ? parseInt(val) : null }; setConfig(updated); @@ -104,14 +117,22 @@ function ConfigPage({ config, setConfig, saveConfig }) {

📋 Fragensets

{(config.sets || []).length === 0 &&

Noch keine Fragensets konfiguriert.

} {(config.sets || []).map((s) => ( -
-
{s.name} (Table ID: {s.tableId})
- +
+
+
{s.name} (Table ID: {s.tableId})
+ +
+
+ ⚔️ Wettkampf-Fragen: + updateSetWettkampfCount(s.id, e.target.value)} /> + {s.wettkampfCount ? ✓ aktiv : nicht konfiguriert} +
))}
setNewSetName(e.target.value)} /> - setNewSetTableId(e.target.value)} /> + setNewSetTableId(e.target.value)} /> + setNewSetWettkampfCount(e.target.value)} />
{msg &&

{msg}

} diff --git a/public/js/app.js b/public/js/app.js index 1d6e4c5..b8177de 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -680,18 +680,20 @@ function WettkampfSelectPage({ navigate }) { const [sets, setSets] = useState([]); const [name, setName] = useState(''); const [selectedSet, setSelectedSet] = useState(null); - const [questionCount, setQuestionCount] = useState(''); const [totalQuestions, setTotalQuestions] = useState(null); const [error, setError] = useState(''); const [checking, setChecking] = useState(false); const [progressDialog, setProgressDialog] = useState(null); - useEffect(() => { api.get('/api/sets').then(setSets).catch((e) => setError(e.message)); }, []); + useEffect(() => { + api.get('/api/sets').then((allSets) => { + // Only show sets with a configured wettkampfCount + setSets(allSets.filter((s) => s.wettkampfCount && s.wettkampfCount > 0)); + }).catch((e) => setError(e.message)); + }, []); const selectSet = async (set) => { setSelectedSet(set); - setQuestionCount(''); - setTotalQuestions(null); try { const data = await api.get(`/api/sets/${set.id}/count`); setTotalQuestions(data.count); @@ -702,9 +704,7 @@ function WettkampfSelectPage({ navigate }) { const startWettkampf = async () => { if (!name.trim()) return setError('Bitte Name eingeben'); - const count = parseInt(questionCount); - if (!count || count < 1) return setError('Bitte Anzahl der Fragen eingeben'); - if (count > totalQuestions) return setError(`Maximal ${totalQuestions} Fragen verfügbar`); + const count = selectedSet.wettkampfCount; setChecking(true); setError(''); try { @@ -723,7 +723,7 @@ function WettkampfSelectPage({ navigate }) { const continueSession = () => { navigate('wettkampf-quiz', { setId: selectedSet.id, setName: selectedSet.name, - name: name.trim(), questionCount: progressDialog.count, + name: name.trim(), questionCount: selectedSet.wettkampfCount, continueSessionId: progressDialog.sessionId, priorAnswers: progressDialog.answers, }); @@ -733,7 +733,7 @@ function WettkampfSelectPage({ navigate }) { const startFresh = () => { navigate('wettkampf-quiz', { setId: selectedSet.id, setName: selectedSet.name, - name: name.trim(), questionCount: parseInt(questionCount), + name: name.trim(), questionCount: selectedSet.wettkampfCount, }); setProgressDialog(null); }; @@ -761,11 +761,11 @@ function WettkampfSelectPage({ navigate }) { {!selectedSet ? ( <>

Fragenset wählen:

- {sets.length === 0 &&

Keine Fragensets konfiguriert.

} + {sets.length === 0 &&

Keine Wettkampf-Sets konfiguriert. Bitte im Admin-Bereich konfigurieren.

} {sets.map((s) => ( ))} @@ -775,24 +775,14 @@ function WettkampfSelectPage({ navigate }) {
Fragenset:

{selectedSet.name}

+

{selectedSet.wettkampfCount} Fragen{totalQuestions ? ` (von ${totalQuestions} gesamt)` : ''}

- +
- {totalQuestions !== null && ( -
- - setQuestionCount(e.target.value)} /> -
- )} - {error &&

{error}

} - diff --git a/server/index.js b/server/index.js index b06d867..434f1a5 100644 --- a/server/index.js +++ b/server/index.js @@ -90,7 +90,7 @@ function rewriteImageUrls(rows) { app.get('/api/sets', (req, res) => { const config = readConfig(); - res.json((config.sets || []).map((s) => ({ id: s.id, name: s.name }))); + res.json((config.sets || []).map((s) => ({ id: s.id, name: s.name, wettkampfCount: s.wettkampfCount || null }))); }); app.get('/api/sets/:id/questions', async (req, res) => {