Skip to content

Commit b460a24

Browse files
committed
removed subcription in favour of input
1 parent 8de87a8 commit b460a24

5 files changed

Lines changed: 38 additions & 73 deletions

File tree

web/src/app/components/shared/data-visibility-control/data-visibility-control.component.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { Component } from '@angular/core';
17+
import { Component, effect, input } from '@angular/core';
1818
import { MatSlideToggleChange } from '@angular/material/slide-toggle';
19-
import { Subscription } from 'rxjs';
2019

2120
import { Survey, SurveyDataVisibility } from 'app/models/survey.model';
2221
import { AuthService } from 'app/services/auth/auth.service';
@@ -28,7 +27,7 @@ import { DraftSurveyService } from 'app/services/draft-survey/draft-survey.servi
2827
standalone: false,
2928
})
3029
export class DataVisibilityControlComponent {
31-
private subscription = new Subscription();
30+
survey = input<Survey>();
3231

3332
selectedDataVisibility!: SurveyDataVisibility;
3433

@@ -38,16 +37,14 @@ export class DataVisibilityControlComponent {
3837
readonly authService: AuthService,
3938
readonly draftSurveyService: DraftSurveyService
4039
) {
41-
this.subscription.add(
42-
this.draftSurveyService
43-
.getSurvey$()
44-
.subscribe(survey => this.onSurveyLoaded(survey))
45-
);
46-
}
47-
48-
private async onSurveyLoaded(survey: Survey): Promise<void> {
49-
this.selectedDataVisibility =
50-
survey.dataVisibility || SurveyDataVisibility.CONTRIBUTOR_AND_ORGANIZERS;
40+
effect(() => {
41+
const survey = this.survey();
42+
if (survey) {
43+
this.selectedDataVisibility =
44+
survey.dataVisibility ||
45+
SurveyDataVisibility.CONTRIBUTOR_AND_ORGANIZERS;
46+
}
47+
});
5148
}
5249

5350
changeDataVisibility(event: MatSlideToggleChange) {
@@ -59,8 +56,4 @@ export class DataVisibilityControlComponent {
5956

6057
this.draftSurveyService.updateDataVisibility(dataVisibility);
6158
}
62-
63-
ngOnDestroy() {
64-
this.subscription.unsubscribe();
65-
}
6659
}

web/src/app/components/shared/general-access-control/general-access-control.component.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616

1717
import '@angular/localize/init';
1818

19-
import { Component } from '@angular/core';
19+
import { Component, effect, input } from '@angular/core';
2020
import { Map } from 'immutable';
21-
import { Subscription } from 'rxjs';
2221

2322
import { Survey, SurveyGeneralAccess } from 'app/models/survey.model';
2423
import { AuthService } from 'app/services/auth/auth.service';
@@ -53,7 +52,7 @@ const generalAccessLabels = Map<
5352
standalone: false,
5453
})
5554
export class GeneralAccessControlComponent {
56-
private subscription = new Subscription();
55+
survey = input<Survey>();
5756

5857
selectedGeneralAccess!: SurveyGeneralAccess;
5958

@@ -65,31 +64,24 @@ export class GeneralAccessControlComponent {
6564
readonly authService: AuthService,
6665
readonly draftSurveyService: DraftSurveyService
6766
) {
68-
this.subscription.add(
69-
this.draftSurveyService
70-
.getSurvey$()
71-
.subscribe(survey => this.onSurveyLoaded(survey))
72-
);
67+
effect(() => {
68+
const survey = this.survey();
69+
if (survey) {
70+
// Default to RESTRICTED for general access if not explicitly set.
71+
// This is present for backward-compatibility with older surveys.
72+
this.selectedGeneralAccess =
73+
survey.generalAccess || SurveyGeneralAccess.RESTRICTED;
74+
}
75+
});
7376
}
7477

7578
get generalAccessKeys(): SurveyGeneralAccess[] {
7679
return Array.from(this.generalAccessLabels.keys());
7780
}
7881

79-
private async onSurveyLoaded(survey: Survey): Promise<void> {
80-
// Default to RESTRICTED for general access if not explicitly set.
81-
// This is present for backward-compatibility with older surveys.
82-
this.selectedGeneralAccess =
83-
survey.generalAccess || SurveyGeneralAccess.RESTRICTED;
84-
}
85-
8682
changeGeneralAccess(generalAccess: SurveyGeneralAccess) {
8783
this.selectedGeneralAccess = generalAccess;
8884

8985
this.draftSurveyService.updateGeneralAccess(generalAccess);
9086
}
91-
92-
ngOnDestroy() {
93-
this.subscription.unsubscribe();
94-
}
9587
}

