1- import { useState } from 'react' ;
2- import { getTheQuran , giveTheQuran } from './getTimes' ;
1+ import { useState , useEffect } from 'react' ;
2+ import { getTheQuran , giveTheQuran , giveQuranAudio } from './getTimes' ;
33
44function Quran ( ) {
55
@@ -8,17 +8,21 @@ function Quran() {
88 const [ search , setSearch ] = useState ( "" ) ;
99 const [ quran , setQuran ] = useState ( [ ] ) ;
1010 const [ display , setDisplay ] = useState ( false ) ;
11+ const [ audio , setAudio ] = useState ( [ ] ) ;
1112
12- const TheIntro = ( ) => {
13+ useEffect ( ( ) => { document . title = "Al-Quran" } , [ ] ) ;
14+
15+ function TheIntro ( ) {
1316 if ( intro === true ) {
1417 return (
15- < p1 > Assalamualaikum</ p1 >
18+ < p > Assalamualaikum</ p >
1619 ) ;
1720 }
1821 }
1922
2023 async function handleSubmit ( event ) {
2124 event . preventDefault ( ) ;
25+ await giveQuranAudio ( search ) . then ( data => { setAudio ( data ) } ) ;
2226 await giveTheQuran ( search ) . then ( data => {
2327 setDisplay ( true ) ;
2428 setIntro ( false ) ;
@@ -31,9 +35,9 @@ function Quran() {
3135 setSearch ( event . target . value ) ;
3236 return ;
3337 } else if ( surah . length === 0 ) {
34- setSearch ( event . target . value ) ;
3538 await getTheQuran ( ) . then ( data => {
3639 setSurah ( data ) ;
40+ setSearch ( event . target . value ) ;
3741 } ) ;
3842 }
3943 }
@@ -43,9 +47,10 @@ function Quran() {
4347 return (
4448 < >
4549 { quran . map ( ( ayats , index ) => (
46- < div class = 'quranAyats' key = { index } >
47- < h3 class = 'arabic '> { ayats . text } </ h3 >
50+ < div className = 'quranAyats' key = { index } >
51+ < h3 className = 'quranic '> { ayats . text } ( { index + 1 } ) </ h3 >
4852 < p > { ayats . translation } </ p >
53+ < audio key = { index } controls > < source src = { audio [ index ] . audio . primary } /> </ audio >
4954 < br />
5055 </ div >
5156 ) ) }
@@ -56,13 +61,13 @@ function Quran() {
5661
5762 return (
5863 < main className = "container" >
59- < div class = "grid" >
64+ < div className = "grid" >
6065 < div >
6166 < form onSubmit = { handleSubmit } >
6267 < select onClick = { handleClick } id = "surah" required = "" name = "surah" >
6368 < option value = "" > Sila pilih surah...</ option >
6469 { surah . map ( ( thesurah , index ) => (
65- < option key = { index } value = { index } > { thesurah } </ option >
70+ < option key = { index } value = { index } > { thesurah . transliteration } </ option >
6671 ) ) }
6772 </ select >
6873 < button type = "submit" value = "Submit" > Pilih</ button >
@@ -74,7 +79,7 @@ function Quran() {
7479 < h1 > Al Quran</ h1 >
7580 </ div >
7681 </ div >
77- { Surah ( quran ) }
82+ < div > { Surah ( quran ) } </ div >
7883 { TheIntro ( ) }
7984 </ main >
8085 ) ;
0 commit comments