1
0
mirror of https://github.com/flarum/core.git synced 2025-08-04 15:37:51 +02:00

forum: fix avatar editor not uploading

This commit is contained in:
David Sevilla Martin
2020-03-20 09:27:29 -04:00
parent cfc0000df0
commit f9cda85937

View File

@@ -62,10 +62,8 @@ export default class AvatarEditor extends Component<AvatarEditorProps> {
/** /**
* Get the items in the edit avatar dropdown menu. * Get the items in the edit avatar dropdown menu.
*
* @return {ItemList}
*/ */
controlItems() { controlItems(): ItemList {
const items = new ItemList(); const items = new ItemList();
items.add( items.add(
@@ -91,10 +89,8 @@ export default class AvatarEditor extends Component<AvatarEditorProps> {
/** /**
* Enable dragover style * Enable dragover style
*
* @param {Event} e
*/ */
enableDragover(e) { enableDragover(e: Event) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
this.isDraggedOver = true; this.isDraggedOver = true;
@@ -102,10 +98,8 @@ export default class AvatarEditor extends Component<AvatarEditorProps> {
/** /**
* Disable dragover style * Disable dragover style
*
* @param {Event} e
*/ */
disableDragover(e) { disableDragover(e: Event) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
this.isDraggedOver = false; this.isDraggedOver = false;
@@ -116,7 +110,7 @@ export default class AvatarEditor extends Component<AvatarEditorProps> {
* *
* @param {Event} e * @param {Event} e
*/ */
dropUpload(e) { dropUpload(e: Event) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
this.isDraggedOver = false; this.isDraggedOver = false;
@@ -128,10 +122,8 @@ export default class AvatarEditor extends Component<AvatarEditorProps> {
* controls dropdown, because only one option would be viable: uploading. * controls dropdown, because only one option would be viable: uploading.
* Thus, when the avatar editor's dropdown toggle button is clicked, we prompt * Thus, when the avatar editor's dropdown toggle button is clicked, we prompt
* the user to upload an avatar immediately. * the user to upload an avatar immediately.
*
* @param {Event} e
*/ */
quickUpload(e) { quickUpload(e: Event) {
if (!this.props.user.avatarUrl()) { if (!this.props.user.avatarUrl()) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
@@ -161,15 +153,13 @@ export default class AvatarEditor extends Component<AvatarEditorProps> {
/** /**
* Upload avatar * Upload avatar
*
* @param {File} file
*/ */
upload(file) { upload(file: File) {
if (this.loading) return; if (this.loading) return;
const user = this.props.user; const user = this.props.user;
const body = new FormData(); const body = new FormData();
data.append('avatar', file); body.append('avatar', file);
this.loading = true; this.loading = true;
m.redraw(); m.redraw();
@@ -200,11 +190,8 @@ export default class AvatarEditor extends Component<AvatarEditorProps> {
/** /**
* After a successful upload/removal, push the updated user data into the * After a successful upload/removal, push the updated user data into the
* store, and force a recomputation of the user's avatar color. * store, and force a recomputation of the user's avatar color.
*
* @param {Object} response
* @protected
*/ */
success(response) { protected success(response: any) {
app.store.pushPayload(response); app.store.pushPayload(response);
delete this.props.user.avatarColor; delete this.props.user.avatarColor;
@@ -214,11 +201,8 @@ export default class AvatarEditor extends Component<AvatarEditorProps> {
/** /**
* If avatar upload/removal fails, stop loading. * If avatar upload/removal fails, stop loading.
*
* @param {Object} response
* @protected
*/ */
failure(response) { protected failure(response: any) {
this.loading = false; this.loading = false;
m.redraw(); m.redraw();
} }