Created
February 21, 2020 18:31
-
-
Save r3dm1ke/4fa2680d3532966832932f9377d6be88 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import React, {useState} from 'react'; | |
| import {Dialog, DialogContent, ListItem, ListItemText} from '@material-ui/core' | |
| const Issue = ({title, bodyHTML}) => { | |
| const [dialogOpened, setDialogOpened] = useState(false); | |
| return ( | |
| <> | |
| <ListItem button onClick={() => setDialogOpened(true)}> | |
| <ListItemText>{title}</ListItemText> | |
| </ListItem> | |
| <Dialog maxWidth={'xl'} open={dialogOpened} onClose={() => setDialogOpened(false)}> | |
| <DialogContent> | |
| <div dangerouslySetInnerHTML={{__html: bodyHTML}}/> | |
| </DialogContent> | |
| </Dialog> | |
| </> | |
| ); | |
| }; | |
| export default Issue; |
This file contains hidden or 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
| import {useQuery} from '@apollo/react-hooks'; | |
| import {CircularProgress, List, Typography, makeStyles} from '@material-ui/core'; | |
| import React from 'react'; | |
| import Issue from "./Issue"; | |
| import {GET_REPO_ISSUES} from './queries'; | |
| const useStyles = makeStyles({ | |
| root: { | |
| flexDirection: 'column' | |
| }, | |
| spinnerContainer: { | |
| display: 'flex', | |
| justifyContent: 'space-around' | |
| } | |
| }); | |
| const IssueList = ({repoName, repoOwner}) => { | |
| const classes = useStyles(); | |
| const {data, loading, error} = useQuery(GET_REPO_ISSUES, | |
| {variables: { | |
| name: repoName, | |
| owner: repoOwner | |
| }}); | |
| if (loading) { | |
| return ( | |
| <div className={classes.spinnerContainer}> | |
| <CircularProgress /> | |
| </div> | |
| ); | |
| } | |
| if (error) { | |
| return ( | |
| <Typography | |
| variant={'overline'} | |
| component={'div'} | |
| color={'error'} | |
| > | |
| {error} | |
| </Typography> | |
| ) | |
| } | |
| if (!data.repository.issues.nodes.length) { | |
| return ( | |
| <Typography | |
| variant={'overline'} | |
| component={'div'} | |
| > | |
| There are no issues! | |
| </Typography> | |
| ) | |
| } | |
| return ( | |
| <div className={classes.root}> | |
| <Typography variant={'h5'}>Latest issues: </Typography> | |
| <List> | |
| {data.repository.issues.nodes.map(issue => ( | |
| <Issue title={issue.title} bodyHTML={issue.bodyHTML} /> | |
| ))} | |
| </List> | |
| </div> | |
| ); | |
| }; | |
| export default IssueList; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment