-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1141 lines (1033 loc) · 43.1 KB
/
Copy pathindex.html
File metadata and controls
1141 lines (1033 loc) · 43.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="da">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gangetabel Træning</title>
<!-- React -->
<script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
<!-- Babel for JSX -->
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<!-- Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Lucide Icons -->
<script src="https://unpkg.com/lucide@latest"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
const { useState, useEffect, useRef } = React;
// Icon component using Lucide
const Icon = ({ name, className = "" }) => {
useEffect(() => {
// Replace icons after render
lucide.createIcons();
});
const iconMap = {
'Trophy': 'trophy',
'Star': 'star',
'Target': 'target',
'Clock': 'clock',
'CheckCircle': 'check-circle',
'XCircle': 'x-circle',
'BarChart3': 'bar-chart-3',
'Zap': 'zap',
'Play': 'play',
'Book': 'book',
'Settings': 'settings',
'ArrowLeft': 'arrow-left',
'Volume2': 'volume-2',
'VolumeX': 'volume-x',
'Lightbulb': 'lightbulb'
};
return (
<i
data-lucide={iconMap[name] || name.toLowerCase()}
className={className}
></i>
);
};
const GangetabelApp = () => {
// State management
const [currentMode, setCurrentMode] = useState('menu');
// Load settings from localStorage
const [selectedTables, setSelectedTables] = useState(() => {
const saved = localStorage.getItem('gangetabelSettings');
return saved ? JSON.parse(saved).selectedTables || [2, 3, 4, 5] : [2, 3, 4, 5];
});
const [practiceType, setPracticeType] = useState(() => {
const saved = localStorage.getItem('gangetabelSettings');
return saved ? JSON.parse(saved).practiceType || 'multiple' : 'multiple';
});
const [practiceLength, setPracticeLength] = useState(() => {
const saved = localStorage.getItem('gangetabelSettings');
return saved ? JSON.parse(saved).practiceLength || 10 : 10;
});
const [soundEnabled, setSoundEnabled] = useState(() => {
const saved = localStorage.getItem('gangetabelSettings');
return saved ? JSON.parse(saved).soundEnabled !== false : true;
});
const [currentQuestion, setCurrentQuestion] = useState(null);
const [userAnswer, setUserAnswer] = useState('');
const [feedback, setFeedback] = useState(null);
const [sessionStats, setSessionStats] = useState({ correct: 0, total: 0 });
const [streak, setStreak] = useState(0);
const [showNextButton, setShowNextButton] = useState(false);
const [isSessionActive, setIsSessionActive] = useState(false);
const [showHint, setShowHint] = useState(false);
const [hintUsed, setHintUsed] = useState(false);
const [sessionStartTime, setSessionStartTime] = useState(null);
const [elapsedTime, setElapsedTime] = useState(0);
const [toast, setToast] = useState(null);
// Toast notification system
const showToast = (message, type = 'info') => {
setToast({ message, type });
setTimeout(() => setToast(null), 3000);
};
// Modal component
const Modal = ({ isOpen, onClose, onConfirm, title, message, confirmText = "Ja", cancelText = "Nej" }) => {
if (!isOpen) return null;
return (
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4">
<div className="bg-white rounded-2xl shadow-2xl p-6 max-w-sm w-full transform transition-all duration-300 scale-100">
<h3 className="text-xl font-bold mb-3">{title}</h3>
<p className="text-gray-600 mb-6">{message}</p>
<div className="flex gap-3 justify-end">
<button
onClick={onClose}
className="px-4 py-2 text-gray-600 hover:bg-gray-100 rounded-lg transition-colors"
>
{cancelText}
</button>
<button
onClick={() => {
onConfirm();
onClose();
}}
className="px-4 py-2 bg-red-500 text-white rounded-lg hover:bg-red-600 transition-colors"
>
{confirmText}
</button>
</div>
</div>
</div>
);
};
const [showResetModal, setShowResetModal] = useState(false);
const [showEndSessionModal, setShowEndSessionModal] = useState(false);
// Audio refs
const correctSoundRef = useRef(null);
const incorrectSoundRef = useRef(null);
const clickSoundRef = useRef(null);
// Progress tracking
const [progress, setProgress] = useState(() => {
try {
const saved = localStorage.getItem('gangetabelProgress');
return saved ? JSON.parse(saved) : {
facts: {},
lastPractice: null
};
} catch (e) {
return {
facts: {},
lastPractice: null
};
}
});
// Save settings whenever they change
useEffect(() => {
const settings = {
selectedTables,
practiceType,
practiceLength,
soundEnabled
};
localStorage.setItem('gangetabelSettings', JSON.stringify(settings));
}, [selectedTables, practiceType, practiceLength, soundEnabled]);
// Timer for practice sessions
useEffect(() => {
let interval;
if (isSessionActive && sessionStartTime) {
interval = setInterval(() => {
setElapsedTime(Math.floor((Date.now() - sessionStartTime) / 1000));
}, 1000);
}
return () => clearInterval(interval);
}, [isSessionActive, sessionStartTime]);
// Format time display
const formatTime = (seconds) => {
const mins = Math.floor(seconds / 60);
const secs = seconds % 60;
return `${mins}:${secs.toString().padStart(2, '0')}`;
};
// Initialize audio on component mount
useEffect(() => {
// Create simple beep sounds using Web Audio API as data URLs don't work well
try {
const AudioContext = window.AudioContext || window.webkitAudioContext;
if (AudioContext) {
const createBeep = (frequency, duration) => {
return () => {
if (!soundEnabled) return;
const audioContext = new AudioContext();
const oscillator = audioContext.createOscillator();
const gainNode = audioContext.createGain();
oscillator.connect(gainNode);
gainNode.connect(audioContext.destination);
oscillator.frequency.value = frequency;
oscillator.type = 'sine';
gainNode.gain.setValueAtTime(0.3, audioContext.currentTime);
gainNode.gain.exponentialRampToValueAtTime(0.01, audioContext.currentTime + duration);
oscillator.start(audioContext.currentTime);
oscillator.stop(audioContext.currentTime + duration);
};
};
window.playCorrectSound = createBeep(800, 0.15);
window.playIncorrectSound = createBeep(300, 0.25);
window.playClickSound = createBeep(600, 0.05);
}
} catch (e) {
console.log('Could not initialize audio:', e);
}
}, [soundEnabled]);
// Play sound helper
const playSound = (type) => {
if (!soundEnabled) return;
try {
if (type === 'correct' && window.playCorrectSound) {
window.playCorrectSound();
} else if (type === 'incorrect' && window.playIncorrectSound) {
window.playIncorrectSound();
} else if (type === 'click' && window.playClickSound) {
window.playClickSound();
}
} catch (error) {
console.log('Audio play failed:', error);
}
};
// Vibrate helper
const vibrate = (pattern) => {
if (!soundEnabled) return;
if ('vibrate' in navigator) {
navigator.vibrate(pattern);
}
};
// Generate hint for multiplication
const generateHint = (a, b) => {
const hints = [];
if (a > 5 && a !== 10) {
hints.push(`Prøv at dele op: ${a}×${b} = (5×${b}) + (${a-5}×${b}) = ${5*b} + ${(a-5)*b}`);
}
if (a === 4 || a === 8) {
if (a === 4) {
hints.push(`${a}×${b} er det dobbelte af 2×${b} = ${2*b}, så svaret er ${2*b}×2`);
} else {
hints.push(`${a}×${b} er det dobbelte af 4×${b} = ${4*b}, så svaret er ${4*b}×2`);
}
}
if (a === 9) {
hints.push(`${a}×${b} = (10×${b}) - ${b} = ${10*b} - ${b}`);
}
if (b > a) {
hints.push(`Husk: ${a}×${b} er det samme som ${b}×${a}`);
}
if (a === 5) {
hints.push(`5-tabellen har et mønster: Slutter altid på 0 eller 5`);
}
if (a === b) {
hints.push(`${a}×${b} er et kvadrattal (${a} i anden)`);
}
if (hints.length === 0) {
hints.push(`Tænk på ${a} grupper med ${b} i hver gruppe`);
}
return hints[Math.floor(Math.random() * hints.length)];
};
// Generate question
const generateQuestion = () => {
const now = Date.now();
let candidates = [];
selectedTables.forEach(table => {
for (let i = 1; i <= 10; i++) {
const key = `${table}x${i}`;
const fact = progress.facts[key];
if (!fact || !fact.nextReview || fact.nextReview <= now) {
candidates.push({ a: table, b: i, priority: fact ? 1 : 2 });
}
}
});
if (candidates.length < 5) {
selectedTables.forEach(table => {
for (let i = 1; i <= 10; i++) {
if (Math.random() < 0.3) {
candidates.push({ a: table, b: i, priority: 0 });
}
}
});
}
if (candidates.length === 0) {
selectedTables.forEach(table => {
for (let i = 1; i <= 10; i++) {
candidates.push({ a: table, b: i, priority: 0 });
}
});
}
candidates.sort((a, b) => b.priority - a.priority);
const question = candidates[Math.floor(Math.random() * Math.min(4, candidates.length))];
if (question) {
const correctAnswer = question.a * question.b;
let options = [correctAnswer];
while (options.length < 4) {
const wrongAnswer = correctAnswer + (Math.random() < 0.5 ? -1 : 1) *
Math.floor(Math.random() * 10 + 1);
if (wrongAnswer > 0 && !options.includes(wrongAnswer)) {
options.push(wrongAnswer);
}
}
options.sort(() => Math.random() - 0.5);
setCurrentQuestion({
...question,
answer: correctAnswer,
options: options
});
}
};
// Handle answer submission
const handleAnswer = (answer) => {
playSound('click');
const isCorrect = answer === currentQuestion.answer;
const key = `${currentQuestion.a}x${currentQuestion.b}`;
if (isCorrect) {
playSound('correct');
vibrate([50, 100, 50]);
} else {
playSound('incorrect');
vibrate([200]);
}
setProgress(prev => {
const newFacts = { ...prev.facts };
const fact = newFacts[key] || { correct: 0, attempts: 0 };
fact.attempts++;
if (isCorrect) {
fact.correct++;
fact.lastSeen = Date.now();
const accuracy = fact.correct / fact.attempts;
let interval;
if (accuracy >= 0.9) {
interval = 7 * 24 * 60 * 60 * 1000;
} else if (accuracy >= 0.7) {
interval = 3 * 24 * 60 * 60 * 1000;
} else if (accuracy >= 0.5) {
interval = 24 * 60 * 60 * 1000;
} else {
interval = 60 * 60 * 1000;
}
fact.nextReview = Date.now() + interval;
}
newFacts[key] = fact;
return {
...prev,
facts: newFacts,
lastPractice: Date.now()
};
});
setSessionStats(prev => ({
correct: prev.correct + (isCorrect ? 1 : 0),
total: prev.total + 1
}));
setStreak(isCorrect ? streak + 1 : 0);
setFeedback({ isCorrect, correctAnswer: currentQuestion.answer });
setShowNextButton(true);
if (isCorrect && hintUsed) {
setHintUsed(false);
}
};
// Handle next question
const handleNextQuestion = () => {
setShowNextButton(false);
setFeedback(null);
setUserAnswer('');
setShowHint(false);
setHintUsed(false);
generateQuestion();
};
// Settings component
const SettingsPage = () => {
return (
<div className="p-4 max-w-md mx-auto">
<div className="flex items-center gap-4 mb-6">
<button
onClick={() => setCurrentMode('menu')}
className="flex items-center gap-2 text-gray-600 hover:text-gray-900 transition-colors"
>
<Icon name="ArrowLeft" className="w-5 h-5" />
<span>Tilbage</span>
</button>
<h2 className="text-2xl font-bold">Indstillinger</h2>
</div>
<div className="bg-white rounded-xl shadow-lg p-6 mb-6">
<h3 className="font-bold text-lg mb-4">Vælg tabeller til øvelser</h3>
<div className="grid grid-cols-5 gap-2 mb-6">
{[1,2,3,4,5,6,7,8,9,10].map(n => (
<button
key={n}
onClick={() => {
setSelectedTables(prev =>
prev.includes(n)
? prev.filter(t => t !== n)
: [...prev, n]
);
}}
className={`p-3 rounded-lg font-medium transition-all ${
selectedTables.includes(n)
? 'bg-blue-500 text-white'
: 'bg-gray-100 hover:bg-gray-200'
}`}
>
{n}
</button>
))}
</div>
<p className="text-sm text-gray-600">
Valgte tabeller: {selectedTables.sort((a,b) => a-b).join(', ')}
</p>
</div>
<div className="bg-white rounded-xl shadow-lg p-6 mb-6">
<h3 className="font-bold text-lg mb-4">Øvelsestype</h3>
<div className="space-y-3">
<label className="flex items-center p-3 rounded-lg cursor-pointer hover:bg-gray-50">
<input
type="radio"
checked={practiceType === 'multiple'}
onChange={() => setPracticeType('multiple')}
className="mr-3"
/>
<div>
<p className="font-medium">Valgmuligheder</p>
<p className="text-sm text-gray-600">Vælg mellem 4 mulige svar</p>
</div>
</label>
<label className="flex items-center p-3 rounded-lg cursor-pointer hover:bg-gray-50">
<input
type="radio"
checked={practiceType === 'input'}
onChange={() => setPracticeType('input')}
className="mr-3"
/>
<div>
<p className="font-medium">Indtast svar</p>
<p className="text-sm text-gray-600">Skriv svaret selv</p>
</div>
</label>
</div>
</div>
<div className="bg-white rounded-xl shadow-lg p-6 mb-6">
<h3 className="font-bold text-lg mb-4">Antal opgaver per øvelse</h3>
<div className="space-y-3">
{[5, 10, 15, 20].map(num => (
<label key={num} className="flex items-center p-3 rounded-lg cursor-pointer hover:bg-gray-50">
<input
type="radio"
checked={practiceLength === num}
onChange={() => setPracticeLength(num)}
className="mr-3"
/>
<div>
<p className="font-medium">{num} opgaver</p>
<p className="text-sm text-gray-600">
{num === 5 && 'Hurtig øvelse'}
{num === 10 && 'Standard øvelse'}
{num === 15 && 'Længere øvelse'}
{num === 20 && 'Grundig øvelse'}
</p>
</div>
</label>
))}
</div>
</div>
<div className="bg-white rounded-xl shadow-lg p-6 mb-6">
<h3 className="font-bold text-lg mb-4">Lyd og vibration</h3>
<label className="flex items-center p-3 rounded-lg cursor-pointer hover:bg-gray-50">
<input
type="checkbox"
checked={soundEnabled}
onChange={(e) => {
setSoundEnabled(e.target.checked);
if (e.target.checked) {
playSound('click');
}
}}
className="mr-3"
/>
<div className="flex items-center gap-3">
<Icon name={soundEnabled ? "Volume2" : "VolumeX"} className={`w-5 h-5 ${soundEnabled ? 'text-blue-500' : 'text-gray-400'}`} />
<div>
<p className="font-medium">Lyd og vibration aktiveret</p>
<p className="text-sm text-gray-600">Lydeffekter og haptisk feedback</p>
</div>
</div>
</label>
</div>
<button
onClick={() => setShowResetModal(true)}
className="w-full p-3 text-red-600 bg-red-50 rounded-xl hover:bg-red-100 transition-colors"
>
Nulstil alle fremskridt
</button>
<Modal
isOpen={showResetModal}
onClose={() => setShowResetModal(false)}
onConfirm={() => {
setProgress({
facts: {},
lastPractice: null
});
showToast('Alle fremskridt er blevet nulstillet', 'success');
}}
title="Nulstil fremskridt?"
message="Er du sikker på at du vil slette alle dine fremskridt? Dette kan ikke fortrydes."
confirmText="Ja, nulstil"
cancelText="Annuller"
/>
</div>
);
};
// Lookup table component
const LookupTable = () => {
const [selectedTable, setSelectedTable] = useState(5);
return (
<div className="p-4 max-w-md mx-auto">
<div className="flex items-center gap-4 mb-6">
<button
onClick={() => setCurrentMode('menu')}
className="flex items-center gap-2 text-gray-600 hover:text-gray-900 transition-colors"
>
<Icon name="ArrowLeft" className="w-5 h-5" />
<span>Tilbage</span>
</button>
<h2 className="text-2xl font-bold">Gangetabeller</h2>
</div>
<div className="flex gap-2 mb-6 flex-wrap">
{[1,2,3,4,5,6,7,8,9,10].map(n => (
<button
key={n}
onClick={() => setSelectedTable(n)}
className={`px-4 py-2 rounded-lg font-medium transition-all ${
selectedTable === n
? 'bg-blue-500 text-white transform scale-110'
: 'bg-gray-100 hover:bg-gray-200'
}`}
>
{n}
</button>
))}
</div>
<div className="bg-white rounded-lg shadow-lg p-6">
<h3 className="text-xl font-bold mb-4 text-center text-blue-600">{selectedTable}-tabellen</h3>
<div className="grid grid-cols-2 gap-3">
{[1,2,3,4,5,6,7,8,9,10].map(i => {
const key = `${selectedTable}x${i}`;
const fact = progress.facts[key];
const isLearned = fact && fact.correct / fact.attempts >= 0.8 && fact.attempts >= 3;
return (
<div key={i} className={`p-3 rounded-lg text-center transition-all ${
isLearned ? 'bg-green-50 border-2 border-green-200' : 'bg-gray-50'
}`}>
<span className="text-lg font-medium">
{selectedTable} × {i} = {selectedTable * i}
</span>
{isLearned && (
<Icon name="Star" className="w-4 h-4 text-green-500 mx-auto mt-1" />
)}
</div>
);
})}
</div>
</div>
</div>
);
};
// Practice component
const Practice = () => {
useEffect(() => {
if (!isSessionActive) {
generateQuestion();
setSessionStats({ correct: 0, total: 0 });
setStreak(0);
setShowHint(false);
setHintUsed(false);
setSessionStartTime(Date.now());
setElapsedTime(0);
setIsSessionActive(true);
}
}, [isSessionActive]);
const handleEndSession = () => {
if (sessionStats.total === 0) {
setIsSessionActive(false);
setFeedback(null);
setShowNextButton(false);
setCurrentMode('menu');
} else {
setShowEndSessionModal(true);
}
};
if (!currentQuestion) return null;
const progressPercentage = (sessionStats.total / practiceLength) * 100;
return (
<div className="p-4 max-w-md mx-auto">
<div className="flex justify-between items-center mb-4">
<button
onClick={handleEndSession}
className="flex items-center gap-2 text-gray-600 hover:text-gray-900 transition-colors"
>
<Icon name="ArrowLeft" className="w-5 h-5" />
<span>Afslut</span>
</button>
<div className="flex items-center gap-4">
<div className="flex items-center gap-1 bg-gray-50 px-3 py-1 rounded-full">
<Icon name="Clock" className="w-4 h-4 text-gray-500" />
<span className="font-medium">{formatTime(elapsedTime)}</span>
</div>
<div className="flex items-center gap-1 bg-blue-50 px-3 py-1 rounded-full">
<Icon name="Target" className="w-4 h-4 text-blue-500" />
<span className="font-medium">{sessionStats.correct}/{sessionStats.total}</span>
</div>
{streak > 2 && (
<div className="flex items-center gap-1 bg-yellow-50 px-3 py-1 rounded-full animate-pulse">
<Icon name="Zap" className="w-4 h-4 text-yellow-500" />
<span className="font-medium">{streak}</span>
</div>
)}
</div>
</div>
<div className="mb-6">
<div className="flex justify-between text-sm text-gray-600 mb-1">
<span>Opgave {sessionStats.total + 1} af {practiceLength}</span>
<span>{Math.round(progressPercentage)}%</span>
</div>
<div className="w-full bg-gray-200 rounded-full h-3">
<div
className="bg-gradient-to-r from-blue-400 to-blue-600 h-3 rounded-full transition-all duration-300"
style={{ width: `${progressPercentage}%` }}
/>
</div>
</div>
<div className="bg-white rounded-lg shadow-lg p-8 mb-6">
<h2 className="text-4xl font-bold text-center mb-8">
{currentQuestion.a} × {currentQuestion.b} = ?
</h2>
{practiceType === 'multiple' ? (
<div className="grid grid-cols-2 gap-4">
{currentQuestion.options.map((option, idx) => (
<button
key={idx}
onClick={() => {
if (!feedback) {
handleAnswer(option);
}
}}
disabled={feedback !== null}
className={`p-4 text-xl font-medium rounded-lg transition-all ${
feedback && option === currentQuestion.answer
? 'bg-green-500 text-white transform scale-105'
: feedback && option !== currentQuestion.answer
? 'bg-gray-200 text-gray-400'
: 'bg-blue-100 hover:bg-blue-200 text-blue-900 hover:transform hover:scale-105'
}`}
>
{option}
</button>
))}
</div>
) : (
<div className="flex flex-col items-center gap-4">
<input
type="number"
inputMode="numeric"
pattern="[0-9]*"
value={userAnswer}
onChange={(e) => setUserAnswer(e.target.value)}
onKeyPress={(e) => {
if (e.key === 'Enter' && userAnswer && !feedback) {
handleAnswer(parseInt(userAnswer));
}
}}
disabled={feedback !== null}
className="w-32 p-4 text-2xl text-center border-2 border-gray-300 rounded-lg focus:border-blue-500 focus:outline-none"
autoFocus
/>
{!feedback && (
<button
onClick={() => {
handleAnswer(parseInt(userAnswer));
}}
disabled={!userAnswer || feedback !== null}
className="px-6 py-3 bg-blue-500 text-white rounded-lg font-medium disabled:bg-gray-300 hover:bg-blue-600 transition-colors"
>
Svar
</button>
)}
</div>
)}
{!feedback && !showHint && sessionStats.total > 0 && (
<div className="mt-6 text-center">
<button
onClick={() => {
playSound('click');
setShowHint(true);
setHintUsed(true);
}}
className="flex items-center gap-2 mx-auto px-4 py-2 text-sm bg-yellow-100 text-yellow-800 rounded-lg hover:bg-yellow-200 transition-colors"
>
<Icon name="Lightbulb" className="w-4 h-4" />
Få et hint
</button>
</div>
)}
{showHint && !feedback && (
<div className="mt-4 p-3 bg-yellow-50 border border-yellow-200 rounded-lg text-sm text-yellow-800">
<p className="font-medium mb-1">💡 Hint:</p>
<p>{generateHint(currentQuestion.a, currentQuestion.b)}</p>
</div>
)}
{feedback && (
<div className={`mt-6 p-4 rounded-lg text-center ${
feedback.isCorrect ? 'bg-green-100' : 'bg-red-100'
}`}>
{feedback.isCorrect ? (
<div className="flex items-center justify-center gap-2 text-green-700">
<Icon name="CheckCircle" className="w-6 h-6" />
<span className="text-lg font-medium">
{hintUsed ? 'Godt klaret med hjælp!' : 'Rigtigt! Fantastisk!'}
</span>
</div>
) : (
<div className="text-red-700">
<Icon name="XCircle" className="w-6 h-6 mx-auto mb-2" />
<p className="font-medium">Ikke helt...</p>
<p className="text-lg mt-1">
{currentQuestion.a} × {currentQuestion.b} = {feedback.correctAnswer}
</p>
{!hintUsed && (
<p className="text-sm mt-2 text-gray-600">
Tip: Prøv at bruge hint-knappen næste gang!
</p>
)}
</div>
)}
</div>
)}
{showNextButton && (
<div className="mt-6 text-center">
<button
onClick={() => {
playSound('click');
if (sessionStats.total >= practiceLength - 1) {
const finalScore = sessionStats.correct + (feedback.isCorrect ? 1 : 0);
showToast(`Fantastisk! Du fik ${finalScore} ud af ${practiceLength} rigtige!`, 'success');
setTimeout(() => {
handleEndSession();
}, 1500);
} else {
handleNextQuestion();
}
}}
className="px-6 py-3 bg-blue-500 text-white rounded-lg font-medium hover:bg-blue-600 transition-colors"
>
{sessionStats.total >= practiceLength - 1 ? 'Afslut øvelse' : 'Næste opgave →'}
</button>
</div>
)}
</div>
<Modal
isOpen={showEndSessionModal}
onClose={() => setShowEndSessionModal(false)}
onConfirm={() => {
setIsSessionActive(false);
setFeedback(null);
setShowNextButton(false);
setCurrentMode('menu');
}}
title="Afslut øvelse?"
message="Er du sikker på at du vil afslutte øvelsen?"
confirmText="Ja, afslut"
cancelText="Fortsæt"
/>
</div>
);
};
// Stats component
const Stats = () => {
// Calculate stats per table
const getTableStats = (tableNumber) => {
let correct = 0;
let incorrect = 0;
for (let i = 1; i <= 10; i++) {
const key = `${tableNumber}x${i}`;
const fact = progress.facts[key];
if (fact) {
correct += fact.correct;
incorrect += (fact.attempts - fact.correct);
}
}
return { correct, incorrect, total: correct + incorrect };
};
// Get overall stats
const getOverallStats = () => {
let totalCorrect = 0;
let totalIncorrect = 0;
Object.values(progress.facts).forEach(fact => {
totalCorrect += fact.correct;
totalIncorrect += (fact.attempts - fact.correct);
});
return {
correct: totalCorrect,
incorrect: totalIncorrect,
total: totalCorrect + totalIncorrect
};
};
const overallStats = getOverallStats();
return (
<div className="p-4 max-w-md mx-auto">
<div className="flex items-center gap-4 mb-6">
<button
onClick={() => setCurrentMode('menu')}
className="flex items-center gap-2 text-gray-600 hover:text-gray-900 transition-colors"
>
<Icon name="ArrowLeft" className="w-5 h-5" />
<span>Tilbage</span>
</button>
<h2 className="text-2xl font-bold">Statistik</h2>
</div>
{/* Overall stats */}
<div className="bg-gradient-to-r from-blue-500 to-blue-600 text-white rounded-lg p-6 mb-6">
<h3 className="text-lg font-medium mb-3">Samlet statistik</h3>
<div className="grid grid-cols-3 gap-4 text-center">
<div>
<p className="text-3xl font-bold">{overallStats.correct}</p>
<p className="text-sm text-blue-100">Rigtige</p>
</div>
<div>
<p className="text-3xl font-bold">{overallStats.incorrect}</p>
<p className="text-sm text-blue-100">Forkerte</p>
</div>
<div>
<p className="text-3xl font-bold">
{overallStats.total > 0
? Math.round((overallStats.correct / overallStats.total) * 100)
: 0}%
</p>
<p className="text-sm text-blue-100">Korrekt</p>
</div>
</div>
</div>
{/* Stats per table */}
<div className="bg-white rounded-lg shadow p-4">
<h3 className="font-bold mb-4">Statistik per tabel</h3>
<div className="space-y-3">
{[1,2,3,4,5,6,7,8,9,10].map(table => {
const stats = getTableStats(table);
const percentage = stats.total > 0
? Math.round((stats.correct / stats.total) * 100)
: 0;
return (
<div key={table} className="border-b border-gray-100 pb-3 last:border-0">
<div className="flex items-center justify-between mb-2">
<span className="font-medium">{table}-tabellen</span>
{stats.total > 0 && (
<span className={`text-sm font-medium ${
percentage >= 80 ? 'text-green-600' :
percentage >= 60 ? 'text-yellow-600' :
'text-red-600'
}`}>
{percentage}%
</span>
)}
</div>
<div className="flex items-center gap-4 text-sm">
<span className="text-green-600">
✓ {stats.correct} rigtige
</span>
<span className="text-red-600">
✗ {stats.incorrect} forkerte
</span>
{stats.total === 0 && (
<span className="text-gray-400">Ikke øvet endnu</span>
)}
</div>
{stats.total > 0 && (
<div className="w-full bg-gray-200 rounded-full h-2 mt-2">
<div
className={`h-2 rounded-full transition-all duration-500 ${
percentage >= 80 ? 'bg-green-500' :
percentage >= 60 ? 'bg-yellow-500' :
'bg-red-500'
}`}
style={{ width: `${percentage}%` }}
/>
</div>
)}
</div>
);
})}
</div>
</div>
{/* Reset button */}
<button
onClick={() => {
if (window.confirm('Er du sikker på at du vil nulstille al statistik?')) {
setProgress({
facts: {},
lastPractice: null
});
alert('Al statistik er blevet nulstillet!');
}
}}
className="mt-6 w-full p-3 text-red-600 bg-red-50 rounded-lg hover:bg-red-100 transition-colors"
>
Nulstil al statistik
</button>
</div>
);
};
// Main menu
const MainMenu = () => (
<div className="p-4 max-w-md mx-auto">
<div className="text-center mb-8">
<h1 className="text-4xl font-bold mb-3 bg-gradient-to-r from-blue-600 to-purple-600 bg-clip-text text-transparent">
Gangetabel Træning
</h1>
<p className="text-gray-600">Lær gangetabellerne på en sjov måde!</p>
{selectedTables.length === 0 && (
<div className="mt-4 p-3 bg-amber-50 text-amber-800 rounded-lg text-sm">