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,SACb8B,EAAkB3D,KAAI,SAACkD,GACtB,OAAO,SAACgB,EAAa,CAAChB,SAAUA,GAAeA,cC5E3D,EATiC,WAC/B,OACE,UAACvB,MAAG,CAACC,UAAWC,IAAAA,mB,WACd,SAACsC,EAAS,KACV,SAACC,EAAS,S,gICAHC,G,SAAc,SAACC,G,OAA+C,IAAfA,IAQ/CC,EAAa,SAACD,G,OAA+C,KAAfA,GAmB9C1F,EAAuB,W,OAAA,iBAAOtB,G,0CACzC,MAAO,C,EAAA,IAAIkH,SAAQ,SAACC,GAClB,sCAA+CC,MAAK,SAACC,GACnDF,EAAIE,EAAKC,QAAQtH,iB,gBAHoBA,G,gCAAP,I,gIC1BvBuH,G,SAAa,SAACC,G,OAA6C,IAAdA,IAQ7CC,EAAY,SAACD,G,OAfM,MAeyBA,GAY5CjG,EAAsB,W,OAAA,iBAAOtB,G,0CACxC,MAAO,C,EAAA,IAAIiH,SAAQ,SAACC,GAClB,oCAAsDC,MAAK,SAACC,GAC1DF,EAAIE,EAAKC,QAAQrH,iB,gBAHmBA,G,gCAAP","sources":["webpack://_N_E/./src/hooks/useChapterId.ts","webpack://_N_E/./src/components/QuranReader/SidebarNavigation/SurahList.tsx","webpack://_N_E/./src/components/QuranReader/SidebarNavigation/VerseListItem.tsx","webpack://_N_E/./src/components/QuranReader/SidebarNavigation/VerseList.tsx","webpack://_N_E/./src/components/QuranReader/SidebarNavigation/SurahSelection.tsx","webpack://_N_E/./src/utils/hizb.ts","webpack://_N_E/./src/utils/rub.ts"],"sourcesContent":["import { useState, useEffect, useContext } from 'react';\n\nimport { useRouter } from 'next/router';\n\nimport { getChapterIdsForJuz, getChapterIdsForPage } from '@/utils/chapter';\nimport { getChapterIdsForHizb } from '@/utils/hizb';\nimport { formatStringNumber } from '@/utils/number';\nimport { getChapterIdsForRub } from '@/utils/rub';\nimport { isValidChapterId, isValidVerseKey } from '@/utils/validator';\nimport { getChapterNumberFromKey } from '@/utils/verse';\nimport { getChapterIdBySlug } from 'src/api';\nimport DataContext from 'src/contexts/DataContext';\n\n/**\n * Given a url path such as `/chapter/1`, return the chapters id\n * This will also handle case where chapterId is not specified in the url path\n * For example: `/juz/1`, `/pages/323`. We will get the data for those url path from json files\n *\n * @returns {string[]} chapterIds\n *\n * example:\n * - /juz/1 => [\"1\", \"2\"]\n * - /page/2 => [\"2\"]\n * - /chapter/1 => [\"1\"]\n */\nconst AYAH_KURSI_SLUGS = ['ayatul-kursi', 'آیت الکرسی']; // TODO: this needs to be refactored when we localize Ayatul Kursi\nconst useChapterIdsByUrlPath = (lang: string): string[] => {\n const router = useRouter();\n const { chapterId, juzId, pageId, hizbId, rubId } = router.query;\n const [chapterIds, setChapterIds] = useState([]);\n const chaptersData = useContext(DataContext);\n useEffect(() => {\n (async () => {\n if (chapterId) {\n const chapterIdOrVerseKeyOrSlug = chapterId as string;\n // if it's a chapter id\n if (isValidChapterId(chapterIdOrVerseKeyOrSlug)) {\n setChapterIds([formatStringNumber(chapterIdOrVerseKeyOrSlug)]);\n } else if (isValidVerseKey(chaptersData, chapterIdOrVerseKeyOrSlug)) {\n // if it's a verse key e.g 5:1\n setChapterIds([getChapterNumberFromKey(chapterIdOrVerseKeyOrSlug).toString()]);\n } else if (AYAH_KURSI_SLUGS.includes(chapterIdOrVerseKeyOrSlug.toLowerCase())) {\n // if it's Ayatul Kursi\n setChapterIds(['2']);\n } else {\n // we need to convert the slug into a chapterId by calling BE\n const sluggedChapterId = await getChapterIdBySlug(chapterIdOrVerseKeyOrSlug, lang);\n // if it's a valid slug and the call doesn't have any errors\n if (sluggedChapterId) {\n setChapterIds([sluggedChapterId.toString()]);\n }\n }\n } else if (pageId) {\n const chapterIdsForPage = await getChapterIdsForPage(formatStringNumber(pageId as string));\n setChapterIds(chapterIdsForPage);\n } else if (juzId) {\n setChapterIds(await getChapterIdsForJuz(formatStringNumber(juzId as string)));\n } else if (hizbId) {\n setChapterIds(await getChapterIdsForHizb(formatStringNumber(hizbId as string)));\n } else if (rubId) {\n setChapterIds(await getChapterIdsForRub(formatStringNumber(rubId as string)));\n }\n })();\n }, [pageId, juzId, hizbId, rubId, lang, chapterId, chaptersData]);\n\n return chapterIds;\n};\n\nexport default useChapterIdsByUrlPath;\n","import { useContext, useEffect, useMemo, useState } from 'react';\n\nimport classNames from 'classnames';\nimport Fuse from 'fuse.js';\nimport { useRouter } from 'next/router';\nimport useTranslation from 'next-translate/useTranslation';\nimport { useSelector } from 'react-redux';\n\nimport styles from './SidebarNavigation.module.scss';\n\nimport Link from '@/dls/Link/Link';\nimport useChapterIdsByUrlPath from '@/hooks/useChapterId';\nimport { SCROLL_TO_NEAREST_ELEMENT, useScrollToElement } from '@/hooks/useScrollToElement';\nimport { selectLastReadVerseKey } from '@/redux/slices/QuranReader/readingTracker';\nimport { selectIsReadingByRevelationOrder } from '@/redux/slices/revelationOrder';\nimport SearchQuerySource from '@/types/SearchQuerySource';\nimport { logEmptySearchResults, logTextSearchQuery } from '@/utils/eventLogger';\nimport { toLocalizedNumber } from '@/utils/locale';\nimport { getSurahNavigationUrl } from '@/utils/navigation';\nimport REVELATION_ORDER from '@/utils/revelationOrder';\nimport DataContext from 'src/contexts/DataContext';\nimport Chapter from 'types/Chapter';\n\nconst filterSurah = (surahs: Chapter[], searchQuery: string) => {\n const fuse = new Fuse(surahs, {\n threshold: 0.3,\n keys: ['id', 'localizedId', 'transliteratedName'],\n });\n\n const filteredSurah = fuse.search(searchQuery).map(({ item }) => item);\n if (!filteredSurah.length) {\n logEmptySearchResults({\n query: searchQuery,\n source: SearchQuerySource.SidebarNavigationChaptersList,\n });\n } else {\n logTextSearchQuery(searchQuery, SearchQuerySource.SidebarNavigationChaptersList);\n }\n\n return filteredSurah as Chapter[];\n};\n\nconst SurahList = () => {\n const { t, lang } = useTranslation('common');\n const lastReadVerseKey = useSelector(selectLastReadVerseKey);\n const isReadingByRevelationOrder = useSelector(selectIsReadingByRevelationOrder);\n const router = useRouter();\n const chaptersData = useContext(DataContext);\n\n const chapterIds = useChapterIdsByUrlPath(lang);\n const urlChapterId = chapterIds && chapterIds.length > 0 ? chapterIds[0] : null;\n\n const [currentChapterId, setCurrentChapterId] = useState(urlChapterId);\n\n useEffect(() => {\n setCurrentChapterId(lastReadVerseKey.chapterId);\n }, [lastReadVerseKey]);\n\n useEffect(() => {\n // when the user navigates to a new chapter, the current chapter id\n setCurrentChapterId(urlChapterId);\n }, [urlChapterId]);\n\n const [searchQuery, setSearchQuery] = useState('');\n\n const chapterDataArray = useMemo(() => {\n if (!isReadingByRevelationOrder) {\n return Object.entries(chaptersData).map(([id, chapter]) => {\n return {\n ...chapter,\n id,\n localizedId: toLocalizedNumber(Number(id), lang),\n };\n });\n }\n\n // Sort the chapters by revelation order\n return Object.entries(chaptersData)\n .map(([id, chapter]) => {\n return {\n ...chapter,\n id,\n localizedId: toLocalizedNumber(Number(REVELATION_ORDER.indexOf(Number(id)) + 1), lang),\n };\n })\n .sort(\n (a, b) => REVELATION_ORDER.indexOf(Number(a.id)) - REVELATION_ORDER.indexOf(Number(b.id)),\n );\n }, [isReadingByRevelationOrder, chaptersData, lang]);\n\n const filteredChapters = searchQuery\n ? filterSurah(chapterDataArray, searchQuery)\n : chapterDataArray;\n\n const [scrollTo, selectedChapterRef] =\n useScrollToElement<HTMLDivElement>(SCROLL_TO_NEAREST_ELEMENT);\n\n useEffect(() => {\n scrollTo();\n }, [currentChapterId, scrollTo]);\n\n // Handle when user press `Enter` in input box\n const handleSurahInputSubmit = (e) => {\n e.preventDefault();\n const firstFilteredChapter = filteredChapters[0];\n if (firstFilteredChapter) {\n router.push(getSurahNavigationUrl(firstFilteredChapter.id));\n }\n };\n\n return (\n <div className={styles.surahListContainer}>\n <form onSubmit={handleSurahInputSubmit}>\n <input\n className={styles.searchInput}\n value={searchQuery}\n onChange={(e) => setSearchQuery(e.target.value)}\n placeholder={t('sidebar.search-surah')}\n />\n </form>\n <div className={styles.listContainer}>\n <div className={styles.list}>\n {filteredChapters.map((chapter) => (\n <Link key={chapter.id} href={getSurahNavigationUrl(chapter.id)} shouldPrefetch={false}>\n <div\n ref={chapter.id.toString() === currentChapterId ? selectedChapterRef : null}\n className={classNames(styles.listItem, {\n [styles.selectedItem]: chapter.id.toString() === currentChapterId,\n })}\n >\n <span className={styles.chapterNumber}>{chapter.localizedId}</span>\n <span>{chapter.transliteratedName}</span>\n </div>\n </Link>\n ))}\n </div>\n </div>\n </div>\n );\n};\n\nexport default SurahList;\n","import React, { useEffect } from 'react';\n\nimport classNames from 'classnames';\nimport useTranslation from 'next-translate/useTranslation';\nimport { useSelector } from 'react-redux';\n\nimport styles from './SidebarNavigation.module.scss';\n\nimport Link from '@/dls/Link/Link';\nimport { SCROLL_TO_NEAREST_ELEMENT, useScrollToElement } from '@/hooks/useScrollToElement';\nimport { selectIsVerseKeySelected } from '@/redux/slices/QuranReader/readingTracker';\nimport { toLocalizedNumber } from '@/utils/locale';\nimport { getChapterWithStartingVerseUrl } from '@/utils/navigation';\nimport { getVerseNumberFromKey } from '@/utils/verse';\n\ntype VerseListItemProps = {\n verseKey: string;\n};\nconst VerseListItem = React.memo(({ verseKey }: VerseListItemProps) => {\n const { lang } = useTranslation();\n const isVerseKeySelected = useSelector(selectIsVerseKeySelected(verseKey));\n\n const verseNumber = getVerseNumberFromKey(verseKey);\n const localizedVerseNumber = toLocalizedNumber(verseNumber, lang);\n\n const [scrollTo, verseRef] = useScrollToElement<HTMLDivElement>(SCROLL_TO_NEAREST_ELEMENT);\n\n useEffect(() => {\n if (isVerseKeySelected) scrollTo();\n }, [scrollTo, isVerseKeySelected]);\n\n return (\n <Link\n href={getChapterWithStartingVerseUrl(verseKey)}\n key={verseKey}\n isShallow\n shouldPrefetch={false}\n >\n <div\n ref={verseRef}\n className={classNames(styles.listItem, {\n [styles.selectedItem]: isVerseKeySelected,\n })}\n >\n {localizedVerseNumber}\n </div>\n </Link>\n );\n});\n\nexport default VerseListItem;\n","import { useState, useMemo, useEffect, useContext } from 'react';\n\nimport { useRouter } from 'next/router';\nimport useTranslation from 'next-translate/useTranslation';\nimport { useSelector } from 'react-redux';\n\nimport styles from './SidebarNavigation.module.scss';\nimport VerseListItem from './VerseListItem';\n\nimport useChapterIdsByUrlPath from '@/hooks/useChapterId';\nimport { selectLastReadVerseKey } from '@/redux/slices/QuranReader/readingTracker';\nimport SearchQuerySource from '@/types/SearchQuerySource';\nimport { logEmptySearchResults, logTextSearchQuery } from '@/utils/eventLogger';\nimport { toLocalizedNumber } from '@/utils/locale';\nimport { getChapterWithStartingVerseUrl } from '@/utils/navigation';\nimport { generateChapterVersesKeys, getVerseNumberFromKey } from '@/utils/verse';\nimport DataContext from 'src/contexts/DataContext';\n\nconst VerseList = () => {\n const [searchQuery, setSearchQuery] = useState('');\n const { t, lang } = useTranslation('common');\n const lastReadVerseKey = useSelector(selectLastReadVerseKey);\n const router = useRouter();\n const chaptersData = useContext(DataContext);\n\n const chapterIds = useChapterIdsByUrlPath(lang);\n const urlChapterId = chapterIds && chapterIds.length > 0 ? chapterIds[0] : null;\n\n const [currentChapterId, setCurrentChapterId] = useState(urlChapterId);\n\n useEffect(() => {\n setCurrentChapterId(lastReadVerseKey.chapterId);\n }, [lastReadVerseKey]);\n\n useEffect(() => {\n // when the user navigates to a new chapter, reset the search query, and update the current chapter id\n setSearchQuery('');\n setCurrentChapterId(urlChapterId);\n }, [urlChapterId]);\n\n const verseKeys = useMemo(\n () => (currentChapterId ? generateChapterVersesKeys(chaptersData, currentChapterId) : []),\n [chaptersData, currentChapterId],\n );\n\n const filteredVerseKeys = verseKeys.filter((verseKey) => {\n const verseNumber = getVerseNumberFromKey(verseKey);\n const localizedVerseNumber = toLocalizedNumber(verseNumber, lang);\n return (\n localizedVerseNumber.toString().startsWith(searchQuery) ||\n verseNumber.toString().startsWith(searchQuery)\n );\n });\n\n useEffect(() => {\n if (!filteredVerseKeys.length) {\n logEmptySearchResults({\n query: searchQuery,\n source: SearchQuerySource.SidebarNavigationVersesList,\n });\n } else {\n logTextSearchQuery(searchQuery, SearchQuerySource.SidebarNavigationVersesList);\n }\n }, [searchQuery, filteredVerseKeys]);\n\n // Handle when user press `Enter` in input box\n const handleVerseInputSubmit = (e) => {\n e.preventDefault();\n const firstFilteredVerseKey = filteredVerseKeys[0];\n if (firstFilteredVerseKey) {\n router.push(getChapterWithStartingVerseUrl(firstFilteredVerseKey), undefined, {\n shallow: true, // https://nextjs.org/docs/routing/shallow-routing\n });\n }\n };\n\n return (\n <div className={styles.verseListContainer}>\n <form onSubmit={handleVerseInputSubmit}>\n <input\n value={searchQuery}\n onChange={(e) => setSearchQuery(e.target.value)}\n className={styles.searchInput}\n placeholder={t('verse')}\n />\n </form>\n <div className={styles.listContainer}>\n <div className={styles.list}>\n {filteredVerseKeys.map((verseKey) => {\n return <VerseListItem verseKey={verseKey} key={verseKey} />;\n })}\n </div>\n </div>\n </div>\n );\n};\n\nexport default VerseList;\n","import styles from './SidebarNavigation.module.scss';\nimport SurahList from './SurahList';\nimport VerseList from './VerseList';\n\nconst SurahSelection: React.FC = () => {\n return (\n <div className={styles.surahBodyContainer}>\n <SurahList />\n <VerseList />\n </div>\n );\n};\n\nexport default SurahSelection;\n","import { toLocalizedNumber } from './locale';\n\n/**\n * Whether the current hizb is the first surah.\n *\n * @param {number} hizbNumber\n * @returns {boolean}\n */\nexport const isFirstHizb = (hizbNumber: number): boolean => hizbNumber === 1;\n\n/**\n * Whether the current hizb is the last surah.\n *\n * @param {number} hizbNumber\n * @returns {boolean}\n */\nexport const isLastHizb = (hizbNumber: number): boolean => hizbNumber === 60;\n\nconst TOTAL_QURAN_HIZB = 60;\nexport const getHizbIds = (lang: string) => {\n return [...Array(TOTAL_QURAN_HIZB)].map((n, index) => {\n const hizb = index + 1;\n return {\n value: hizb,\n label: toLocalizedNumber(hizb, lang),\n };\n });\n};\n\n/**\n * Given a hizbId, get chapters ids from a json file\n *\n * @param {string} hizbId\n * @returns {string[]} chapterIds\n */\nexport const getChapterIdsForHizb = async (hizbId: string): Promise<string[]> => {\n return new Promise((res) => {\n import(`@/data/hizb-to-chapter-mappings.json`).then((data) => {\n res(data.default[hizbId]);\n });\n });\n};\n","import { toLocalizedNumber } from './locale';\n\nconst TOTAL_QURAN_RUB_EL_HIZB = 240;\n/**\n * Whether the current Rub is the first Rub El Hizb.\n *\n * @param {number} rubNumber\n * @returns {boolean}\n */\nexport const isFirstRub = (rubNumber: number): boolean => rubNumber === 1;\n\n/**\n * Whether the current Rub is the last Rub El Hizb.\n *\n * @param {number} rubNumber\n * @returns {boolean}\n */\nexport const isLastRub = (rubNumber: number): boolean => rubNumber === TOTAL_QURAN_RUB_EL_HIZB;\n\nexport const getRubIds = (lang: string) => {\n return [...Array(TOTAL_QURAN_RUB_EL_HIZB)].map((n, index) => {\n const rub = index + 1;\n return {\n value: rub,\n label: toLocalizedNumber(rub, lang),\n };\n });\n};\n\nexport const getChapterIdsForRub = async (rubId: string): Promise<string[]> => {\n return new Promise((res) => {\n import(`@/data/rub-el-hizb-to-chapter-mappings.json`).then((data) => {\n res(data.default[rubId]);\n });\n });\n};\n"],"names":["AYAH_KURSI_SLUGS","lang","router","useRouter","query","chapterId","juzId","pageId","hizbId","rubId","useState","chapterIds","setChapterIds","chaptersData","useContext","DataContext","useEffect","chapterIdOrVerseKeyOrSlug","sluggedChapterId","chapterIdsForPage","isValidChapterId","formatStringNumber","isValidVerseKey","getChapterNumberFromKey","toString","includes","toLowerCase","getChapterIdBySlug","getChapterIdsForPage","getChapterIdsForJuz","getChapterIdsForHizb","getChapterIdsForRub","useTranslation","t","lastReadVerseKey","useSelector","selectLastReadVerseKey","isReadingByRevelationOrder","selectIsReadingByRevelationOrder","useChapterIdsByUrlPath","urlChapterId","length","currentChapterId","setCurrentChapterId","searchQuery","setSearchQuery","chapterDataArray","useMemo","Object","entries","map","id","chapter","localizedId","toLocalizedNumber","Number","REVELATION_ORDER","sort","a","b","filteredChapters","surahs","filteredSurah","Fuse","threshold","keys","search","item","logTextSearchQuery","SearchQuerySource","logEmptySearchResults","source","filterSurah","useScrollToElement","SCROLL_TO_NEAREST_ELEMENT","scrollTo","selectedChapterRef","div","className","styles","form","onSubmit","e","preventDefault","firstFilteredChapter","push","getSurahNavigationUrl","input","value","onChange","target","placeholder","Link","href","shouldPrefetch","ref","classNames","span","transliteratedName","React","verseKey","isVerseKeySelected","selectIsVerseKeySelected","verseNumber","getVerseNumberFromKey","localizedVerseNumber","verseRef","getChapterWithStartingVerseUrl","isShallow","filteredVerseKeys","generateChapterVersesKeys","filter","startsWith","firstFilteredVerseKey","undefined","shallow","VerseListItem","SurahList","VerseList","isFirstHizb","hizbNumber","isLastHizb","Promise","res","then","data","default","isFirstRub","rubNumber","isLastRub"],"sourceRoot":""}
|