11import React , { useState } from 'react' ;
22import BookList from '../BookList' ;
33import PropTypes from 'prop-types' ;
4- import { BIBLE_LIST , BIBLE_BOOKS } from './config' ;
4+ import {
5+ OLD_TESTAMENT_LIST ,
6+ NEW_TESTAMENT_LIST ,
7+ OBS_LIST ,
8+ OLD_TESTAMENT ,
9+ NEW_TESTAMENT ,
10+ OBS ,
11+ } from './config' ;
512import Checkbox from '@material-ui/core/Checkbox' ;
613import { FormControlLabel } from '@material-ui/core' ;
714
@@ -13,25 +20,39 @@ function BibleBookList({
1320 selectedBookId,
1421 titleOT,
1522 titleNT,
23+ titleOBS,
1624 availableBookList,
1725 titleBooks,
1826 BibleBookListClasses,
1927 bookClasses,
2028 testaments,
2129 sortFirstNT,
30+ showOBS,
2231} ) {
2332 const [ checkState , setCheckState ] = useState ( ! showInactive ) ;
24- const currentBookList = BIBLE_LIST . map ( ( el ) => {
33+ let bibleList ;
34+ if ( showOBS ) {
35+ bibleList = OLD_TESTAMENT_LIST . concat ( NEW_TESTAMENT_LIST ) . concat ( OBS_LIST ) ;
36+ } else {
37+ bibleList = OLD_TESTAMENT_LIST . concat ( NEW_TESTAMENT_LIST ) ;
38+ }
39+ let bibleBooks ;
40+ if ( showOBS ) {
41+ bibleBooks = { ...OLD_TESTAMENT , ...NEW_TESTAMENT , ...OBS } ;
42+ } else {
43+ bibleBooks = { ...OLD_TESTAMENT , ...NEW_TESTAMENT } ;
44+ }
45+ const currentBookList = bibleList . map ( ( el ) => {
2546 return {
2647 ...el ,
27- text : titleBooks [ el . identifier ] ?? BIBLE_BOOKS [ el . identifier ] ,
48+ text : titleBooks [ el . identifier ] ?? bibleBooks [ el . identifier ] ,
2849 isset : availableBookList . includes ( el . identifier ) ,
2950 } ;
3051 } ) ;
3152
3253 const currentBookListOT = currentBookList . filter ( ( el ) => el . categories === 'bible-ot' ) ;
33-
3454 const currentBookListNT = currentBookList . filter ( ( el ) => el . categories === 'bible-nt' ) ;
55+ const currentBookListOBS = currentBookList . filter ( ( el ) => el . categories === 'obs' ) ;
3556 const handleChange = ( ) => {
3657 setCheckState ( ( prev ) => ! prev ) ;
3758 } ;
@@ -85,6 +106,16 @@ function BibleBookList({
85106 break ;
86107 }
87108
109+ if ( showOBS ) {
110+ testamentList = testamentList . concat ( {
111+ title : titleOBS ,
112+ bookList : currentBookListOBS ,
113+ } ) ;
114+ if ( showCheckbox ) {
115+ showCheckbox = allBooksIsSet ( currentBookListOBS ) ;
116+ }
117+ }
118+
88119 const checkboxRender = showCheckbox ? (
89120 < FormControlLabel
90121 classes = { {
@@ -96,11 +127,7 @@ function BibleBookList({
96127 ) : (
97128 ''
98129 ) ;
99-
100- return (
101- < >
102- { checkboxRender }
103- { testamentList . map ( ( el , index ) => {
130+ const bookListRender = testamentList . map ( ( el , index ) => {
104131 return (
105132 < BookList
106133 bookClasses = { bookClasses }
@@ -117,17 +144,24 @@ function BibleBookList({
117144 title = { el . title }
118145 />
119146 ) ;
120- } ) }
147+ } )
148+
149+ return (
150+ < >
151+ { checkboxRender }
152+ { bookListRender }
121153 </ >
122154 ) ;
123155}
124156
125157BibleBookList . defaultProps = {
126158 showCheckbox : true ,
159+ showOBS : false ,
127160 sortFirstNT : false ,
128161 testaments : 'all' ,
129162 titleOT : '' ,
130163 titleNT : '' ,
164+ titleOBS : '' ,
131165 showInactive : true ,
132166 onClickBook : ( bookId ) => { } ,
133167 labelForCheckbox : 'Show only existing books' ,
@@ -139,6 +173,8 @@ BibleBookList.propTypes = {
139173 testaments : PropTypes . oneOf ( [ 'all' , 'nt' , 'ot' ] ) ,
140174 /** block header of "New Testament" */
141175 titleNT : PropTypes . string ,
176+ /** block header of "OBS" */
177+ titleOBS : PropTypes . string ,
142178 /** block header of "Old Testament" */
143179 titleOT : PropTypes . string ,
144180 /** when true, show first New Testament, second - Old Testament */
@@ -149,6 +185,8 @@ BibleBookList.propTypes = {
149185 titleBooks : PropTypes . object ,
150186 /** show or hide checkbox that show only existing books */
151187 showCheckbox : PropTypes . bool ,
188+ /** show or hide OBS block */
189+ showOBS : PropTypes . bool ,
152190 /** whether to display inactive books */
153191 showInactive : PropTypes . bool ,
154192 /** label of checkbox */
0 commit comments