-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#12 Can read Quran from option (Manzil, Rukuk, and Juz)
feat: start read Quran from option (Manzil, Rukuk, and Juz)
- Loading branch information
Showing
5 changed files
with
133 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { firestore } from "../../service/firebase"; | ||
|
||
const ayatFilter = { | ||
namespaced: true, | ||
state: () => { | ||
return { | ||
isLoading: false, | ||
ayats: [], | ||
surat: {}, | ||
last_ayat: {}, | ||
}; | ||
}, | ||
mutations: { | ||
SET_IS_LOADING: (state, loading) => (state.isLoading = loading), | ||
SET_AYAT: (state, data) => (state.ayats = data), | ||
SET_NEXT_AYAT: (state, data) => state.ayats.push(...data), | ||
SET_LAST_AYAT: (state, data) => (state.last_ayat = data), | ||
SET_SURAT: (state, data) => (state.surat = data), | ||
}, | ||
actions: { | ||
setAyatDetail({ commit, dispatch }, payload) { | ||
commit("SET_IS_LOADING", true); | ||
|
||
firestore | ||
.collection("ayah_collections") | ||
.where("sura_id", "==", parseInt(payload.surat)) | ||
.where("aya_number", "==", parseInt(payload.ayat)) | ||
.get() | ||
.then((aya) => { | ||
if (aya.docs.length > 0) { | ||
var initialAyat = aya.docs[0]; | ||
|
||
firestore | ||
.collection("ayah_collections") | ||
.orderBy("aya_id", "asc") | ||
.startAt(initialAyat) | ||
.limit(25) | ||
.get() | ||
.then((ayats) => { | ||
var lastVisible = ayats.docs[ayats.docs.length - 1]; | ||
dispatch("setLastAyat", lastVisible); | ||
|
||
let dataAyah = []; | ||
|
||
ayats.forEach((ayat) => { | ||
dataAyah.push(ayat.data()); | ||
}); | ||
|
||
commit("SET_AYAT", dataAyah); | ||
commit("SET_IS_LOADING", false); | ||
}); | ||
} | ||
}); | ||
}, | ||
|
||
setSuratDetail({ commit, dispatch }, payload) { | ||
commit("SET_IS_LOADING", true); | ||
|
||
firestore | ||
.collection("surah_collections") | ||
.doc(payload.surat.toString()) | ||
.get() | ||
.then((doc) => { | ||
if (doc.exists) { | ||
const surat_detail = doc.data(); | ||
|
||
commit("SET_SURAT", surat_detail); | ||
dispatch("setAyatDetail", payload); | ||
commit("SET_IS_LOADING", false); | ||
} | ||
}); | ||
}, | ||
nextAyat({ commit, dispatch, state }) { | ||
var next = firestore | ||
.collection("ayah_collections") | ||
.orderBy("aya_id", "asc") | ||
.startAfter(state.last_ayat) | ||
.limit(25); | ||
|
||
next.get().then((doc) => { | ||
var lastVisible = doc.docs[doc.docs.length - 1]; | ||
dispatch("setLastAyat", lastVisible); | ||
|
||
let tempData = []; | ||
|
||
doc.forEach((ayat) => { | ||
tempData.push(ayat.data()); | ||
}); | ||
|
||
commit("SET_NEXT_AYAT", tempData); | ||
}); | ||
}, | ||
setLastAyat({ commit }, payload) { | ||
commit("SET_LAST_AYAT", payload); | ||
}, | ||
}, | ||
}; | ||
|
||
export default ayatFilter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters