Skip to content

Commit 5e1edb6

Browse files
committed
prepping for first release
1 parent 5235e8e commit 5e1edb6

File tree

4 files changed

+58
-37
lines changed

4 files changed

+58
-37
lines changed

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM node:alpine
2+
WORKDIR /app
3+
COPY package.json ./
4+
COPY package-lock.json ./
5+
COPY ./ ./
6+
RUN npm i
7+
CMD ["npm", "run", "start"]

src/pages/Hadith.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import { useState, useEffect } from 'react';
22
import { getTheKeetab, giveTheKeetab } from './getTimes';
33

44
function Hadith() {
5+
6+
useEffect(() => {
7+
async function Awwalun() {
8+
setKeetab(await getTheKeetab());
9+
}
10+
Awwalun();
11+
}, []);
512

613
const [intro, setIntro] = useState(true);
714
const [hadith, setHadith] = useState([]);
@@ -29,15 +36,7 @@ function Hadith() {
2936
}
3037

3138
async function handleClick(event) {
32-
if (keetab.length > 5) {
33-
setSearch(event.target.value);
34-
return;
35-
} else if (keetab.length === 0) {
36-
await getTheKeetab().then(data => {
37-
setKeetab(data);
38-
setSearch(event.target.value);
39-
});
40-
}
39+
setSearch(event.target.value);
4140
}
4241

4342
function HadithPage() {

src/pages/Quran.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@ import { useState, useEffect } from 'react';
22
import { getTheQuran, giveTheQuran, giveQuranAudio } from './getTimes';
33

44
function Quran() {
5-
5+
6+
useEffect(() => {
7+
async function Awwalun() {
8+
setSurah(await getTheQuran());
9+
}
10+
Awwalun();
11+
}, []);
12+
613
const [intro, setIntro] = useState(true);
714
const [surah, setSurah] = useState([]);
815
const [search, setSearch] = useState("");
916
const [quran, setQuran] = useState([]);
1017
const [display, setDisplay] = useState(false);
1118
const [audio, setAudio] = useState([]);
19+
const [clicked, setClicked] = useState(0);
1220

1321
useEffect(() => { document.title = "Al-Quran" }, []);
1422

@@ -22,24 +30,23 @@ function Quran() {
2230

2331
async function handleSubmit(event) {
2432
event.preventDefault();
25-
await giveQuranAudio(search).then(data => { setAudio(data) });
33+
await giveQuranAudio(search).then(data => { setAudio(data); console.log(data); });
2634
await giveTheQuran(search).then(data => {
2735
setDisplay(true);
2836
setIntro(false);
2937
setQuran(data);
38+
console.log(audio);
3039
});
3140
}
3241

3342
async function handleClick(event) {
34-
if (surah.length > 113) {
35-
setSearch(event.target.value);
43+
setClicked(clicked + 1);
44+
if (clicked === 0) {
3645
return;
37-
} else if (surah.length === 0) {
38-
await getTheQuran().then(data => {
39-
setSurah(data);
40-
setSearch(event.target.value);
41-
});
46+
} else if (clicked === 2) {
47+
window.location.reload();
4248
}
49+
setSearch(event.target.value);
4350
}
4451

4552
function Surah() {

src/pages/getTimes.js

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -116,29 +116,37 @@ export async function giveTheQuran(surah) {
116116
}
117117

118118
export async function giveQuranAudio(surah) {
119-
try {
120-
surah++;
121-
const audio = await fetch(`https://api.quran.sutanlab.id/surah/${surah}`, {
122-
crossDomain:true,
123-
method: 'GET',
124-
});
125-
myCache.set('quranAudio', audio.json(), ttl);
126-
} catch (error) {
127-
console.log(error);
128-
}
129-
const audio = await myCache.get('quranAudio');
119+
surah++;
120+
if (myCache.has(`quranAudio-${surah}`)) {
121+
console.log("audio is in cache");
122+
} else {
123+
try{
124+
const audio = await fetch(`https://api.quran.sutanlab.id/surah/${surah}`, {
125+
crossDomain:true,
126+
method: 'GET',
127+
});
128+
myCache.set(`quranAudio-${surah}`, audio.json(), ttl);
129+
} catch (error) {
130+
console.log(error);
131+
}
132+
}
133+
const audio = await myCache.get(`quranAudio-${surah}`);
130134
return audio.data.verses;
131135
}
132136

133137
export async function getTheKeetab() {
134-
try {
135-
const keetab = await fetch('https://api.hadith.sutanlab.id/books', {
136-
crossDomain:true,
137-
method: 'GET',
138-
});
139-
myCache.set('keetab', keetab.json(), ttl);
140-
} catch (error) {
141-
console.log(error);
138+
if (myCache.has('keetab')) {
139+
console.log("keetab is in cache");
140+
} else {
141+
try {
142+
const keetab = await fetch('https://api.hadith.sutanlab.id/books', {
143+
crossDomain:true,
144+
method: 'GET',
145+
});
146+
myCache.set('keetab', keetab.json(), ttl);
147+
} catch (error) {
148+
console.log(error);
149+
}
142150
}
143151
const keetab = await myCache.get('keetab');
144152
return keetab.data;

0 commit comments

Comments
 (0)