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

Enhance display of many link previews #571

Merged
merged 6 commits into from
Jul 21, 2024
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
35 changes: 26 additions & 9 deletions components/Hyperlinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { HyperlinkIcon } from 'components/icons';

const useStyles = makeStyles(theme => ({
root: {
display: 'flex',
flexFlow: 'row',
flexWrap: 'wrap',
},
linkcard: {
padding: '12px 16px',
margin: '0 8px 8px 0',
background: theme.palette.secondary[50],
Expand All @@ -23,6 +28,20 @@ const useStyles = makeStyles(theme => ({
fontSize: 14,
},
},
multilink: {
[theme.breakpoints.down('sm')]: {
flexWrap: 'nowrap',
overflowX: 'auto',
'--gutter': `${theme.spacing(2)}px`,
marginLeft: 'calc(-1 * var(--gutter))',
marginRight: 'calc(-1 * var(--gutter))',
paddingLeft: 'var(--gutter)',
paddingRight: 'var(--gutter)',
'& article': {
maxWidth: '90%',
},
},
},
url: {
color: theme.palette.secondary[300],
display: 'flex',
Expand Down Expand Up @@ -136,7 +155,7 @@ function Hyperlink({ hyperlink, rel = '' }) {
const classes = useStyles({ topImageUrl });

return (
<article className={classes.root}>
<article className={classes.linkcard}>
<h1 title={title}>{title}</h1>
<div className={classes.preview}>
<p className="summary" title={summary}>
Expand Down Expand Up @@ -177,21 +196,19 @@ function PollingHyperlink({ pollingType, pollingId }) {
* @param {string?} props.rel - rel prop for the hyperlink (other than noopener and noreferrer)
*/
function Hyperlinks({ hyperlinks, pollingType, pollingId, rel }) {
const classes = useStyles();
if (!((pollingId && pollingType) || (!pollingId && !pollingType))) {
throw new Error('pollingType and pollingId must be specified together');
}

if (hyperlinks && hyperlinks.length === 0) return null;

let className = `${classes.root}`;
if (hyperlinks.length > 1) {
className += ` ${classes.multilink}`;
}
return (
<Box
component="section"
display="flex"
flexDirection="row"
flexWrap="wrap"
mt={2}
mb={1}
>
<Box className={className} component="section" mt={2} mb={1}>
{(hyperlinks || []).map((hyperlink, idx) => (
<Hyperlink key={idx} hyperlink={hyperlink} rel={rel} />
))}
Expand Down
Loading