MOBILE-4362 mycourses: Fix category disappear after PTR

main
Dani Palou 2023-10-31 11:24:31 +01:00
parent b9e9dade0b
commit 93b8ce274c
2 changed files with 26 additions and 8 deletions

View File

@ -176,6 +176,8 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
* @inheritdoc
*/
ngOnChanges(changes: SimpleChanges): void {
super.ngOnChanges(changes);
if (this.loaded && changes.block) {
// Block was re-fetched, load content.
this.reloadContent();

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { OnInit, Input, Component, Optional, Inject } from '@angular/core';
import { OnInit, Input, Component, Optional, Inject, OnChanges, SimpleChanges } from '@angular/core';
import { CoreLogger } from '@singletons/logger';
import { CoreDomUtils } from '@services/utils/dom';
import { CoreUtils } from '@services/utils/utils';
@ -30,7 +30,7 @@ import { CorePromisedValue } from '@classes/promised-value';
@Component({
template: '',
})
export abstract class CoreBlockBaseComponent implements OnInit, ICoreBlockComponent, AsyncDirective {
export abstract class CoreBlockBaseComponent implements OnInit, OnChanges, ICoreBlockComponent, AsyncDirective {
@Input() title!: string; // The block title.
@Input() block!: CoreCourseBlock; // The block to render.
@ -54,15 +54,31 @@ export abstract class CoreBlockBaseComponent implements OnInit, ICoreBlockCompon
* @inheritdoc
*/
async ngOnInit(): Promise<void> {
if (this.block.configs && this.block.configs.length > 0) {
this.block.configs.forEach((config) => {
config.value = CoreTextUtils.parseJSON(config.value);
});
await this.loadContent();
}
this.block.configsRecord = CoreUtils.arrayToObject(this.block.configs, 'name');
/**
* @inheritdoc
*/
ngOnChanges(changes: SimpleChanges): void {
if (changes.block) {
this.parseConfigs();
}
}
/**
* Parse configs if needed.
*/
protected parseConfigs(): void {
if (!this.block.configs?.length || this.block.configsRecord) {
return;
}
await this.loadContent();
this.block.configs.forEach((config) => {
config.value = CoreTextUtils.parseJSON(config.value);
});
this.block.configsRecord = CoreUtils.arrayToObject(this.block.configs, 'name');
}
/**