-
-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2154 from quran/QF-352
QF-352: Update translation view initial data with the api data
- Loading branch information
Showing
2 changed files
with
60 additions
and
4 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/components/QuranReader/TranslationView/hooks/useGetVersesCount.ts
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,47 @@ | ||
import { useContext, useMemo } from 'react'; | ||
|
||
import { useSelector } from 'react-redux'; | ||
|
||
import useFetchPagesLookup from '@/components/QuranReader/hooks/useFetchPagesLookup'; | ||
import DataContext from '@/contexts/DataContext'; | ||
import { selectIsUsingDefaultFont } from '@/redux/slices/QuranReader/styles'; | ||
import { generateVerseKeysBetweenTwoVerseKeys } from '@/utils/verseKeys'; | ||
|
||
/** | ||
* This hooks calculates the total number of verses based on the verses range | ||
* and the current Mushaf settings | ||
* | ||
* @param {number|string} resourceId | ||
* @param {QuranReaderDataType} quranReaderDataType | ||
* @param {VersesResponse} initialData | ||
* @param {QuranReaderStyles} quranReaderStyles | ||
* | ||
* @returns {number} versesCount | ||
*/ | ||
|
||
const useGetVersesCount = ({ | ||
resourceId, | ||
quranReaderDataType, | ||
initialData, | ||
quranReaderStyles, | ||
}): number => { | ||
const isUsingDefaultFont = useSelector(selectIsUsingDefaultFont); | ||
const { lookupRange } = useFetchPagesLookup( | ||
resourceId, | ||
quranReaderDataType, | ||
initialData, | ||
quranReaderStyles, | ||
isUsingDefaultFont, | ||
); | ||
|
||
const chaptersData = useContext(DataContext); | ||
|
||
const versesCount = useMemo(() => { | ||
return generateVerseKeysBetweenTwoVerseKeys(chaptersData, lookupRange.from, lookupRange.to) | ||
.length; | ||
}, [chaptersData, lookupRange.from, lookupRange.to]); | ||
|
||
return versesCount; | ||
}; | ||
|
||
export default useGetVersesCount; |
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