Created
February 21, 2020 16:10
-
-
Save r3dm1ke/4326fc428545bfee1281186e63b0c398 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 {useQuery} from "@apollo/react-hooks"; | |
| import React from 'react'; | |
| import {Typography, makeStyles, CircularProgress} from "@material-ui/core"; | |
| import {useDebounce} from "use-debounce"; | |
| import {SEARCH_FOR_REPOS} from "./queries"; | |
| const useStyles = makeStyles({ | |
| note: { | |
| marginTop: '1rem', | |
| textAlign: 'center', | |
| }, | |
| spinnerContainer: { | |
| display: 'flex', | |
| justifyContent: 'space-around', | |
| marginTop: '1rem' | |
| } | |
| }); | |
| const RepositoryList = ({searchTerm}) => { | |
| const classes = useStyles(); | |
| const [debouncedSearchTerm] = useDebounce(searchTerm, 1000); | |
| const {data, loading, error} = useQuery(SEARCH_FOR_REPOS, | |
| {variables: {search_term: debouncedSearchTerm}} | |
| ); | |
| if (loading) { | |
| return ( | |
| <div className={classes.spinnerContainer}> | |
| <CircularProgress /> | |
| </div> | |
| ); | |
| } | |
| if (error) { | |
| return ( | |
| <Typography | |
| variant={'overline'} | |
| className={classes.note} | |
| component={'div'} | |
| color={'error'} | |
| > | |
| {error} | |
| </Typography> | |
| ) | |
| } | |
| if (!data.search.repositoryCount) { | |
| return ( | |
| <Typography | |
| variant={'overline'} | |
| className={classes.note} | |
| component={'div'} | |
| > | |
| There are no such repositories! | |
| </Typography> | |
| ) | |
| } | |
| return ( | |
| <Typography | |
| variant={'overline'} | |
| className={classes.note} | |
| component={'div'} | |
| > | |
| Some repositories! | |
| </Typography> | |
| ); | |
| }; | |
| export default RepositoryList; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment