migrate SourceCard to Mui 5 (#82)
* migrate SourceCard to Mui 5 * give semantic meaning
This commit is contained in:
@@ -6,7 +6,6 @@
|
|||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import makeStyles from '@mui/styles/makeStyles';
|
|
||||||
import Card from '@mui/material/Card';
|
import Card from '@mui/material/Card';
|
||||||
import CardContent from '@mui/material/CardContent';
|
import CardContent from '@mui/material/CardContent';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
@@ -18,53 +17,23 @@ import Avatar from '@mui/material/Avatar';
|
|||||||
import Typography from '@mui/material/Typography';
|
import Typography from '@mui/material/Typography';
|
||||||
import useLocalStorage from 'util/useLocalStorage';
|
import useLocalStorage from 'util/useLocalStorage';
|
||||||
import { langCodeToName } from 'util/language';
|
import { langCodeToName } from 'util/language';
|
||||||
|
import { Box, styled } from '@mui/system';
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const MobileWidthButtons = styled('div')(({ theme }) => ({
|
||||||
root: {
|
display: 'flex',
|
||||||
display: 'flex',
|
[theme.breakpoints.up('sm')]: {
|
||||||
justifyContent: 'space-between',
|
display: 'none',
|
||||||
alignItems: 'center',
|
|
||||||
padding: 16,
|
|
||||||
},
|
},
|
||||||
bullet: {
|
}));
|
||||||
display: 'inline-block',
|
|
||||||
margin: '0 2px',
|
const WiderWidthButtons = styled('div')(({ theme }) => ({
|
||||||
transform: 'scale(0.8)',
|
display: 'flex',
|
||||||
|
[theme.breakpoints.down('sm')]: {
|
||||||
|
display: 'none',
|
||||||
},
|
},
|
||||||
title: {
|
|
||||||
fontSize: 14,
|
'& .MuiButton-root': {
|
||||||
},
|
marginLeft: '20px',
|
||||||
pos: {
|
|
||||||
marginBottom: 12,
|
|
||||||
},
|
|
||||||
icon: {
|
|
||||||
width: theme.spacing(7),
|
|
||||||
height: theme.spacing(7),
|
|
||||||
flex: '0 0 auto',
|
|
||||||
marginRight: 16,
|
|
||||||
},
|
|
||||||
card: {
|
|
||||||
margin: '10px',
|
|
||||||
'&:hover': {
|
|
||||||
backgroundColor: theme.palette.action.hover,
|
|
||||||
transition: 'background-color 100ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',
|
|
||||||
},
|
|
||||||
'&:active': {
|
|
||||||
backgroundColor: theme.palette.action.selected,
|
|
||||||
transition: 'background-color 100ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
showMobile: {
|
|
||||||
display: 'flex',
|
|
||||||
[theme.breakpoints.up('sm')]: {
|
|
||||||
display: 'none',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
showBigger: {
|
|
||||||
display: 'flex',
|
|
||||||
[theme.breakpoints.down('sm')]: {
|
|
||||||
display: 'none',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -84,8 +53,6 @@ export default function SourceCard(props: IProps) {
|
|||||||
const [serverAddress] = useLocalStorage<String>('serverBaseURL', '');
|
const [serverAddress] = useLocalStorage<String>('serverBaseURL', '');
|
||||||
const [useCache] = useLocalStorage<boolean>('useCache', true);
|
const [useCache] = useLocalStorage<boolean>('useCache', true);
|
||||||
|
|
||||||
const classes = useStyles();
|
|
||||||
|
|
||||||
const redirectTo = (e: any, to: string) => {
|
const redirectTo = (e: any, to: string) => {
|
||||||
history.push(to);
|
history.push(to);
|
||||||
|
|
||||||
@@ -95,19 +62,40 @@ export default function SourceCard(props: IProps) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
className={classes.card}
|
sx={{
|
||||||
|
margin: '10px',
|
||||||
|
'&:hover': {
|
||||||
|
backgroundColor: 'action.hover',
|
||||||
|
transition: 'background-color 100ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',
|
||||||
|
},
|
||||||
|
'&:active': {
|
||||||
|
backgroundColor: 'action.selected',
|
||||||
|
transition: 'background-color 100ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',
|
||||||
|
},
|
||||||
|
}}
|
||||||
onClick={(e) => redirectTo(e, `/sources/${id}/popular/`)}
|
onClick={(e) => redirectTo(e, `/sources/${id}/popular/`)}
|
||||||
>
|
>
|
||||||
<CardContent className={classes.root}>
|
<CardContent sx={{
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
alignItems: 'center',
|
||||||
|
padding: 2,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
|
||||||
<div style={{ display: 'flex' }}>
|
<Box sx={{ display: 'flex' }}>
|
||||||
<Avatar
|
<Avatar
|
||||||
variant="rounded"
|
variant="rounded"
|
||||||
className={classes.icon}
|
|
||||||
alt={name}
|
alt={name}
|
||||||
|
sx={{
|
||||||
|
width: 56,
|
||||||
|
height: 56,
|
||||||
|
flex: '0 0 auto',
|
||||||
|
mr: 2,
|
||||||
|
}}
|
||||||
src={`${serverAddress}${iconUrl}?useCache=${useCache}`}
|
src={`${serverAddress}${iconUrl}?useCache=${useCache}`}
|
||||||
/>
|
/>
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', justifyContent: 'center' }}>
|
<Box sx={{ display: 'flex', flexDirection: 'column', justifyContent: 'center' }}>
|
||||||
<Typography variant="h5" component="h2">
|
<Typography variant="h5" component="h2">
|
||||||
{name}
|
{name}
|
||||||
</Typography>
|
</Typography>
|
||||||
@@ -116,12 +104,12 @@ export default function SourceCard(props: IProps) {
|
|||||||
{langCodeToName(lang)}
|
{langCodeToName(lang)}
|
||||||
</Typography>
|
</Typography>
|
||||||
)}
|
)}
|
||||||
</div>
|
</Box>
|
||||||
</div>
|
</Box>
|
||||||
<div>
|
<>
|
||||||
<div className={classes.showMobile}>
|
<MobileWidthButtons>
|
||||||
<IconButton
|
<IconButton
|
||||||
style={{ width: 59, height: 59 }}
|
sx={{ width: 59, height: 59 }}
|
||||||
onClick={(e) => redirectTo(e, `/sources/${id}/search/`)}
|
onClick={(e) => redirectTo(e, `/sources/${id}/search/`)}
|
||||||
size="large"
|
size="large"
|
||||||
edge="end"
|
edge="end"
|
||||||
@@ -140,11 +128,10 @@ export default function SourceCard(props: IProps) {
|
|||||||
/>
|
/>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
)}
|
)}
|
||||||
</div>
|
</MobileWidthButtons>
|
||||||
<div className={classes.showBigger}>
|
<WiderWidthButtons>
|
||||||
<Button
|
<Button
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
style={{ marginLeft: 20 }}
|
|
||||||
onClick={(e) => redirectTo(e, `/sources/${id}/search/`)}
|
onClick={(e) => redirectTo(e, `/sources/${id}/search/`)}
|
||||||
>
|
>
|
||||||
Search
|
Search
|
||||||
@@ -152,7 +139,6 @@ export default function SourceCard(props: IProps) {
|
|||||||
{supportsLatest && (
|
{supportsLatest && (
|
||||||
<Button
|
<Button
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
style={{ marginLeft: 20 }}
|
|
||||||
onClick={(e) => redirectTo(e, `/sources/${id}/latest/`)}
|
onClick={(e) => redirectTo(e, `/sources/${id}/latest/`)}
|
||||||
>
|
>
|
||||||
Latest
|
Latest
|
||||||
@@ -160,13 +146,12 @@ export default function SourceCard(props: IProps) {
|
|||||||
)}
|
)}
|
||||||
<Button
|
<Button
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
style={{ marginLeft: 20 }}
|
|
||||||
onClick={(e: any) => redirectTo(e, `/sources/${id}/popular/`)}
|
onClick={(e: any) => redirectTo(e, `/sources/${id}/popular/`)}
|
||||||
>
|
>
|
||||||
Browse
|
Browse
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</WiderWidthButtons>
|
||||||
</div>
|
</>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user