-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
106 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export {default as withResource} from './withResource'; | ||
export {default as withResource} from './withResource'; | ||
export {default as withResources} from './withResources'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import PropTypes from 'prop-types'; | ||
import deepFreeze from 'deep-freeze'; | ||
|
||
import {resourcesFromResourceLinks} from '../../core'; | ||
|
||
function WithResources(Component){ | ||
function ResourcesComponent({ | ||
resourceLinks, | ||
config, | ||
...props | ||
}) { | ||
const [resources, setResources] = useState([]); | ||
|
||
useEffect(() => { | ||
resourcesFromResourceLinks({resourceLinks, config}) | ||
.then(_resources => { | ||
setResources(deepFreeze(_resources)); | ||
}); | ||
}, [resourceLinks, config]); | ||
|
||
return ( | ||
<Component resources={resources} {...props} /> | ||
); | ||
} | ||
|
||
ResourcesComponent.propTypes = WithResources.propTypes; | ||
|
||
return ResourcesComponent; | ||
} | ||
|
||
WithResources.propTypes = { | ||
/** The link to parse and fetch the resource manifest */ | ||
resourceLinks: PropTypes.arrayOf( | ||
PropTypes.string.isRequired | ||
).isRequired, | ||
/** The configuration of the server, and fetching */ | ||
config: PropTypes.shape({ | ||
server: PropTypes.string.isRequired, | ||
/** the overriding cache settings */ | ||
cache: PropTypes.shape({ | ||
/** cache age in ms */ | ||
maxAge: PropTypes.number | ||
}) | ||
}), | ||
}; | ||
|
||
export default WithResources; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
```js | ||
import {Paper} from '@material-ui/core'; | ||
import ReactJson from 'react-json-view'; | ||
import {withResources} from 'scripture-resources-rcl'; | ||
|
||
function Component ({resources}) { | ||
const [files, setFiles] = React.useState([]); | ||
|
||
React.useEffect(() => { | ||
const promises = resources.map((resource, index) => resource.project.file() ); | ||
Promise.all(promises).then(_files => setFiles(_files)); | ||
}, [resources]); | ||
|
||
const component = resources.map((resource, index) => ( | ||
<> | ||
<Paper style={{maxHeight: '250px', margin: '1em', padding: '1em', overflow: 'scroll'}}> | ||
<ReactJson src={resource} /> | ||
</Paper> | ||
<Paper style={{maxHeight: '250px', margin: '1em', padding: '1em', overflow: 'scroll'}}> | ||
<pre> | ||
{files[index]} | ||
</pre> | ||
</Paper> | ||
</> | ||
)); | ||
|
||
return component; | ||
}; | ||
const ResourcesComponent = withResources(Component); | ||
|
||
const resourceLinks = [ | ||
'unfoldingWord/el-x-koine/ugnt/v0.8/tit', | ||
'unfoldingWord/en/ult/v5/tit', | ||
'unfoldingWord/en/ust/v5/tit', | ||
]; | ||
|
||
const config = { | ||
server: 'https://git.door43.org', | ||
cache: { | ||
maxAge: 1 * 1 * 1 * 60 * 1000, // override cache to 1 minute | ||
}, | ||
}; | ||
|
||
<ResourcesComponent resourceLinks={resourceLinks} config={config} /> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters