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:
BIN
frontend/logos/csb-logo.png
Normal file
BIN
frontend/logos/csb-logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
BIN
frontend/logos/niv-logo.png
Normal file
BIN
frontend/logos/niv-logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.0 KiB |
BIN
frontend/logos/nlt-logo.png
Normal file
BIN
frontend/logos/nlt-logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.5 KiB |
@@ -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);
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@ export const getBooks = async (): Promise<BookData> => {
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const getBook = async (book: string): Promise<{ chapters: string[] }> => {
|
||||
const response = await api.get(`/books/${book}`);
|
||||
export const getBook = async (book: string, version: string = 'esv'): Promise<{ chapters: string[] }> => {
|
||||
const response = await api.get(`/books/${book}?version=${version}`);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const getChapter = async (book: string, chapter: string): Promise<string> => {
|
||||
const response = await api.get(`/books/${book}/${chapter}`);
|
||||
export const getChapter = async (book: string, chapter: string, version: string = 'esv'): Promise<string> => {
|
||||
const response = await api.get(`/books/${book}/${chapter}?version=${version}`);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user