@@ -33,9 +33,9 @@ const AsmaUlHusnaPuzzle: React.FC<AsmaUlHusnaPuzzleProps> = ({ setIndex, onCompl
3333 const pieceHeight = 70 ;
3434 const gap = 25 ;
3535 const canvasWidth = cols * ( pieceWidth + gap ) + 100 ;
36- const canvasHeight = 420 ; // Extra space for hints
36+ const canvasHeight = 420 ;
3737 const startX = 50 ;
38- const startY = 110 ; // Move down to make room for hints
38+ const startY = 110 ;
3939
4040 const [ snapSound ] = useState ( ( ) => new Audio ( 'data:audio/wav;base64,UklGRnoGAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQoGAACBhYqFbF1fdJivrJBhNjVgodDbq2EcBj+a2/LDciUFLIHO8tiJNwgZaLvt559NEAxQp+PwtmMcBjiR1/LMeSwF' ) ) ;
4141 const [ victorySound ] = useState ( ( ) => new Audio ( 'data:audio/wav;base64,UklGRiQFAABXQVZFZm10IBAAAAABAAEAIlYAAESsAAACABAAZGF0YQdFAACAhYqFbF1fdJivrJBhNjVgodDbq2EcBj+a2/LDciUFLIHO8tiJNwgZaLvt559NEAxQp+PwtmMcBjiR1/LMeSwF' ) ) ;
@@ -47,15 +47,14 @@ const AsmaUlHusnaPuzzle: React.FC<AsmaUlHusnaPuzzleProps> = ({ setIndex, onCompl
4747 const initializePuzzle = ( ) => {
4848 const initialPieces : PuzzlePiece [ ] = [ ] ;
4949
50- // Fixed order: column 0 = name 0, column 1 = name 1, etc.
5150 names . forEach ( ( name , i ) => {
5251 initialPieces . push ( {
5352 id : i * 2 ,
5453 text : name . arabic ,
5554 x : 50 + Math . random ( ) * 300 ,
5655 y : 250 + Math . random ( ) * 60 ,
5756 isArabic : true ,
58- correctCol : i , // Fixed: Arabic goes to column i
57+ correctCol : i ,
5958 currentCol : - 1 ,
6059 currentRow : - 1 ,
6160 } ) ;
@@ -65,7 +64,7 @@ const AsmaUlHusnaPuzzle: React.FC<AsmaUlHusnaPuzzleProps> = ({ setIndex, onCompl
6564 x : 300 + Math . random ( ) * 300 ,
6665 y : 250 + Math . random ( ) * 60 ,
6766 isArabic : false ,
68- correctCol : i , // English also goes to column i
67+ correctCol : i ,
6968 currentCol : - 1 ,
7069 currentRow : - 1 ,
7170 } ) ;
@@ -87,7 +86,7 @@ const AsmaUlHusnaPuzzle: React.FC<AsmaUlHusnaPuzzleProps> = ({ setIndex, onCompl
8786
8887 ctx . clearRect ( 0 , 0 , canvas . width , canvas . height ) ;
8988
90- // Draw hints: Number + Arabic name at top
89+ // Draw hints
9190 ctx . fillStyle = '#4B0082' ;
9291 ctx . font = 'bold 20px Amiri, serif' ;
9392 ctx . textAlign = 'center' ;
@@ -105,7 +104,6 @@ const AsmaUlHusnaPuzzle: React.FC<AsmaUlHusnaPuzzleProps> = ({ setIndex, onCompl
105104 const y = startY + row * ( pieceHeight + gap ) ;
106105 ctx . strokeRect ( x , y , pieceWidth , pieceHeight ) ;
107106
108- // Row labels
109107 ctx . fillStyle = '#555' ;
110108 ctx . font = '14px Arial' ;
111109 ctx . textAlign = 'left' ;
@@ -133,19 +131,21 @@ const AsmaUlHusnaPuzzle: React.FC<AsmaUlHusnaPuzzleProps> = ({ setIndex, onCompl
133131 ctx . fillText ( piece . text , piece . x + pieceWidth / 2 , piece . y + pieceHeight / 2 ) ;
134132 } ) ;
135133
136- // Victory
137- if ( pieces . length > 0 && pieces . every ( p => p . currentRow === ( p . isArabic ? 0 : 1 ) && p . currentCol === p . correctCol ) ) {
138- if ( ! isComplete ) {
139- setIsComplete ( true ) ;
140- onComplete ?.( ) ;
141- victorySound . currentTime = 0 ;
142- victorySound . play ( ) ;
143- }
144- drawVictory ( ctx ) ;
134+ // Victory check
135+ const allCorrect = pieces . length > 0 && pieces . every ( p =>
136+ p . currentRow === ( p . isArabic ? 0 : 1 ) && p . currentCol === p . correctCol
137+ ) ;
138+
139+ if ( allCorrect && ! isComplete ) {
140+ setIsComplete ( true ) ;
141+ onComplete ?.( ) ;
142+ victorySound . currentTime = 0 ;
143+ victorySound . play ( ) ;
144+ drawVictory ( ctx , canvas ) ; // Pass canvas!
145145 }
146146 } ;
147147
148- const drawVictory = ( ctx : CanvasRenderingContext2D ) => {
148+ const drawVictory = ( ctx : CanvasRenderingContext2D , canvas : HTMLCanvasElement ) => {
149149 ctx . fillStyle = 'rgba(0, 128, 0, 0.9)' ;
150150 ctx . fillRect ( 0 , 0 , canvas . width , canvas . height ) ;
151151 ctx . fillStyle = '#FFF' ;
@@ -200,7 +200,6 @@ const AsmaUlHusnaPuzzle: React.FC<AsmaUlHusnaPuzzleProps> = ({ setIndex, onCompl
200200 const row = Math . round ( ( selectedPiece . y - startY ) / ( pieceHeight + gap ) ) ;
201201 const targetRow = selectedPiece . isArabic ? 0 : 1 ;
202202
203- // Only allow correct column
204203 if (
205204 row === targetRow &&
206205 col >= 0 && col < cols &&
0 commit comments