PLT-7397 Added loadImage function instead of Image.prototype.load (#7184)
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
26ec8ffc3e
Коммит
6df51f8617
@@ -48,14 +48,16 @@ export default class FileAttachment extends React.Component {
|
||||
if (fileType === 'image') {
|
||||
const thumbnailUrl = getFileThumbnailUrl(fileInfo.id);
|
||||
|
||||
const img = new Image();
|
||||
img.onload = () => {
|
||||
this.setState({loaded: true});
|
||||
};
|
||||
img.load(thumbnailUrl);
|
||||
Utils.loadImage(thumbnailUrl, this.handleImageLoaded);
|
||||
}
|
||||
}
|
||||
|
||||
handleImageLoaded = () => {
|
||||
this.setState({
|
||||
loaded: true
|
||||
});
|
||||
}
|
||||
|
||||
onAttachmentClick(e) {
|
||||
e.preventDefault();
|
||||
this.props.handleImageClick(this.props.index);
|
||||
|
||||
@@ -134,28 +134,39 @@ export default class ViewImageModal extends React.Component {
|
||||
previewUrl = getFileUrl(fileInfo.id);
|
||||
}
|
||||
|
||||
const img = new Image();
|
||||
img.load(
|
||||
Utils.loadImage(
|
||||
previewUrl,
|
||||
() => {
|
||||
const progress = this.state.progress;
|
||||
progress[index] = img.completedPercentage;
|
||||
this.setState({progress});
|
||||
}
|
||||
() => this.handleImageLoaded(index),
|
||||
(completedPercentage) => this.handleImageProgress(index, completedPercentage)
|
||||
);
|
||||
img.onload = () => {
|
||||
const loaded = this.state.loaded;
|
||||
loaded[index] = true;
|
||||
this.setState({loaded});
|
||||
};
|
||||
} else {
|
||||
// there's nothing to load for non-image files
|
||||
var loaded = this.state.loaded;
|
||||
loaded[index] = true;
|
||||
this.setState({loaded});
|
||||
this.handleImageLoaded(index);
|
||||
}
|
||||
}
|
||||
|
||||
handleImageLoaded = (index) => {
|
||||
this.setState((prevState) => {
|
||||
return {
|
||||
loaded: {
|
||||
...prevState.loaded,
|
||||
[index]: true
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
handleImageProgress = (index, completedPercentage) => {
|
||||
this.setState((prevState) => {
|
||||
return {
|
||||
progress: {
|
||||
...prevState.progress,
|
||||
[index]: completedPercentage
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
handleGetPublicLink() {
|
||||
this.props.onModalDismissed();
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user