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() {
|
renderImageName() {
|
||||||
if (!this.state.currentImage) return null;
|
if (!this.state.currentImage) return null;
|
||||||
const { uri } = this.state.currentImage;
|
return truncateMiddle(this.state.currentImage.uri, MAX_DISPLAY_LENGTH);
|
||||||
if (uri.length <= MAX_DISPLAY_LENGTH) {
|
|
||||||
return uri;
|
|
||||||
}
|
|
||||||
return truncateMiddle(uri, MAX_DISPLAY_LENGTH);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
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);
|
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