Fixed chapter counting and numbering issues
- Updated API functions to accept version parameter (getBook, getChapter) - Added proper chapter sorting with parseInt for numerical order - Removed fallback to 50 fake chapters - now shows actual chapter counts - Fixed Psalms chapter numbering: 1,2,3,4,5,6,7,8,9,10,11,12... instead of 1,2,3,4,5,6,7,8,9,10,101,102... - Books like 2 John now show correct number of chapters (1) instead of fake 50
This commit is contained in:
@@ -114,21 +114,21 @@ const ChapterSelector: React.FC<ChapterSelectorProps> = ({ book, onChapterSelect
|
||||
const loadChapters = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const response = await getBook(book);
|
||||
|
||||
const response = await getBook(book, version);
|
||||
|
||||
// The API now returns { chapters: ["1", "2", "3", ...] }
|
||||
if (response.chapters) {
|
||||
setChapters(response.chapters);
|
||||
// Sort chapters numerically to ensure proper order
|
||||
const sortedChapters = response.chapters.sort((a, b) => parseInt(a, 10) - parseInt(b, 10));
|
||||
setChapters(sortedChapters);
|
||||
} else {
|
||||
// Fallback: generate chapter numbers 1-50 (most books have fewer than 50 chapters)
|
||||
const fallbackChapters = Array.from({ length: 50 }, (_, i) => (i + 1).toString());
|
||||
setChapters(fallbackChapters);
|
||||
console.error('API returned no chapters data');
|
||||
setChapters([]);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load chapters:', error);
|
||||
// Fallback: generate chapter numbers 1-50 (most books have fewer than 50 chapters)
|
||||
const fallbackChapters = Array.from({ length: 50 }, (_, i) => (i + 1).toString());
|
||||
setChapters(fallbackChapters);
|
||||
// Don't show fallback chapters - just show an empty list
|
||||
setChapters([]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user