-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: display collections and drb books
- Loading branch information
Chidi Orji
committed
Jul 21, 2019
1 parent
0e63582
commit 9ed82ad
Showing
20 changed files
with
312 additions
and
74 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
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
export const SET_AUTH_USER = 'SET_AUTH_USER'; | ||
|
||
export const GET_DRB_BOOKS = 'GET_DRB_BOOKS'; |
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,13 +1,10 @@ | ||
import { SET_AUTH_USER } from './constants'; | ||
// /* eslint-disable no-unused-vars */ | ||
// import { SET_AUTH_USER } from './actions.types'; | ||
|
||
// action creator | ||
export const set_auth_action_creator = id => ({ type: SET_AUTH_USER, id }); | ||
// // action creator | ||
// export const set_auth_action_creator = id => ({ type: SET_AUTH_USER, id }); | ||
|
||
// action dispatcher | ||
export const set_auth_user = () => { | ||
return dispatch => { | ||
return new Promise.resolve('AUTH_USER_ID').then(user => { | ||
dispatch(set_auth_action_creator(user)); | ||
}); | ||
}; | ||
}; | ||
// // action dispatcher | ||
// export const set_auth_user = () => dispatch => { | ||
// return dispatch; | ||
// }; |
This file was deleted.
Oops, something went wrong.
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,12 @@ | ||
import { GET_DRB_BOOKS } from './actions.types'; | ||
|
||
const get_drb_books_action_creator = booklist => { | ||
return { | ||
type: GET_DRB_BOOKS, | ||
booklist, | ||
}; | ||
}; | ||
|
||
export const get_drb_books = (book_list) => dispatch => { | ||
dispatch(get_drb_books_action_creator(book_list)); | ||
}; |
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,98 @@ | ||
import React, { Fragment, useState, useEffect } from 'react'; | ||
import axios from 'axios'; | ||
import titlecase from 'titlecase'; | ||
import slugify from 'slugify'; | ||
|
||
import Grid from '@material-ui/core/Grid'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
import { useDispatch } from 'react-redux'; | ||
|
||
import { DR_BOOKS_URL, default_headers } from '../constants'; | ||
import LinkGridItem from './LinkGridItem'; | ||
|
||
import { get_drb_books } from '../actions/drbActions'; | ||
|
||
const useStyles = makeStyles({ | ||
container: { | ||
paddingTop: '20px' | ||
}, | ||
}); | ||
|
||
const DouayBooks = () => { | ||
const classes = useStyles(); | ||
const dispatch = useDispatch(); | ||
const [books, setBooks] = useState(['a']); | ||
|
||
useEffect(() => { | ||
const getBooks = async () => { | ||
let books = []; | ||
let url = DR_BOOKS_URL; | ||
const config = { headers: { ...default_headers }}; | ||
|
||
while (url) { | ||
const { data } = await axios.get(url, config); | ||
const { results, next } = data; | ||
books = books.concat(results); | ||
url = next; | ||
} | ||
setBooks(books); | ||
dispatch(get_drb_books(books)); | ||
}; | ||
getBooks(); | ||
}, [dispatch]); | ||
|
||
|
||
return ( | ||
<Fragment> | ||
<h2>Douay-Rheims Bible</h2> | ||
|
||
<h3>Old Testament</h3> | ||
<Grid | ||
container | ||
spacing={2} | ||
classes={{ | ||
root: classes.container | ||
}} | ||
> | ||
{ | ||
books | ||
.filter(book => book.testament==='old testament') | ||
.map(book => { | ||
return ( | ||
<LinkGridItem | ||
key={ book.id } | ||
title={ titlecase(book.name) } | ||
location={ `/${slugify(book.name)}` } | ||
/> | ||
); | ||
}) | ||
} | ||
</Grid> | ||
|
||
<h3>New Testament</h3> | ||
<Grid | ||
container | ||
spacing={2} | ||
classes={{ | ||
root: classes.container | ||
}} | ||
> | ||
{ | ||
books | ||
.filter(book => book.testament==='new testament') | ||
.map(book => { | ||
return ( | ||
<LinkGridItem | ||
key={ book.id } | ||
title={ titlecase(book.name) } | ||
location={ `/${slugify(book.name)}` } | ||
/> | ||
); | ||
}) | ||
} | ||
</Grid> | ||
</Fragment> | ||
); | ||
}; | ||
|
||
export default DouayBooks; |
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
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,36 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Link } from 'react-router-dom'; | ||
import Grid from '@material-ui/core/Grid'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
|
||
const useStyles = makeStyles({ | ||
item: { | ||
// padding: '0px', | ||
// margin: '5px', | ||
} | ||
}); | ||
|
||
const LinkGridItem = props => { | ||
const classes = useStyles(); | ||
const { title, location } = props; | ||
|
||
return ( | ||
<Grid | ||
item | ||
classes={{ | ||
item: classes.item | ||
}} | ||
> | ||
<Link className='book-link' to={ location }>{ title }</Link> | ||
</Grid> | ||
); | ||
}; | ||
|
||
|
||
LinkGridItem.propTypes = { | ||
location: PropTypes.string.isRequired, | ||
title: PropTypes.string.isRequired | ||
}; | ||
|
||
export default LinkGridItem; |
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,19 @@ | ||
// eslint-disable-next-line no-unused-vars | ||
import React, { useState, useEffect } from 'react'; | ||
|
||
import axios from 'axios'; | ||
import { default_headers } from '../constants'; | ||
|
||
const useAxiosGet = url => { | ||
const [ data, setData ] = useState(null); | ||
const getData = async () => { | ||
const config = { headers: { ...default_headers }}; | ||
const resp = await axios.get(url, config); | ||
const json = resp.json(); | ||
setData(json); | ||
}; | ||
useEffect(() => { getData(url); [url];}); | ||
return data; | ||
}; | ||
|
||
export default useAxiosGet; |
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,9 @@ | ||
export const BASE_URL = 'https://ethodoxy.herokuapp.com/api/v1'; | ||
export const DR_BOOKS_URL = `${BASE_URL}/books/`; | ||
|
||
export const default_headers = { | ||
'Access-Control-Allow-Origin': '*', | ||
'Access-Control-Allow-Methods': 'PUT, GET, PATCH, POST', | ||
'Access-Control-Allow-Headers': 'Content-Type', | ||
'Access-Control-Max-Age': '3000', | ||
}; |
Oops, something went wrong.