-
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(locations): added a residents avatars on locations grid card
- Loading branch information
1 parent
25fccf2
commit 221130e
Showing
8 changed files
with
216 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Avatar, makeStyles } from '@material-ui/core'; | ||
import { Skeleton } from '@material-ui/lab'; | ||
import React from 'react'; | ||
import { Character } from '../../models/Character'; | ||
|
||
// component style | ||
const useStyles = makeStyles((theme) => ({ | ||
large: { | ||
width: theme.spacing(7), | ||
height: theme.spacing(7), | ||
margin: theme.spacing(1) | ||
} | ||
})); | ||
|
||
export default function LocationCardResidentAvatar({ | ||
resident, | ||
isLoading | ||
}: { | ||
resident: Character; | ||
isLoading: boolean; | ||
}) { | ||
const classes = useStyles(); | ||
|
||
if (isLoading) { | ||
return <Skeleton className={classes.large} variant="circle" />; | ||
} | ||
|
||
return <Avatar alt={resident.name} src={resident.image} className={classes.large} />; | ||
} |
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,99 @@ | ||
/* eslint-disable jsx-a11y/anchor-is-valid */ | ||
/* eslint-disable react/no-array-index-key */ | ||
import { Grid, Link, makeStyles, Typography } from '@material-ui/core'; | ||
import { Skeleton } from '@material-ui/lab'; | ||
import React from 'react'; | ||
import { useDispatch } from 'react-redux'; | ||
import useMediaQueries from '../../hooks/useMediaQueries'; | ||
import { Location } from '../../models/Location'; | ||
import { setDialogCharacters, setDialogOpen, setDialogTitle } from '../../store/charactersDialog'; | ||
import LocationCardResidentAvatar from './LocationCardResidentAvatar'; | ||
|
||
// component style | ||
const useStyles = makeStyles((theme) => ({ | ||
container: { | ||
paddingTop: theme.spacing(3) | ||
}, | ||
avatarsContainer: { | ||
paddingTop: theme.spacing(1) | ||
}, | ||
viewMore: { | ||
paddingTop: theme.spacing(1) | ||
} | ||
})); | ||
|
||
export default function LocationCardResidents({ location, isLoading }: { location: Location; isLoading: boolean }) { | ||
let avatarsCount = 5; | ||
const classes = useStyles(); | ||
const { xs, sm, md, lg, xl } = useMediaQueries(); | ||
const dispatch = useDispatch(); | ||
|
||
const openFullScreenDialog = () => { | ||
dispatch(setDialogCharacters(location.residents)); | ||
dispatch(setDialogTitle(`Residents of ${location.name}`)); | ||
dispatch(setDialogOpen(true)); | ||
}; | ||
|
||
if (xs) { | ||
avatarsCount = 10; | ||
} | ||
|
||
if (sm) { | ||
avatarsCount = 6; | ||
} | ||
|
||
if (md) { | ||
avatarsCount = 10; | ||
} | ||
|
||
if (lg) { | ||
avatarsCount = 3; | ||
} | ||
|
||
if (xl) { | ||
avatarsCount = 4; | ||
} | ||
|
||
return ( | ||
<> | ||
<div className={classes.container}> | ||
{isLoading ? ( | ||
<Skeleton height={20} /> | ||
) : ( | ||
<> | ||
<Typography variant="subtitle2" component="label" color="textSecondary"> | ||
Residents | ||
</Typography> | ||
|
||
{location.residents.length > avatarsCount ? ( | ||
<> | ||
| ||
<Link | ||
component="button" | ||
variant="body2" | ||
onClick={() => { | ||
openFullScreenDialog(); | ||
}} | ||
> | ||
View more | ||
</Link> | ||
</> | ||
) : null} | ||
</> | ||
)} | ||
|
||
<div className={classes.avatarsContainer}> | ||
<Grid container> | ||
{(isLoading ? Array.from(new Array(avatarsCount)) : location.residents.slice(0, avatarsCount)).map( | ||
(resident, index) => ( | ||
<Grid item key={index}> | ||
<LocationCardResidentAvatar resident={resident} isLoading={isLoading} /> | ||
</Grid> | ||
) | ||
)} | ||
</Grid> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
} |
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,35 +1,16 @@ | ||
import { makeStyles, Typography } from '@material-ui/core'; | ||
import { Typography } from '@material-ui/core'; | ||
import { Skeleton } from '@material-ui/lab'; | ||
import React from 'react'; | ||
import { Location } from '../../models/Location'; | ||
|
||
// component style | ||
const useStyles = makeStyles(() => ({ | ||
cardTitle: { | ||
width: '320px', | ||
whiteSpace: 'nowrap', | ||
overflow: 'hidden', | ||
textOverflow: 'ellipsis' | ||
} | ||
})); | ||
|
||
export default function LocationCardTitle({ location, isLoading }: { location: Location; isLoading: boolean }) { | ||
const classes = useStyles(); | ||
|
||
if (isLoading) { | ||
return ( | ||
<> | ||
<Skeleton height={44} /> | ||
<Skeleton height={20} /> | ||
</> | ||
); | ||
return <Skeleton height={44} />; | ||
} | ||
|
||
return ( | ||
<> | ||
<Typography className={classes.cardTitle} component="h2" variant="h4" data-cy="location-name"> | ||
{location.name} | ||
</Typography> | ||
</> | ||
<Typography component="h2" variant="h4" data-cy="location-name"> | ||
{location.name} | ||
</Typography> | ||
); | ||
} |
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 @@ | ||
import { makeStyles } from '@material-ui/core'; | ||
|
||
export default makeStyles((theme) => ({ | ||
title: { | ||
marginLeft: theme.spacing(3) | ||
}, | ||
cardGrid: { | ||
paddingTop: theme.spacing(4), | ||
paddingLeft: theme.spacing(6), | ||
paddingRight: theme.spacing(6), | ||
|
||
[theme.breakpoints.down('lg')]: { | ||
paddingLeft: '8rem', | ||
paddingRight: '8rem' | ||
}, | ||
|
||
[theme.breakpoints.down('md')]: { | ||
paddingLeft: '12rem', | ||
paddingRight: '12rem' | ||
}, | ||
[theme.breakpoints.down('sm')]: { | ||
paddingLeft: theme.spacing(6), | ||
paddingRight: theme.spacing(6) | ||
} | ||
}, | ||
loadingText: { | ||
textAlign: 'center', | ||
color: theme.palette.text.hint | ||
} | ||
})); |
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,15 @@ | ||
import { useMediaQuery, useTheme } from '@material-ui/core'; | ||
|
||
/** | ||
* Hook for handle media queries | ||
*/ | ||
export default () => { | ||
const theme = useTheme(); | ||
const xs = useMediaQuery(theme.breakpoints.only('xs')); | ||
const sm = useMediaQuery(theme.breakpoints.only('sm')); | ||
const md = useMediaQuery(theme.breakpoints.only('md')); | ||
const lg = useMediaQuery(theme.breakpoints.only('lg')); | ||
const xl = useMediaQuery(theme.breakpoints.only('xl')); | ||
|
||
return { xs, sm, md, lg, xl }; | ||
}; |
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