diff --git a/src/addon/mod/forum/components/post/addon-mod-forum-post.html b/src/addon/mod/forum/components/post/addon-mod-forum-post.html index 253e7208a..19a55682d 100644 --- a/src/addon/mod/forum/components/post/addon-mod-forum-post.html +++ b/src/addon/mod/forum/components/post/addon-mod-forum-post.html @@ -23,7 +23,7 @@ </ng-container> </div> </ion-card-content> -<core-rating-rate *ngIf="forum && ratingInfo" [ratingInfo]="ratingInfo" contextLevel="module" [instanceId]="componentId" [itemId]="post.id" [itemSetId]="discussionId" [courseId]="courseId" [aggregateMethod]="forum.assessed" [scaleId]="forum.scale" [userId]="post.userid"></core-rating-rate> +<core-rating-rate *ngIf="forum && ratingInfo" [ratingInfo]="ratingInfo" contextLevel="module" [instanceId]="componentId" [itemId]="post.id" [itemSetId]="discussionId" [courseId]="courseId" [aggregateMethod]="forum.assessed" [scaleId]="forum.scale" [userId]="post.userid" (onUpdate)="ratingUpdated()"></core-rating-rate> <core-rating-aggregate *ngIf="forum && ratingInfo" [ratingInfo]="ratingInfo" contextLevel="module" [instanceId]="componentId" [itemId]="post.id" [courseId]="courseId" [aggregateMethod]="forum.assessed" [scaleId]="forum.scale"></core-rating-aggregate> <ion-item no-padding text-end *ngIf="post.id && post.canreply" class="addon-forum-reply-button"> <button ion-button icon-left clear small (click)="showReply()" [attr.aria-controls]="'addon-forum-reply-edit-form-' + uniqueId" [attr.aria-expanded]="replyData.replyingTo === post.id"> diff --git a/src/addon/mod/forum/components/post/post.ts b/src/addon/mod/forum/components/post/post.ts index e1d542e3e..d245ddff0 100644 --- a/src/addon/mod/forum/components/post/post.ts +++ b/src/addon/mod/forum/components/post/post.ts @@ -307,6 +307,13 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy { }); } + /** + * Function called when rating is updated online. + */ + ratingUpdated(): void { + this.forumProvider.invalidateDiscussionPosts(this.discussionId); + } + /** * Component being destroyed. */ diff --git a/src/core/rating/components/rate/rate.ts b/src/core/rating/components/rate/rate.ts index d2407543f..1a214bfc0 100644 --- a/src/core/rating/components/rate/rate.ts +++ b/src/core/rating/components/rate/rate.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Component, Input, OnChanges, SimpleChange } from '@angular/core'; +import { Component, EventEmitter, Input, OnChanges, Output, SimpleChange } from '@angular/core'; import { TranslateService } from '@ngx-translate/core'; import { CoreRatingProvider, CoreRatingInfo, CoreRatingInfoItem, CoreRatingScale } from '@core/rating/providers/rating'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; @@ -35,13 +35,16 @@ export class CoreRatingRateComponent implements OnChanges { @Input() aggregateMethod: number; @Input() scaleId: number; @Input() userId: number; + @Output() onUpdate: EventEmitter<void>; // Event emitted when the rating is updated online. item: CoreRatingInfoItem; scale: CoreRatingScale; rating: number; constructor(private domUtils: CoreDomUtilsProvider, private translate: TranslateService, - private ratingProvider: CoreRatingProvider, private ratingOffline: CoreRatingOfflineProvider) {} + private ratingProvider: CoreRatingProvider, private ratingOffline: CoreRatingOfflineProvider) { + this.onUpdate = new EventEmitter<void>(); + } /** * Detect changes on input properties. @@ -96,6 +99,8 @@ export class CoreRatingRateComponent implements OnChanges { .then((response) => { if (response == null) { this.domUtils.showToast('core.datastoredoffline', true, 3000); + } else { + this.onUpdate.emit(); } }).catch((error) => { this.domUtils.showErrorModal(error);