Move Wettkampf question count to admin-configured setting per set

This commit is contained in:
2026-04-26 11:22:08 +02:00
parent 7b886c4355
commit 5980aaab41
3 changed files with 41 additions and 30 deletions
+14 -24
View File
@@ -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 ? (
<>
<h3 className="text-lg font-semibold mt-4">Fragenset wählen:</h3>
{sets.length === 0 && <p className="text-gray-500">Keine Fragensets konfiguriert.</p>}
{sets.length === 0 && <p className="text-gray-500">Keine Wettkampf-Sets konfiguriert. Bitte im Admin-Bereich konfigurieren.</p>}
{sets.map((s) => (
<button key={s.id} onClick={() => selectSet(s)}
className="w-full py-4 bg-emerald-600 hover:bg-emerald-700 rounded-xl text-lg font-bold transition-all shadow-lg shadow-emerald-900/30">
{s.name}
{s.name} <span className="text-emerald-200 text-sm">({s.wettkampfCount} Fragen)</span>
</button>
))}
</>
@@ -775,24 +775,14 @@ function WettkampfSelectPage({ navigate }) {
<div>
<span className="text-sm text-gray-400">Fragenset:</span>
<p className="font-bold text-emerald-400">{selectedSet.name}</p>
<p className="text-sm text-gray-400">{selectedSet.wettkampfCount} Fragen{totalQuestions ? ` (von ${totalQuestions} gesamt)` : ''}</p>
</div>
<button onClick={() => { setSelectedSet(null); setTotalQuestions(null); setQuestionCount(''); }} className="text-sm text-gray-400 hover:text-white">Ändern</button>
<button onClick={() => { setSelectedSet(null); setTotalQuestions(null); }} className="text-sm text-gray-400 hover:text-white">Ändern</button>
</div>
{totalQuestions !== null && (
<div className="space-y-2">
<label className="block text-sm text-gray-400">Anzahl Fragen (max. {totalQuestions})</label>
<input type="number" min="1" max={totalQuestions}
className="w-full p-4 rounded-xl bg-gray-800 text-white text-center text-xl border-2 border-gray-700 focus:border-emerald-500 outline-none"
placeholder={`1 ${totalQuestions}`}
value={questionCount}
onChange={(e) => setQuestionCount(e.target.value)} />
</div>
)}
{error && <p className="text-red-400">{error}</p>}
<button onClick={startWettkampf} disabled={checking || !questionCount}
<button onClick={startWettkampf} disabled={checking}
className="w-full py-4 bg-emerald-600 hover:bg-emerald-700 disabled:opacity-40 rounded-xl text-xl font-bold transition-all shadow-lg shadow-emerald-900/30">
{checking ? 'Prüfe...' : '⚔️ Wettkampf starten'}
</button>