Fixes: Save profile picture automatically after upload

Fix jank when cropping large photos
This commit is contained in:
Tom Moor
2018-11-17 18:25:10 -08:00
parent d3834d2dc5
commit d74b99635e
3 changed files with 15 additions and 3 deletions

View File

@ -52,8 +52,13 @@ class Profile extends React.Component<Props> {
this.name = ev.target.value; this.name = ev.target.value;
}; };
handleAvatarUpload = (avatarUrl: string) => { handleAvatarUpload = async (avatarUrl: string) => {
this.avatarUrl = avatarUrl; this.avatarUrl = avatarUrl;
await this.props.auth.updateUser({
avatarUrl: this.avatarUrl,
});
this.props.ui.showToast('Profile picture updated', 'success');
}; };
handleAvatarError = (error: ?string) => { handleAvatarError = (error: ?string) => {

View File

@ -38,8 +38,15 @@ class DropToImport extends React.Component<Props> {
this.file = files[0]; this.file = files[0];
}; };
handleCrop = async () => { handleCrop = () => {
this.isUploading = true; this.isUploading = true;
// allow the UI to update before converting the canvas to a Blob
// for large images this can cause the page rendering to hang.
setImmediate(this.uploadImage);
};
uploadImage = async () => {
const canvas = this.avatarEditorRef.getImage(); const canvas = this.avatarEditorRef.getImage();
const imageBlob = dataUrlToBlob(canvas.toDataURL()); const imageBlob = dataUrlToBlob(canvas.toDataURL());
try { try {

View File

@ -62,7 +62,7 @@ class AuthStore {
}; };
@action @action
updateUser = async (params: { name: string, avatarUrl: ?string }) => { updateUser = async (params: { name?: string, avatarUrl: ?string }) => {
this.isSaving = true; this.isSaving = true;
try { try {