Skip to content

Commit 93b8ce2

Browse files
committed
MOBILE-4362 mycourses: Fix category disappear after PTR
1 parent b9e9dad commit 93b8ce2

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

src/addons/block/myoverview/components/myoverview/myoverview.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
176176
* @inheritdoc
177177
*/
178178
ngOnChanges(changes: SimpleChanges): void {
179+
super.ngOnChanges(changes);
180+
179181
if (this.loaded && changes.block) {
180182
// Block was re-fetched, load content.
181183
this.reloadContent();

src/core/features/block/classes/base-block-component.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { OnInit, Input, Component, Optional, Inject } from '@angular/core';
15+
import { OnInit, Input, Component, Optional, Inject, OnChanges, SimpleChanges } from '@angular/core';
1616
import { CoreLogger } from '@singletons/logger';
1717
import { CoreDomUtils } from '@services/utils/dom';
1818
import { CoreUtils } from '@services/utils/utils';
@@ -30,7 +30,7 @@ import { CorePromisedValue } from '@classes/promised-value';
3030
@Component({
3131
template: '',
3232
})
33-
export abstract class CoreBlockBaseComponent implements OnInit, ICoreBlockComponent, AsyncDirective {
33+
export abstract class CoreBlockBaseComponent implements OnInit, OnChanges, ICoreBlockComponent, AsyncDirective {
3434

3535
@Input() title!: string; // The block title.
3636
@Input() block!: CoreCourseBlock; // The block to render.
@@ -54,15 +54,31 @@ export abstract class CoreBlockBaseComponent implements OnInit, ICoreBlockCompon
5454
* @inheritdoc
5555
*/
5656
async ngOnInit(): Promise<void> {
57-
if (this.block.configs && this.block.configs.length > 0) {
58-
this.block.configs.forEach((config) => {
59-
config.value = CoreTextUtils.parseJSON(config.value);
60-
});
57+
await this.loadContent();
58+
}
6159

62-
this.block.configsRecord = CoreUtils.arrayToObject(this.block.configs, 'name');
60+
/**
61+
* @inheritdoc
62+
*/
63+
ngOnChanges(changes: SimpleChanges): void {
64+
if (changes.block) {
65+
this.parseConfigs();
6366
}
67+
}
6468

65-
await this.loadContent();
69+
/**
70+
* Parse configs if needed.
71+
*/
72+
protected parseConfigs(): void {
73+
if (!this.block.configs?.length || this.block.configsRecord) {
74+
return;
75+
}
76+
77+
this.block.configs.forEach((config) => {
78+
config.value = CoreTextUtils.parseJSON(config.value);
79+
});
80+
81+
this.block.configsRecord = CoreUtils.arrayToObject(this.block.configs, 'name');
6682
}
6783

6884
/**

0 commit comments

Comments
 (0)