22 <div class =" flex justify-center items-center my-4 text-center" >
33 <div class =" mr-4" >
44 <label for =" nBack" class =" block text-sm font-medium text-gray-400" >N-Back</label >
5- <input type =" number" id =" nBack" :value =" nBack" @input =" $emit('update:nBack', $event.target.value)" min =" 1" class =" text-black mt-1 p-1 block w-20 rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" />
5+ <input
6+ type =" number"
7+ id =" nBack"
8+ v-model =" localNBack"
9+ @blur =" enforceMinNBack"
10+ min =" 1"
11+ class =" text-black mt-1 p-1 block w-20 rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50"
12+ />
613 </div >
714 <div >
815 <label for =" timeLeft" class =" block text-sm font-medium text-gray-400" >Timer (sec)</label >
9- <input type =" number" id =" timeLeft" :value =" timeLeft" @input =" $emit('update:timeLeft', $event.target.value)" min =" 1" class =" text-black mt-1 p-1 block w-20 rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" />
16+ <input
17+ type =" number"
18+ id =" timeLeft"
19+ v-model =" localTimeLeft"
20+ @blur =" enforceMinTimeLeft"
21+ min =" 1"
22+ class =" text-black mt-1 p-1 block w-20 rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50"
23+ />
1024 </div >
1125 </div >
12- <button @click =" $emit('startGame') " class =" mb-2 p-4 text-lg bg-blue-900 text-white font-medium rounded-md w-full shadow-sm hover:bg-blue-800 focus:outline-none focus:ring-2 focus:ring-blue-300" >
26+ <button @click =" handleStartGame " class =" mb-2 p-4 text-lg bg-blue-900 text-white font-medium rounded-md w-full shadow-sm hover:bg-blue-800 focus:outline-none focus:ring-2 focus:ring-blue-300" >
1327 Start Game
1428 </button >
1529</template >
@@ -28,5 +42,41 @@ export default {
2842 }
2943 },
3044 emits: [' update:nBack' , ' update:timeLeft' , ' startGame' ],
45+ data () {
46+ return {
47+ localNBack: this .nBack ,
48+ localTimeLeft: this .timeLeft
49+ };
50+ },
51+ watch: {
52+ nBack (val ) {
53+ this .localNBack = val;
54+ },
55+ timeLeft (val ) {
56+ this .localTimeLeft = val;
57+ }
58+ },
59+ methods: {
60+ enforceMinNBack () {
61+ const value = Math .max (1 , parseInt (this .localNBack ) || 1 );
62+ this .localNBack = value;
63+ this .$emit (' update:nBack' , value);
64+ },
65+ enforceMinTimeLeft () {
66+ const value = Math .max (1 , parseInt (this .localTimeLeft ) || 1 );
67+ this .localTimeLeft = value;
68+ this .$emit (' update:timeLeft' , value);
69+ },
70+ handleStartGame () {
71+ // Ensure valid values before starting
72+ const nBack = Math .max (1 , parseInt (this .localNBack ) || 1 );
73+ const timeLeft = Math .max (1 , parseInt (this .localTimeLeft ) || 1 );
74+ this .localNBack = nBack;
75+ this .localTimeLeft = timeLeft;
76+ this .$emit (' update:nBack' , nBack);
77+ this .$emit (' update:timeLeft' , timeLeft);
78+ this .$emit (' startGame' );
79+ }
80+ }
3181}
3282 </script >
0 commit comments