forked from mastodon/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Glitch] Add author links on the explore page in web UI
Port ed6d243 to glitch-soc Signed-off-by: Claire <[email protected]>
- Loading branch information
1 parent
454dc40
commit fd36977
Showing
10 changed files
with
187 additions
and
84 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
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
19 changes: 19 additions & 0 deletions
19
app/javascript/flavours/glitch/components/more_from_author.jsx
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,19 @@ | ||
import PropTypes from 'prop-types'; | ||
|
||
import { FormattedMessage } from 'react-intl'; | ||
|
||
import { AuthorLink } from 'flavours/glitch/features/explore/components/author_link'; | ||
|
||
export const MoreFromAuthor = ({ accountId }) => ( | ||
<div className='more-from-author'> | ||
<svg viewBox='0 0 79 79' className='logo logo--icon' role='img'> | ||
<use xlinkHref='#logo-symbol-icon' /> | ||
</svg> | ||
|
||
<FormattedMessage id='link_preview.more_from_author' defaultMessage='More from {name}' values={{ name: <AuthorLink accountId={accountId} /> }} /> | ||
</div> | ||
); | ||
|
||
MoreFromAuthor.propTypes = { | ||
accountId: PropTypes.string.isRequired, | ||
}; |
20 changes: 20 additions & 0 deletions
20
app/javascript/flavours/glitch/features/explore/components/author_link.jsx
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,20 @@ | ||
import PropTypes from 'prop-types'; | ||
|
||
import { Avatar } from 'flavours/glitch/components/avatar'; | ||
import { Permalink } from 'flavours/glitch/components/permalink'; | ||
import { useAppSelector } from 'flavours/glitch/store'; | ||
|
||
export const AuthorLink = ({ accountId }) => { | ||
const account = useAppSelector(state => state.getIn(['accounts', accountId])); | ||
|
||
return ( | ||
<Permalink href={account.get('url')} to={`/@${account.get('acct')}`} className='story__details__shared__author-link'> | ||
<Avatar account={account} size={16} /> | ||
<bdi dangerouslySetInnerHTML={{ __html: account.get('display_name_html') }} /> | ||
</Permalink> | ||
); | ||
}; | ||
|
||
AuthorLink.propTypes = { | ||
accountId: PropTypes.string.isRequired, | ||
}; |
118 changes: 73 additions & 45 deletions
118
app/javascript/flavours/glitch/features/explore/components/story.jsx
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,61 +1,89 @@ | ||
import PropTypes from 'prop-types'; | ||
import { PureComponent } from 'react'; | ||
import { useState, useCallback } from 'react'; | ||
|
||
import { FormattedMessage } from 'react-intl'; | ||
|
||
import classNames from 'classnames'; | ||
|
||
|
||
import { Blurhash } from 'flavours/glitch/components/blurhash'; | ||
import { accountsCountRenderer } from 'flavours/glitch/components/hashtag'; | ||
import { RelativeTimestamp } from 'flavours/glitch/components/relative_timestamp'; | ||
import { ShortNumber } from 'flavours/glitch/components/short_number'; | ||
import { Skeleton } from 'flavours/glitch/components/skeleton'; | ||
|
||
export default class Story extends PureComponent { | ||
|
||
static propTypes = { | ||
url: PropTypes.string, | ||
title: PropTypes.string, | ||
lang: PropTypes.string, | ||
publisher: PropTypes.string, | ||
publishedAt: PropTypes.string, | ||
author: PropTypes.string, | ||
sharedTimes: PropTypes.number, | ||
thumbnail: PropTypes.string, | ||
thumbnailDescription: PropTypes.string, | ||
blurhash: PropTypes.string, | ||
expanded: PropTypes.bool, | ||
}; | ||
|
||
state = { | ||
thumbnailLoaded: false, | ||
}; | ||
|
||
handleImageLoad = () => this.setState({ thumbnailLoaded: true }); | ||
|
||
render () { | ||
const { expanded, url, title, lang, publisher, author, publishedAt, sharedTimes, thumbnail, thumbnailDescription, blurhash } = this.props; | ||
|
||
const { thumbnailLoaded } = this.state; | ||
|
||
return ( | ||
<a className={classNames('story', { expanded })} href={url} target='blank' rel='noopener'> | ||
<div className='story__details'> | ||
<div className='story__details__publisher'>{publisher ? <span lang={lang}>{publisher}</span> : <Skeleton width={50} />}{publishedAt && <> · <RelativeTimestamp timestamp={publishedAt} /></>}</div> | ||
<div className='story__details__title' lang={lang}>{title ? title : <Skeleton />}</div> | ||
<div className='story__details__shared'>{author && <><FormattedMessage id='link_preview.author' defaultMessage='By {name}' values={{ name: <strong>{author}</strong> }} /> · </>}{typeof sharedTimes === 'number' ? <ShortNumber value={sharedTimes} renderer={accountsCountRenderer} /> : <Skeleton width={100} />}</div> | ||
import { AuthorLink } from './author_link'; | ||
|
||
const sharesCountRenderer = (displayNumber, pluralReady) => ( | ||
<FormattedMessage | ||
id='link_preview.shares' | ||
defaultMessage='{count, plural, one {{counter} post} other {{counter} posts}}' | ||
values={{ | ||
count: pluralReady, | ||
counter: <strong>{displayNumber}</strong>, | ||
}} | ||
/> | ||
); | ||
|
||
export const Story = ({ | ||
url, | ||
title, | ||
lang, | ||
publisher, | ||
publishedAt, | ||
author, | ||
authorAccount, | ||
sharedTimes, | ||
thumbnail, | ||
thumbnailDescription, | ||
blurhash, | ||
expanded | ||
}) => { | ||
const [thumbnailLoaded, setThumbnailLoaded] = useState(false); | ||
|
||
const handleImageLoad = useCallback(() => { | ||
setThumbnailLoaded(true); | ||
}, [setThumbnailLoaded]); | ||
|
||
return ( | ||
<div className={classNames('story', { expanded })}> | ||
<div className='story__details'> | ||
<div className='story__details__publisher'> | ||
{publisher ? <span lang={lang}>{publisher}</span> : <Skeleton width={50} />}{publishedAt && <> · <RelativeTimestamp timestamp={publishedAt} /></>} | ||
</div> | ||
|
||
<div className='story__thumbnail'> | ||
{thumbnail ? ( | ||
<> | ||
<div className={classNames('story__thumbnail__preview', { 'story__thumbnail__preview--hidden': thumbnailLoaded })}><Blurhash hash={blurhash} /></div> | ||
<img src={thumbnail} onLoad={this.handleImageLoad} alt={thumbnailDescription} title={thumbnailDescription} lang={lang} /> | ||
</> | ||
) : <Skeleton />} | ||
<a className='story__details__title' lang={lang} href={url} target='blank' rel='noopener'> | ||
{title ? title : <Skeleton />} | ||
</a> | ||
|
||
<div className='story__details__shared'> | ||
{author ? <FormattedMessage id='link_preview.author' className='story__details__shared__author' defaultMessage='By {name}' values={{ name: authorAccount ? <AuthorLink accountId={authorAccount} /> : <strong>{author}</strong> }} /> : <span />} | ||
{typeof sharedTimes === 'number' ? <span className='story__details__shared__pill'><ShortNumber value={sharedTimes} renderer={sharesCountRenderer} /></span> : <Skeleton width='10ch' />} | ||
</div> | ||
</div> | ||
|
||
<a className='story__thumbnail' href={url} target='blank' rel='noopener'> | ||
{thumbnail ? ( | ||
<> | ||
<div className={classNames('story__thumbnail__preview', { 'story__thumbnail__preview--hidden': thumbnailLoaded })}><Blurhash hash={blurhash} /></div> | ||
<img src={thumbnail} onLoad={handleImageLoad} alt={thumbnailDescription} title={thumbnailDescription} lang={lang} /> | ||
</> | ||
) : <Skeleton />} | ||
</a> | ||
); | ||
} | ||
</div> | ||
); | ||
}; | ||
|
||
} | ||
Story.propTypes = { | ||
url: PropTypes.string, | ||
title: PropTypes.string, | ||
lang: PropTypes.string, | ||
publisher: PropTypes.string, | ||
publishedAt: PropTypes.string, | ||
author: PropTypes.string, | ||
authorAccount: PropTypes.string, | ||
sharedTimes: PropTypes.number, | ||
thumbnail: PropTypes.string, | ||
thumbnailDescription: PropTypes.string, | ||
blurhash: PropTypes.string, | ||
expanded: PropTypes.bool, | ||
}; |
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
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
Oops, something went wrong.