mirror of
https://github.com/datahub-project/datahub.git
synced 2025-10-30 18:26:58 +00:00
replaces avatar-image with e-concurrency task
This commit is contained in:
parent
cd94e5af6f
commit
0c8edbca7e
@ -2,8 +2,10 @@ import Component from '@ember/component';
|
|||||||
import ComputedProperty from '@ember/object/computed';
|
import ComputedProperty from '@ember/object/computed';
|
||||||
import { IAvatar } from 'wherehows-web/typings/app/avatars';
|
import { IAvatar } from 'wherehows-web/typings/app/avatars';
|
||||||
import { alias } from '@ember-decorators/object/computed';
|
import { alias } from '@ember-decorators/object/computed';
|
||||||
import { set } from '@ember/object';
|
import { set, get } from '@ember/object';
|
||||||
import { classNames, tagName, attribute } from '@ember-decorators/component';
|
import { classNames, tagName, attribute } from '@ember-decorators/component';
|
||||||
|
import { task } from 'ember-concurrency';
|
||||||
|
import { run } from '@ember/runloop';
|
||||||
|
|
||||||
@tagName('img')
|
@tagName('img')
|
||||||
@classNames('avatar')
|
@classNames('avatar')
|
||||||
@ -37,16 +39,15 @@ export default class AvatarImage extends Component {
|
|||||||
@attribute
|
@attribute
|
||||||
onerror = (): void => {
|
onerror = (): void => {
|
||||||
// Change avatar if an error occurs when the image is loaded
|
// Change avatar if an error occurs when the image is loaded
|
||||||
this.onImageFallback();
|
run(() => get(this, 'onImageFallback').perform());
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the fallback image for an avatar
|
* Task to set the fallback image for an avatar
|
||||||
|
* @type Task<void, (a?: {}) => TaskInstance<void>>
|
||||||
* @memberof AvatarImage
|
* @memberof AvatarImage
|
||||||
*/
|
*/
|
||||||
onImageFallback(): void {
|
onImageFallback = task(function*(this: AvatarImage): IterableIterator<void> {
|
||||||
if (!this.isDestroyed) {
|
set(this, 'src', this.avatar.imageUrlFallback);
|
||||||
set(this, 'src', this.avatar.imageUrlFallback);
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user