moving string size check to helper lib
This commit is contained in:
parent
327cb883ee
commit
2d48743f37
@ -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() {
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user