Skip to content

Commit

Permalink
Merge branch 'master' into remove_post_hide_rep_protection
Browse files Browse the repository at this point in the history
  • Loading branch information
sneak authored Oct 24, 2017
2 parents 0c2d680 + 16cfd8e commit ef8746e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/app/components/elements/AuthorDropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const AuthorDropdown = (props) => {
<div className = "Author__container">
<div className="Author__dropdown">
<Link to={'/@' + props.author}>
<Userpic account={props.author} width="75" height="75" />
<Userpic account={props.author} />
</Link>
<Link to={'/@' + props.author} className="Author__name">
{props.name}
Expand Down
6 changes: 4 additions & 2 deletions src/app/components/elements/AuthorDropdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
min-height: 108px;

.Userpic {
margin-right: 1rem;
float: left;
margin-right: 1rem;
float: left;
width:75px;
height:75px;
}

.Author__name {
Expand Down
36 changes: 14 additions & 22 deletions src/app/components/elements/Userpic.jsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,43 @@
import React, {Component, PropTypes} from 'react';
import {connect} from 'react-redux';
import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import shouldComponentUpdate from 'app/utils/shouldComponentUpdate';
import proxifyImageUrl from 'app/utils/ProxifyUrl';
import { imageProxy } from 'app/utils/ProxifyUrl';

class Userpic extends Component {
static propTypes = {
account: PropTypes.string
}

shouldComponentUpdate = shouldComponentUpdate(this, 'Userpic')

render() {
const {json_metadata, width, height} = this.props
const {account, json_metadata} = this.props
const hideIfDefault = this.props.hideIfDefault || false

let url = null;

// try to extract image url from users metaData
try {
const md = JSON.parse(json_metadata);
if(/^(https?:)\/\//.test(md.profile.profile_image)) {
const size = (width && width > 48)? '320x320' : '120x120';
url = proxifyImageUrl(md.profile.profile_image, size);
}
} catch (e) {}
if(!url) {
if(hideIfDefault) {
if(!/^(https?:)\/\//.test(md.profile.profile_image) && hideIfDefault) {
return null;
}
url = require('assets/images/user.png');
} catch (e) {
/* eslint-disable-line no-empty */
}

const style = {backgroundImage: 'url(' + url + ')',
width: (width || 48) + 'px',
height: (height || 48) + 'px'}
const style = {backgroundImage: 'url(' + imageProxy() + `/u/${account}/avatar)` };

return (<div className="Userpic" style={style} />)
}
}

Userpic.propTypes = {
account: PropTypes.string.isRequired
}

export default connect(
(state, ownProps) => {
const {account, width, height, hideIfDefault} = ownProps
const {account, hideIfDefault} = ownProps
return {
account,
json_metadata: state.global.getIn(['accounts', account, 'json_metadata']),
width,
height,
hideIfDefault,
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/app/utils/ProxifyUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const rProxyDomain = /^http(s)?:\/\/steemit(dev|stage)?images.com\//g;
const rProxyDomainsDimensions = /http(s)?:\/\/steemit(dev|stage)?images.com\/([0-9]+x[0-9]+)\//g;
const NATURAL_SIZE = '0x0/';

export const imageProxy = () => $STM_Config.img_proxy_prefix;

/**
* Strips all proxy domains from the beginning of the url. Adds the global proxy if dimension is specified
* @param {string} url
Expand Down

0 comments on commit ef8746e

Please sign in to comment.