Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate SourceCard to Mui 5 #82

Merged
merged 2 commits into from
Nov 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 49 additions & 64 deletions src/components/SourceCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

import React from 'react';
import makeStyles from '@mui/styles/makeStyles';
import Card from '@mui/material/Card';
import CardContent from '@mui/material/CardContent';
import { useHistory } from 'react-router-dom';
Expand All @@ -18,53 +17,23 @@ import Avatar from '@mui/material/Avatar';
import Typography from '@mui/material/Typography';
import useLocalStorage from 'util/useLocalStorage';
import { langCodeToName } from 'util/language';
import { Box, styled } from '@mui/system';

const useStyles = makeStyles((theme) => ({
root: {
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
padding: 16,
const MobileWidthButtons = styled('div')(({ theme }) => ({
display: 'flex',
[theme.breakpoints.up('sm')]: {
display: 'none',
},
bullet: {
display: 'inline-block',
margin: '0 2px',
transform: 'scale(0.8)',
},
title: {
fontSize: 14,
},
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',
},
}));

const WiderWidthButtons = styled('div')(({ theme }) => ({
display: 'flex',
[theme.breakpoints.down('sm')]: {
display: 'none',
},
showBigger: {
display: 'flex',
[theme.breakpoints.down('sm')]: {
display: 'none',
},

'& .MuiButton-root': {
marginLeft: '20px',
},
}));

Expand All @@ -84,8 +53,6 @@ export default function SourceCard(props: IProps) {
const [serverAddress] = useLocalStorage<String>('serverBaseURL', '');
const [useCache] = useLocalStorage<boolean>('useCache', true);

const classes = useStyles();

const redirectTo = (e: any, to: string) => {
history.push(to);

Expand All @@ -95,19 +62,40 @@ export default function SourceCard(props: IProps) {

return (
<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/`)}
>
<CardContent className={classes.root}>
<CardContent sx={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
padding: 2,
}}
>

<div style={{ display: 'flex' }}>
<Box sx={{ display: 'flex' }}>
<Avatar
variant="rounded"
className={classes.icon}
alt={name}
sx={{
width: 56,
height: 56,
flex: '0 0 auto',
mr: 2,
}}
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">
{name}
</Typography>
Expand All @@ -116,12 +104,12 @@ export default function SourceCard(props: IProps) {
{langCodeToName(lang)}
</Typography>
)}
</div>
</div>
<div>
<div className={classes.showMobile}>
</Box>
</Box>
<>
<MobileWidthButtons>
<IconButton
style={{ width: 59, height: 59 }}
sx={{ width: 59, height: 59 }}
onClick={(e) => redirectTo(e, `/sources/${id}/search/`)}
size="large"
edge="end"
Expand All @@ -140,33 +128,30 @@ export default function SourceCard(props: IProps) {
/>
</IconButton>
)}
</div>
<div className={classes.showBigger}>
</MobileWidthButtons>
<WiderWidthButtons>
<Button
variant="outlined"
style={{ marginLeft: 20 }}
onClick={(e) => redirectTo(e, `/sources/${id}/search/`)}
>
Search
</Button>
{supportsLatest && (
<Button
variant="outlined"
style={{ marginLeft: 20 }}
onClick={(e) => redirectTo(e, `/sources/${id}/latest/`)}
>
Latest
</Button>
)}
<Button
variant="outlined"
style={{ marginLeft: 20 }}
onClick={(e: any) => redirectTo(e, `/sources/${id}/popular/`)}
>
Browse
</Button>
</div>
</div>
</WiderWidthButtons>
</>
</CardContent>
</Card>
);
Expand Down