-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1027 from hackforla/mattyweb/issue1025
Mattyweb/issue1025
- Loading branch information
Showing
11 changed files
with
605 additions
and
8 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 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,86 @@ | ||
import React from 'react'; | ||
import ReactMarkdown from 'react-markdown'; | ||
import { | ||
makeStyles, | ||
Container, | ||
Box, | ||
Grid, | ||
List, | ||
ListItem, | ||
} from '@material-ui/core'; | ||
import useContentful from '../../hooks/useContentful'; | ||
|
||
const query = ` | ||
query { | ||
blogPostCollection(order: publishDate_DESC) { | ||
items { | ||
sys { id } | ||
slug | ||
title | ||
body | ||
publishDate | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const useStyles = makeStyles({ | ||
root: { | ||
color: 'black', | ||
backgroundColor: 'white', | ||
padding: '2em', | ||
'& h1': { | ||
fontSize: '2.5em', | ||
}, | ||
'& img': { | ||
maxWidth: '100%', | ||
height: 'auto', | ||
display: 'block', | ||
marginLeft: 'auto', | ||
marginRight: 'auto', | ||
}, | ||
}, | ||
}); | ||
|
||
const Blog = () => { | ||
const { data, errors } = useContentful(query); | ||
const classes = useStyles(); | ||
|
||
React.useEffect(() => { | ||
if (errors) console.log(errors); | ||
}, [errors]); | ||
|
||
return ( | ||
<> | ||
{ data | ||
&& ( | ||
<Container className={classes.root} maxWidth="md"> | ||
<Grid container spacing={2}> | ||
<Grid item xs={9}> | ||
{ data.blogPostCollection.items.map(item => ( | ||
<Box key={item.sys.id} style={{ marginBottom: '3em' }}> | ||
<h1 id={`${item.slug}`}>{item.title}</h1> | ||
<h4> | ||
{new Date(item.publishDate).toLocaleDateString()} | ||
</h4> | ||
<ReactMarkdown>{item.body}</ReactMarkdown> | ||
</Box> | ||
))} | ||
</Grid> | ||
<Grid item xs={3}> | ||
<List dense> | ||
{ data.blogPostCollection.items.map(item => ( | ||
<ListItem key={item.sys.id} component="a" href={`#${item.slug}`}> | ||
{item.title} | ||
</ListItem> | ||
))} | ||
</List> | ||
</Grid> | ||
</Grid> | ||
</Container> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default Blog; |
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,78 @@ | ||
import React from 'react'; | ||
import ReactMarkdown from 'react-markdown'; | ||
import { | ||
makeStyles, | ||
Container, | ||
Box, | ||
List, | ||
ListItem, | ||
Grid, | ||
} from '@material-ui/core'; | ||
import useContentful from '../../hooks/useContentful'; | ||
|
||
const query = ` | ||
query { | ||
faqCollection(order: priority_ASC) { | ||
items { | ||
sys { id } | ||
question | ||
answer | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const useStyles = makeStyles({ | ||
root: { | ||
color: 'black', | ||
backgroundColor: 'white', | ||
padding: '2em', | ||
'& h1': { | ||
fontSize: '2.5em', | ||
}, | ||
'& img': { | ||
maxWidth: '100%', | ||
height: 'auto', | ||
display: 'block', | ||
marginLeft: 'auto', | ||
marginRight: 'auto', | ||
}, | ||
}, | ||
}); | ||
|
||
const Faqs = () => { | ||
const { data, errors } = useContentful(query); | ||
const classes = useStyles(); | ||
|
||
React.useEffect(() => { | ||
if (errors) console.log(errors); | ||
}, [errors]); | ||
|
||
return ( | ||
<> | ||
{ data | ||
&& ( | ||
<Container className={classes.root} maxWidth="md"> | ||
<Grid container spacing={2}> | ||
<Grid item xs={9}> | ||
<h1>Frequently Asked Questions</h1> | ||
<List dense> | ||
{ data.faqCollection.items.map(item => ( | ||
<ListItem key={item.sys.id} component="a" href={`#${item.question}`}>{item.question}</ListItem> | ||
))} | ||
</List> | ||
{ data.faqCollection.items.map(item => ( | ||
<Box key={item.sys.id} style={{ marginBottom: '3em' }}> | ||
<h2 id={item.question}>{item.question}</h2> | ||
<ReactMarkdown>{item.answer}</ReactMarkdown> | ||
</Box> | ||
))} | ||
</Grid> | ||
</Grid> | ||
</Container> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default Faqs; |
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,64 @@ | ||
import React from 'react'; | ||
import ReactMarkdown from 'react-markdown'; | ||
import { | ||
makeStyles, | ||
Container, | ||
Grid, | ||
} from '@material-ui/core'; | ||
import useContentful from '../../hooks/useContentful'; | ||
|
||
const query = ` | ||
query { | ||
simplePageCollection(where: {slug: "privacy"}) { | ||
items { | ||
title | ||
body | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const useStyles = makeStyles({ | ||
root: { | ||
color: 'black', | ||
backgroundColor: 'white', | ||
padding: '2em', | ||
'& h1': { | ||
fontSize: '2.5em', | ||
}, | ||
'& img': { | ||
maxWidth: '100%', | ||
height: 'auto', | ||
display: 'block', | ||
marginLeft: 'auto', | ||
marginRight: 'auto', | ||
}, | ||
}, | ||
}); | ||
|
||
const Privacy = () => { | ||
const { data, errors } = useContentful(query); | ||
const classes = useStyles(); | ||
|
||
React.useEffect(() => { | ||
if (errors) console.log(errors); | ||
}, [errors]); | ||
|
||
return ( | ||
<> | ||
{ data | ||
&& ( | ||
<Container className={classes.root} maxWidth="md"> | ||
<Grid container spacing={2}> | ||
<Grid item xs={9}> | ||
<h1>{data.simplePageCollection.items[0].title}</h1> | ||
<ReactMarkdown>{data.simplePageCollection.items[0].body}</ReactMarkdown> | ||
</Grid> | ||
</Grid> | ||
</Container> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default Privacy; |
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,30 @@ | ||
/* eslint no-shadow: ["error", { "allow": ["data", "errors"] }] */ | ||
import React from 'react'; | ||
|
||
const url = `https://graphql.contentful.com/content/v1/spaces/${process.env.CONTENTFUL_SPACE}`; | ||
|
||
const useContentful = query => { | ||
const [data, setData] = React.useState(null); | ||
const [errors, setErrors] = React.useState(null); | ||
|
||
React.useEffect(() => { | ||
fetch(url, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${process.env.CONTENTFUL_TOKEN}`, | ||
}, | ||
body: JSON.stringify({ query }), | ||
}) | ||
.then(response => response.json()) | ||
.then(({ data, errors }) => { | ||
if (errors) setErrors(errors); | ||
if (data) setData(data); | ||
}) | ||
.catch(error => setErrors([error])); | ||
}, [query]); | ||
|
||
return { data, errors }; | ||
}; | ||
|
||
export default useContentful; |
Oops, something went wrong.