Support emojis in display name, bio
This commit is contained in:
parent
4f07fb1f0a
commit
489bd99803
@ -1,5 +1,7 @@
|
|||||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||||
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
||||||
|
import escapeTextContentForBrowser from 'react/lib/escapeTextContentForBrowser';
|
||||||
|
import emojify from '../emoji';
|
||||||
|
|
||||||
const DisplayName = React.createClass({
|
const DisplayName = React.createClass({
|
||||||
|
|
||||||
@ -10,15 +12,12 @@ const DisplayName = React.createClass({
|
|||||||
mixins: [PureRenderMixin],
|
mixins: [PureRenderMixin],
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
let displayName = this.props.account.get('display_name');
|
const displayName = this.props.account.get('display_name').length === 0 ? this.props.account.get('username') : this.props.account.get('display_name');
|
||||||
|
const displayNameHTML = { __html: emojify(escapeTextContentForBrowser(displayName)) };
|
||||||
if (displayName.length === 0) {
|
|
||||||
displayName = this.props.account.get('username');
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span style={{ display: 'block', maxWidth: '100%', overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis' }}>
|
<span style={{ display: 'block', maxWidth: '100%', overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis' }} className='display-name'>
|
||||||
<strong style={{ fontWeight: 'bold' }}>{displayName}</strong> <span style={{ fontSize: '14px' }}>@{this.props.account.get('acct')}</span>
|
<strong style={{ fontWeight: '500' }} dangerouslySetInnerHTML={displayNameHTML} /> <span style={{ fontSize: '14px' }}>@{this.props.account.get('acct')}</span>
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||||
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
||||||
import emojione from 'emojione';
|
import emojify from '../emoji';
|
||||||
|
|
||||||
emojione.imageType = 'png';
|
|
||||||
emojione.sprites = false;
|
|
||||||
emojione.imagePathPNG = '/emoji/';
|
|
||||||
|
|
||||||
const StatusContent = React.createClass({
|
const StatusContent = React.createClass({
|
||||||
|
|
||||||
@ -61,7 +57,7 @@ const StatusContent = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const content = { __html: emojione.unicodeToImage(this.props.status.get('content')) };
|
const content = { __html: emojify(this.props.status.get('content')) };
|
||||||
return <div className='status__content' style={{ cursor: 'pointer' }} dangerouslySetInnerHTML={content} onClick={this.props.onClick} />;
|
return <div className='status__content' style={{ cursor: 'pointer' }} dangerouslySetInnerHTML={content} onClick={this.props.onClick} />;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
9
app/assets/javascripts/components/emoji.jsx
Normal file
9
app/assets/javascripts/components/emoji.jsx
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import emojione from 'emojione';
|
||||||
|
|
||||||
|
emojione.imageType = 'png';
|
||||||
|
emojione.sprites = false;
|
||||||
|
emojione.imagePathPNG = '/emoji/';
|
||||||
|
|
||||||
|
export default function emojify(text) {
|
||||||
|
return emojione.unicodeToImage(text);
|
||||||
|
};
|
@ -1,5 +1,7 @@
|
|||||||
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
||||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||||
|
import emojify from '../../../emoji';
|
||||||
|
import escapeTextContentForBrowser from 'react/lib/escapeTextContentForBrowser';
|
||||||
|
|
||||||
const Header = React.createClass({
|
const Header = React.createClass({
|
||||||
|
|
||||||
@ -14,7 +16,7 @@ const Header = React.createClass({
|
|||||||
const { account, me } = this.props;
|
const { account, me } = this.props;
|
||||||
|
|
||||||
let displayName = account.get('display_name');
|
let displayName = account.get('display_name');
|
||||||
let info = '';
|
let info = '';
|
||||||
|
|
||||||
if (displayName.length === 0) {
|
if (displayName.length === 0) {
|
||||||
displayName = account.get('username');
|
displayName = account.get('username');
|
||||||
@ -24,7 +26,8 @@ const Header = React.createClass({
|
|||||||
info = <span style={{ position: 'absolute', top: '10px', right: '10px', opacity: '0.7', display: 'inline-block', verticalAlign: 'top', background: 'rgba(0, 0, 0, 0.4)', color: '#fff', textTransform: 'uppercase', fontSize: '11px', fontWeight: '500', padding: '4px', borderRadius: '4px' }}>Follows you</span>
|
info = <span style={{ position: 'absolute', top: '10px', right: '10px', opacity: '0.7', display: 'inline-block', verticalAlign: 'top', background: 'rgba(0, 0, 0, 0.4)', color: '#fff', textTransform: 'uppercase', fontSize: '11px', fontWeight: '500', padding: '4px', borderRadius: '4px' }}>Follows you</span>
|
||||||
}
|
}
|
||||||
|
|
||||||
const content = { __html: account.get('note') };
|
const content = { __html: emojify(account.get('note')) };
|
||||||
|
const displayNameHTML = { __html: emojify(escapeTextContentForBrowser(displayName)) };
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ flex: '0 0 auto', background: '#2f3441', textAlign: 'center', backgroundImage: `url(${account.get('header')})`, backgroundSize: 'cover', position: 'relative' }}>
|
<div style={{ flex: '0 0 auto', background: '#2f3441', textAlign: 'center', backgroundImage: `url(${account.get('header')})`, backgroundSize: 'cover', position: 'relative' }}>
|
||||||
@ -34,7 +37,7 @@ const Header = React.createClass({
|
|||||||
<img src={account.get('avatar')} alt='' style={{ display: 'block', width: '90px', height: '90px', borderRadius: '90px' }} />
|
<img src={account.get('avatar')} alt='' style={{ display: 'block', width: '90px', height: '90px', borderRadius: '90px' }} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<span style={{ display: 'inline-block', color: '#fff', fontSize: '20px', lineHeight: '27px', fontWeight: '500' }}>{displayName}</span>
|
<span style={{ display: 'inline-block', color: '#fff', fontSize: '20px', lineHeight: '27px', fontWeight: '500' }} className='account__header__display-name' dangerouslySetInnerHTML={displayNameHTML} />
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<span style={{ fontSize: '14px', fontWeight: '400', display: 'block', color: '#2b90d9', marginBottom: '10px' }}>@{account.get('acct')}</span>
|
<span style={{ fontSize: '14px', fontWeight: '400', display: 'block', color: '#2b90d9', marginBottom: '10px' }}>@{account.get('acct')}</span>
|
||||||
|
@ -76,6 +76,8 @@
|
|||||||
font-size: inherit;
|
font-size: inherit;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
margin: -.2ex .15em .2ex;
|
margin: -.2ex .15em .2ex;
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
|
||||||
img {
|
img {
|
||||||
width: auto;
|
width: auto;
|
||||||
@ -166,6 +168,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.account__header__display-name {
|
||||||
|
.emojione {
|
||||||
|
width: 25px;
|
||||||
|
height: 25px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.status__display-name, .status__relative-time, .detailed-status__display-name, .detailed-status__datetime, .account__display-name {
|
.status__display-name, .status__relative-time, .detailed-status__display-name, .detailed-status__datetime, .account__display-name {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user