I attach a file with ember-active-storage and the image is not displayed after updating the model. I have to refresh the page to see it. I tried to call this.transitionToRoute('same_page_route')
in a controller but without success.
Actually, I’m keeping the current shop (selected by a User) instance in a currentShop
service, that makes it available throughout all the pages related to the current shop.
So, when updating the shop information, I just peek it from the service in the corresponding controller by id and update it:
#controllers/information.js
actions: {
addShopPhoto(blob) {
this.get('currentShop.shop').set('photo', blob.get('signedId'));
},
async save() {
this.errors.length = 0;
let shop = this.store.peekRecord('shop', this.get('currentShop.shop.id'));
shop.set('modifiedBy', this.get('currentUser.user').get('username'));
shop.set('status', this.get('status'));
if (shop.get('photo.signed_id')) {
shop.set('photo', shop.get('photo.signed_id'));
}
try {
if (shop.validations.isValid) {
await shop.save();
await this.get('flashMessages').success(this.get('intl').t('flash.shop.updated'));
await this.transitionToRoute('information');
}
} catch(response) {
let errorMessage = extractServerError(response.errors);
this.errors.pushObject(errorMessage);
}
...
The addShopPhoto
action is triggered from the template component:
# templates/information.hbs
{{file-upload
onFileUploaded=(action "addShopPhoto")
class="form-control-file"
}}
The photo is atached to the shop but is nit displayed, I have to refresh the same page to see it.
By the way, should I really keep await this.transitionToRoute('information');
if I stay on the same route/page ?
Redirecting to another route changes nothing. I think the reason is that the actual information
route has no model hook defined because I don’t need it, - all the information displayed in the information.hbs
template is coming from currentShop.shop
that I keep in currentShop
service.
Any ideas? Thank you.