1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15- import { Component , Input , OnInit , Type , ViewChild } from '@angular/core' ;
15+ import { Component , Input , OnChanges , SimpleChanges , Type , ViewChild } from '@angular/core' ;
1616import { CoreDynamicComponent } from '@components/dynamic-component/dynamic-component' ;
1717import {
1818 AddonModAssignAssign ,
@@ -34,7 +34,7 @@ import { toBoolean } from '@/core/transforms/boolean';
3434 selector : 'addon-mod-assign-submission-plugin' ,
3535 templateUrl : 'addon-mod-assign-submission-plugin.html' ,
3636} )
37- export class AddonModAssignSubmissionPluginComponent implements OnInit {
37+ export class AddonModAssignSubmissionPluginComponent implements OnChanges {
3838
3939 @ViewChild ( CoreDynamicComponent ) dynamicComponent ! : CoreDynamicComponent < AddonModAssignSubmissionPluginBaseComponent > ;
4040
@@ -57,7 +57,7 @@ export class AddonModAssignSubmissionPluginComponent implements OnInit {
5757 /**
5858 * @inheritdoc
5959 */
60- async ngOnInit ( ) : Promise < void > {
60+ async ngOnChanges ( changes : SimpleChanges ) : Promise < void > {
6161 if ( ! this . plugin ) {
6262 this . pluginLoaded = true ;
6363
@@ -73,8 +73,19 @@ export class AddonModAssignSubmissionPluginComponent implements OnInit {
7373 }
7474 this . plugin . name = name ;
7575
76- // Check if the plugin has defined its own component to render itself.
77- this . pluginComponent = await AddonModAssignSubmissionDelegate . getComponentForPlugin ( this . plugin , this . edit ) ;
76+ if ( changes . plugin || changes . edit ) {
77+ // Check if the plugin has defined its own component to render itself.
78+ this . pluginComponent = await AddonModAssignSubmissionDelegate . getComponentForPlugin ( this . plugin , this . edit ) ;
79+
80+ this . pluginLoaded = ! this . pluginComponent ;
81+
82+ if ( ! this . pluginComponent ) {
83+ // Data to render the plugin.
84+ this . text = AddonModAssign . getSubmissionPluginText ( this . plugin ) ;
85+ this . files = AddonModAssign . getSubmissionPluginAttachments ( this . plugin ) ;
86+ this . notSupported = AddonModAssignSubmissionDelegate . isPluginSupported ( this . plugin . type ) ;
87+ }
88+ }
7889
7990 if ( this . pluginComponent ) {
8091 // Prepare the data to pass to the component.
@@ -86,12 +97,6 @@ export class AddonModAssignSubmissionPluginComponent implements OnInit {
8697 edit : this . edit ,
8798 allowOffline : this . allowOffline ,
8899 } ;
89- } else {
90- // Data to render the plugin.
91- this . text = AddonModAssign . getSubmissionPluginText ( this . plugin ) ;
92- this . files = AddonModAssign . getSubmissionPluginAttachments ( this . plugin ) ;
93- this . notSupported = AddonModAssignSubmissionDelegate . isPluginSupported ( this . plugin . type ) ;
94- this . pluginLoaded = true ;
95100 }
96101 }
97102
0 commit comments