fixed page freeze while uploading bug

This commit is contained in:
Martina 2020-12-11 19:57:54 -08:00
parent 1256ea109b
commit 31642ede5a
2 changed files with 5 additions and 4 deletions

View File

@ -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}`]: {

View File

@ -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;