Skip to content

Commit

Permalink
Fixed dynamic Title in Parallel Scripture Example
Browse files Browse the repository at this point in the history
  • Loading branch information
klappy committed Oct 21, 2019
1 parent dc65ab8 commit b5cc51a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/components/parallel-scripture/ParallelScripture.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,30 @@ import {ParallelScripture, withResources} from "scripture-resources-rcl";
import usfmJS from 'usfm-js';

function Component ({resources, reference}) {
const [title, setTitle] = React.useState();
const [titles, setTitles] = React.useState([]);
const [books, setBooks] = React.useState([]);
const [quote, setQuote] = React.useState();

React.useEffect(() => {
const _titles = resources.map((resource) => {
let _title = `Error: ${resource.resourceLink}`;
if (resource.manifest) {
const { manifest: { dublin_core: {title, version} } } = resource;
_title =`${title} v${version}`;
}
return _title;
});
setTitles(_titles);
const promises = resources.map((resource, index) => resource.project.file() );
Promise.all(promises).then(files => {
const _books = files.map(file => usfmJS.toJSON(file));
setBooks(_books);
});
if (resources.length > 0) {
const {title: _title} = resources[0].project;
setTitle(_title);
const _titles = resources.map((resource) => {
let _title = `Error: ${resource.resourceLink}`;
if (resource.manifest) {
const { manifest: { dublin_core: {title, version} } } = resource;
_title =`${title} v${version}`;
}
return _title;
});
setTitles(_titles);
const promises = resources.map((resource, index) => resource.project.file() );
Promise.all(promises).then(files => {
const _books = files.map(file => usfmJS.toJSON(file));
setBooks(_books);
});
}
}, [resources]);

return (
Expand All @@ -33,7 +38,7 @@ function Component ({resources, reference}) {
<ParallelScripture
titles={titles}
books={books}
title='Titus'
title={title}
reference={reference}
onQuote={setQuote}
height='250px'
Expand Down
1 change: 1 addition & 0 deletions src/components/selections/withSelections.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const parsify = (array) => array.map(string => JSON.parse(string));

function withSelections(Component){
return function SelectionsComponent({
quote,
onQuote,
quoteVerseObjects,
...props
Expand Down

0 comments on commit b5cc51a

Please sign in to comment.