mirror of
https://github.com/filecoin-project/slate.git
synced 2024-11-30 02:12:38 +03:00
fixed page freeze while uploading bug
This commit is contained in:
parent
1256ea109b
commit
31642ede5a
@ -20,10 +20,14 @@ const loadImage = async (src) =>
|
||||
});
|
||||
|
||||
const getImageData = (image) => {
|
||||
let ratio = Math.min(100 / image.height, 100 / image.width);
|
||||
image.height = image.height * ratio;
|
||||
image.width = image.width * ratio;
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = image.width;
|
||||
canvas.height = image.height;
|
||||
const context = canvas.getContext("2d");
|
||||
context.scale(ratio, ratio);
|
||||
context.drawImage(image, 0, 0);
|
||||
return context.getImageData(0, 0, image.width, image.height);
|
||||
};
|
||||
@ -150,7 +154,7 @@ export const upload = async ({ file, context, bucketName, routes, excludeFromLib
|
||||
|
||||
if (!res || res.error || !res.data) {
|
||||
if (context) {
|
||||
context.setState({
|
||||
await context.setState({
|
||||
fileLoading: {
|
||||
...context.state.fileLoading,
|
||||
[`${file.lastModified}-${file.name}`]: {
|
||||
|
@ -61,8 +61,6 @@ const STYLES_BLUR_CONTAINER = css`
|
||||
`;
|
||||
|
||||
export default class SlateMediaObjectPreview extends React.Component {
|
||||
count = 0;
|
||||
|
||||
static defaultProps = {
|
||||
charCap: 30,
|
||||
};
|
||||
@ -87,7 +85,6 @@ export default class SlateMediaObjectPreview extends React.Component {
|
||||
};
|
||||
|
||||
loadImage = async (url) => {
|
||||
this.count += 1;
|
||||
const img = new Image();
|
||||
img.onload = () => this.setState({ showImage: true });
|
||||
img.src = url;
|
||||
|
Loading…
Reference in New Issue
Block a user