fix double redirect issue

This commit is contained in:
Aria Moradi
2021-09-09 22:19:33 +04:30
parent 2e96dcedb3
commit 7f27e3b745

View File

@@ -6,11 +6,10 @@
* 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 { useTheme } from '@mui/material/styles';
import makeStyles from '@mui/styles/makeStyles'; 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 { Link, useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
import SearchIcon from '@mui/icons-material/Search'; import SearchIcon from '@mui/icons-material/Search';
import Button from '@mui/material/Button'; import Button from '@mui/material/Button';
import IconButton from '@mui/material/IconButton'; import IconButton from '@mui/material/IconButton';
@@ -76,26 +75,27 @@ interface IProps {
export default function SourceCard(props: IProps) { export default function SourceCard(props: IProps) {
const { const {
source: { source: {
// eslint-disable-next-line @typescript-eslint/no-unused-vars id, name, lang, iconUrl, supportsLatest,
id, name, lang, iconUrl, supportsLatest, isConfigurable,
}, },
} = props; } = props;
const theme = useTheme();
const history = useHistory(); const history = useHistory();
const [serverAddress] = useLocalStorage<String>('serverBaseURL', ''); const [serverAddress] = useLocalStorage<String>('serverBaseURL', '');
const classes = useStyles(); const classes = useStyles();
const redirectTo = (e: any, to: string) => {
history.push(to);
// prevent parent tags from getting the event
e.stopPropagation();
};
return ( return (
<Card className={classes.card}> <Card
<Link className={classes.card}
to={`/sources/${id}/popular/`} onClick={(e) => redirectTo(e, `/sources/${id}/popular/`)}
style={{
textDecoration: 'none',
color: theme.palette.text.primary,
}}
> >
<CardContent className={classes.root}> <CardContent className={classes.root}>
@@ -119,7 +119,7 @@ export default function SourceCard(props: IProps) {
<div className={classes.showMobile}> <div className={classes.showMobile}>
<IconButton <IconButton
style={{ width: 59, height: 59 }} style={{ width: 59, height: 59 }}
onClick={() => history.push(`/sources/${id}/search/`)} onClick={(e) => redirectTo(e, `/sources/${id}/search/`)}
size="large" size="large"
edge="end" edge="end"
> >
@@ -129,7 +129,7 @@ export default function SourceCard(props: IProps) {
</IconButton> </IconButton>
{supportsLatest && ( {supportsLatest && (
<IconButton <IconButton
onClick={() => history.push(`/sources/${id}/latest/`)} onClick={(e) => redirectTo(e, `/sources/${id}/latest/`)}
size="large" size="large"
> >
<FiberNewOutlinedIcon <FiberNewOutlinedIcon
@@ -142,7 +142,7 @@ export default function SourceCard(props: IProps) {
<Button <Button
variant="outlined" variant="outlined"
style={{ marginLeft: 20 }} style={{ marginLeft: 20 }}
onClick={() => history.push(`/sources/${id}/search/`)} onClick={(e) => redirectTo(e, `/sources/${id}/search/`)}
> >
Search Search
</Button> </Button>
@@ -150,7 +150,7 @@ export default function SourceCard(props: IProps) {
<Button <Button
variant="outlined" variant="outlined"
style={{ marginLeft: 20 }} style={{ marginLeft: 20 }}
onClick={() => history.push(`/sources/${id}/latest/`)} onClick={(e) => redirectTo(e, `/sources/${id}/latest/`)}
> >
Latest Latest
</Button> </Button>
@@ -158,14 +158,13 @@ export default function SourceCard(props: IProps) {
<Button <Button
variant="outlined" variant="outlined"
style={{ marginLeft: 20 }} style={{ marginLeft: 20 }}
onClick={() => history.push(`/sources/${id}/popular/`)} onClick={(e: any) => redirectTo(e, `/sources/${id}/popular/`)}
> >
Browse Browse
</Button> </Button>
</div> </div>
</div> </div>
</CardContent> </CardContent>
</Link>
</Card> </Card>
); );
} }