web/src/app/components/shared/share-dialog/share-dialog.component.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { Component } from '@angular/core';
17+
import { Component, Inject } from '@angular/core';
1818
import {
1919
AbstractControl,
2020
FormControl,
@@ -23,10 +23,9 @@ import {
2323
ValidatorFn,
2424
Validators,
2525
} from '@angular/forms';
26-
import { MatDialogRef } from '@angular/material/dialog';
26+
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
2727
import { MatSelectChange } from '@angular/material/select';
2828
import { Map } from 'immutable';
29-
import { Subscription } from 'rxjs';
3029

3130
import { AclEntry } from 'app/models/acl-entry.model';
3231
import { Role } from 'app/models/role.model';
@@ -65,17 +64,12 @@ export class ShareDialogComponent {
6564
/** The active survey. */
6665
private survey?: Survey;
6766

68-
private subscription = new Subscription();
69-
7067
constructor(
7168
private dialogRef: MatDialogRef<ShareDialogComponent>,
72-
private draftSurveyService: DraftSurveyService
69+
private draftSurveyService: DraftSurveyService,
70+
@Inject(MAT_DIALOG_DATA) data: { survey: Survey }
7371
) {
74-
this.subscription.add(
75-
this.draftSurveyService
76-
.getSurvey$()
77-
.subscribe(survey => this.onSurveyLoaded(survey))
78-
);
72+
this.onSurveyLoaded(data.survey);
7973
}
8074

8175
/**
@@ -128,13 +122,6 @@ export class ShareDialogComponent {
128122
this.dialogRef.close();
129123
}
130124

131-
/**
132-
* Clean up Rx subscription when cleaning up the component.
133-
*/
134-
ngOnDestroy(): void {
135-
this.subscription.unsubscribe();
136-
}
137-
138125
/**
139126
* Update ACL and surveyId when survey is loaded.
140127
*/

web/src/app/components/shared/share-list/share-list.component.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { Component } from '@angular/core';
17+
import { Component, effect, input } from '@angular/core';
1818
import { MatSelectChange } from '@angular/material/select';
1919
import { Map } from 'immutable';
20-
import { Subscription } from 'rxjs';
2120

2221
import { AclEntry } from 'app/models/acl-entry.model';
2322
import { Role } from 'app/models/role.model';
@@ -32,12 +31,11 @@ import { DraftSurveyService } from 'app/services/draft-survey/draft-survey.servi
3231
standalone: false,
3332
})
3433
export class ShareListComponent {
34+
survey = input<Survey>();
35+
3536
acl: Array<AclEntry> = [];
36-
survey?: Survey;
3737
surveyOwnerEmail = '';
3838

39-
private subscription = new Subscription();
40-
4139
readonly roleOptions = ROLE_OPTIONS;
4240

4341
roles = Role;
@@ -46,16 +44,15 @@ export class ShareListComponent {
4644
readonly authService: AuthService,
4745
readonly draftSurveyService: DraftSurveyService
4846
) {
49-
this.subscription.add(
50-
this.draftSurveyService
51-
.getSurvey$()
52-
.subscribe(survey => this.onSurveyLoaded(survey))
53-
);
47+
effect(() => {
48+
const survey = this.survey();
49+
if (survey) {
50+
this.onSurveyLoaded(survey);
51+
}
52+
});
5453
}
5554

5655
private async onSurveyLoaded(survey: Survey): Promise<void> {
57-
this.survey = survey;
58-
5956
const owner = await this.authService.getUser(survey.ownerId);
6057

6158
this.surveyOwnerEmail = owner?.email || '';
@@ -88,8 +85,4 @@ export class ShareListComponent {
8885
Map(aclUpdate.map(entry => [entry.email, entry.role]))
8986
);
9087
}
91-
92-
ngOnDestroy() {
93-
this.subscription.unsubscribe();
94-
}
9588
}

web/src/app/components/shared/share-survey/share-survey.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</mat-card-header>
2828

2929
<mat-card-content>
30-
<ground-share-list></ground-share-list>
30+
<ground-share-list [survey]="survey"></ground-share-list>
3131
</mat-card-content>
3232
</mat-card>
3333

@@ -37,12 +37,12 @@
3737
</mat-card-header>
3838

3939
<mat-card-content>
40-
<ground-general-access-control></ground-general-access-control>
40+
<ground-general-access-control [survey]="survey"></ground-general-access-control>
4141
</mat-card-content>
4242
</mat-card>
4343

4444
<mat-card>
45-
<ground-data-visibility-control class="floating-button"></ground-data-visibility-control>
45+
<ground-data-visibility-control class="floating-button" [survey]="survey"></ground-data-visibility-control>
4646

4747
<mat-card-header>
4848
<mat-card-title i18n="@@app.cards.dataVisibility.title">Data visibility</mat-card-title>

0 commit comments

Comments
 (0)