Skip to content

Commit 72f9132

Browse files
authored
Merge pull request #27 from texttree/develop
Clean code + add OBS in bibles
2 parents cb3e51a + 89b1a3b commit 72f9132

8 files changed

Lines changed: 132 additions & 25 deletions

File tree

src/components/BibleBookList/BibleBookList.js

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import React, { useState } from 'react';
22
import BookList from '../BookList';
33
import 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';
512
import Checkbox from '@material-ui/core/Checkbox';
613
import { 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

125157
BibleBookList.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 */

src/components/BibleBookList/BibleBookList.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ const titleBooks = {
99
mrk: 'Марк',
1010
luk: 'Лука',
1111
tit: 'Титу',
12+
obs: 'Открытые Библейские Истории',
1213
};
1314

1415
const [selectedBookId, setSelectedBookId] = React.useState('exo');
1516

1617
const onClickBook = (bookId) => setSelectedBookId(bookId);
1718

18-
const availableBookList = ['gen', 'exo', 'lev', 'num', 'mat', 'mrk', 'luk', 'tit'];
19+
const availableBookList = ['gen', 'exo', 'lev', 'num', 'mat', 'mrk', 'luk', 'tit', 'obs'];
1920

2021
const NTBookList = [
2122
'mat',
@@ -53,6 +54,8 @@ const NTBookList = [
5354
showInactive={false}
5455
titleOT="Old Testament"
5556
titleNT="New Testament"
57+
titleOBS="Other"
58+
showOBS={true}
5659
titleBooks={titleBooks}
5760
availableBookList={availableBookList} // replace to NTBookList
5861
selectedBookId={selectedBookId}

src/components/BibleBookList/config.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,19 @@ export const NEW_TESTAMENT = {
6969
rev: 'Revelation',
7070
};
7171

72-
export const BIBLE_BOOKS = {
73-
...NEW_TESTAMENT,
74-
...OLD_TESTAMENT,
72+
export const OBS = {
73+
obs: 'Open Bible Story',
7574
};
7675

76+
export const OBS_LIST = [
77+
{
78+
identifier: 'obs',
79+
isset: false,
80+
sort: 70,
81+
categories: 'obs',
82+
},
83+
];
84+
7785
export const OLD_TESTAMENT_LIST = [
7886
{
7987
identifier: 'gen',
@@ -474,4 +482,3 @@ export const NEW_TESTAMENT_LIST = [
474482
categories: 'bible-nt',
475483
},
476484
];
477-
export const BIBLE_LIST = OLD_TESTAMENT_LIST.concat(NEW_TESTAMENT_LIST);

src/components/BibleChapterList/config.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,4 +1320,56 @@ export const BOOK_CHAPTERS = {
13201320
21: '27',
13211321
22: '21',
13221322
},
1323+
obs: {
1324+
1: '1',
1325+
2: '1',
1326+
3: '1',
1327+
4: '1',
1328+
5: '1',
1329+
6: '1',
1330+
7: '1',
1331+
8: '1',
1332+
9: '1',
1333+
10: '1',
1334+
11: '1',
1335+
12: '1',
1336+
13: '1',
1337+
14: '1',
1338+
15: '1',
1339+
16: '1',
1340+
17: '1',
1341+
18: '1',
1342+
19: '1',
1343+
20: '1',
1344+
21: '1',
1345+
22: '1',
1346+
23: '1',
1347+
24: '1',
1348+
25: '1',
1349+
26: '1',
1350+
27: '1',
1351+
28: '1',
1352+
29: '1',
1353+
30: '1',
1354+
31: '1',
1355+
32: '1',
1356+
33: '1',
1357+
34: '1',
1358+
35: '1',
1359+
36: '1',
1360+
37: '1',
1361+
38: '1',
1362+
39: '1',
1363+
40: '1',
1364+
41: '1',
1365+
42: '1',
1366+
43: '1',
1367+
44: '1',
1368+
45: '1',
1369+
46: '1',
1370+
47: '1',
1371+
48: '1',
1372+
49: '1',
1373+
50: '1',
1374+
},
13231375
};

src/components/Book/Book.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Button from '@material-ui/core/Button';
33
import PropTypes from 'prop-types';
44

55
function Book({ isset, bookId, classes, className, isSelected, text, onClick }) {
6+
67
return (
78
<Button
89
className={className}

src/components/BookList/BookList.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@ function BookList({
1212
onClickBook,
1313
showInactive,
1414
}) {
15-
return (
16-
<>
17-
<div className={bookListClasses?.title}>{title}</div>
18-
<Box className={bookListClasses?.bookList}>
19-
{bookList.map(
15+
16+
bookListRender = bookList.map(
2017
(el, index) =>
2118
(showInactive || el.isset) && (
2219
<Book
@@ -30,7 +27,13 @@ function BookList({
3027
text={el.text}
3128
/>
3229
)
33-
)}
30+
)
31+
32+
return (
33+
<>
34+
<div className={bookListClasses?.title}>{title}</div>
35+
<Box className={bookListClasses?.bookList}>
36+
{bookListRender}
3437
</Box>
3538
</>
3639
);

src/components/Chapter/Chapter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Button from '@material-ui/core/Button';
33
import PropTypes from 'prop-types';
44

55
function Chapter({ isSelected, classes, className, chapterId, chapterPrefix, onClick }) {
6+
67
return (
78
<Button
89
className={className}

src/components/ChapterList/ChapterList.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ function ChapterList({
1111
selectedChapter,
1212
onClickChapter,
1313
}) {
14-
return (
15-
<Box className={chapterListClasses?.chapterList}>
16-
{chapterList.map((el, index) => (
14+
chapterListRender = chapterList.map((el, index) => (
1715
<Chapter
1816
chapterId={el}
1917
chapterPrefix={chapterPrefix}
@@ -23,7 +21,11 @@ function ChapterList({
2321
key={index}
2422
onClick={onClickChapter}
2523
/>
26-
))}
24+
))
25+
26+
return (
27+
<Box className={chapterListClasses?.chapterList}>
28+
{chapterListRender}
2729
</Box>
2830
);
2931
}

0 commit comments

Comments
 (0)