Skip to content

Commit

Permalink
fix: error at chapter has verse below 20
Browse files Browse the repository at this point in the history
  • Loading branch information
aacmal committed Jun 26, 2023
1 parent 3b3d0ad commit 1eeefc3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
29 changes: 13 additions & 16 deletions src/components/quranReader/DynamicSurahVerse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ const DynamicSurahVerse = ({ totalData, chapterId }: Props) => {
});
};

const initData = () => {
getVersesByChapter({
chapterId,
page: 2,
per_page: LIMIT,
}).then((res) => {
setPaginationData(res.pagination);
setData(res.verses);
});
};

useEffect(() => {
if (!highlightedVerse || !ref.current || !autoScroll) return;
const idAndVerse = highlightedVerse.split(':');
Expand All @@ -74,21 +85,6 @@ const DynamicSurahVerse = ({ totalData, chapterId }: Props) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [highlightedWord]);

useEffect(() => {
function getInitialData() {
getVersesByChapter({
chapterId,
page: 2,
per_page: LIMIT,
}).then((res) => {
setPaginationData(res.pagination);
setData(res.verses);
});
}

getInitialData();
}, []);

const renderRow = (index: number) => {
const dataIndex = data.findIndex(
(item) => item.verse_number - LIMIT - 1 === index
Expand All @@ -112,12 +108,13 @@ const DynamicSurahVerse = ({ totalData, chapterId }: Props) => {

return (
<Virtuoso
totalCount={totalData - LIMIT}
totalCount={totalData > 20 ? totalData - LIMIT : 0}
useWindowScroll
itemContent={renderRow}
rangeChanged={loadMoreData}
itemsRendered={(items) => setItemsRendered(items)}
ref={ref}
startReached={initData}
/>
);
};
Expand Down
7 changes: 5 additions & 2 deletions src/components/quranReader/QuranReader.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import Verses from './Verses';
import Bismillah from './Bismillah';
import { Verse } from '@utils/types/Verse';
import InitialSurahVerse from './InitialSurahVerse';
import DynamicSurahVerse from './DynamicSurahVerse';
import dynamic from 'next/dynamic';

const DynamicSurahVerse = dynamic(() => import('./DynamicSurahVerse'), {
ssr: false,
});

type QuranReaderProps = {
versesData: Verse[];
Expand Down

0 comments on commit 1eeefc3

Please sign in to comment.