moving string size check to helper lib

This commit is contained in:
Cássio Zen 2016-06-07 21:33:12 -03:00
parent 327cb883ee
commit 2d48743f37
2 changed files with 5 additions and 6 deletions

View File

@ -72,11 +72,7 @@ export default class ImageControl extends React.Component {
renderImageName() {
if (!this.state.currentImage) return null;
const { uri } = this.state.currentImage;
if (uri.length <= MAX_DISPLAY_LENGTH) {
return uri;
}
return truncateMiddle(uri, MAX_DISPLAY_LENGTH);
return truncateMiddle(this.state.currentImage.uri, MAX_DISPLAY_LENGTH);
}
render() {

View File

@ -1,3 +1,6 @@
export function truncateMiddle(string, size) {
export function truncateMiddle(string = '', size) {
if (string.length <= size) {
return string;
}
return string.substring(0, size / 2) + '\u2026' + string.substring(string.length - size / 2 + 1, string.length);
}