Skip to content

Commit 92add4d

Browse files
committed
refactor: migrate inputs and outputs to signals
1 parent d5cf529 commit 92add4d

File tree

117 files changed

+802
-827
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+802
-827
lines changed

src/app/articles/list/list.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ <h1 i18n>Articles</h1>
4343
}
4444
</ul>
4545

46-
<app-paginator [data]="response.paginator"></app-paginator>
46+
@if (response.paginator) {
47+
<app-paginator [data]="response.paginator"></app-paginator>
48+
}
4749
</div>
4850
} @else {
4951
<div class="spinner-border" role="status"><span class="visually-hidden" i18n>Loading…</span></div>

src/app/brands/item/item.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
[routerLink]="['/', brand.catname]"
2222
class="brandicon"
2323
[ngClass]="'brandicon-' + cssClass(brand)"
24-
[ngStyle]="{'background-image': 'url(' + icons?.image + ')'}"
24+
[ngStyle]="{'background-image': 'url(' + icons()?.image + ')'}"
2525
></a>
2626
<h4>
2727
<a [routerLink]="['/', brand.catname]" [textContent]="brand.name"></a>

src/app/brands/item/item.component.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import {AsyncPipe, NgClass, NgIf, NgStyle} from '@angular/common';
2-
import {Component, inject, Input} from '@angular/core';
2+
import {Component, inject, input} from '@angular/core';
3+
import {toObservable} from '@angular/core/rxjs-interop';
34
import {RouterLink} from '@angular/router';
45
import {APIBrandsListItem, BrandIcons, NewItemsRequest} from '@grpc/spec.pb';
56
import {ItemsClient} from '@grpc/spec.pbsc';
67
import {NgbPopover} from '@ng-bootstrap/ng-bootstrap';
78
import {LanguageService} from '@services/language';
8-
import {BehaviorSubject, EMPTY} from 'rxjs';
9+
import {EMPTY} from 'rxjs';
910
import {switchMap} from 'rxjs/operators';
1011

1112
@Component({
@@ -17,12 +18,10 @@ export class BrandsItemComponent {
1718
readonly #itemsClient = inject(ItemsClient);
1819
readonly #languageService = inject(LanguageService);
1920

20-
@Input() set brand(item: APIBrandsListItem) {
21-
this.brand$.next(item);
22-
}
23-
protected readonly brand$ = new BehaviorSubject<APIBrandsListItem | null>(null);
21+
readonly brand = input.required<APIBrandsListItem>();
22+
protected readonly brand$ = toObservable(this.brand);
2423

25-
@Input() icons?: BrandIcons;
24+
readonly icons = input.required<BrandIcons>();
2625

2726
protected readonly response$ = this.brand$.pipe(
2827
switchMap((brand) =>

src/app/cars/specifications-editor/engine/engine.component.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import {AsyncPipe} from '@angular/common';
2-
import {Component, EventEmitter, inject, Input, Output} from '@angular/core';
2+
import {Component, inject, input, output} from '@angular/core';
3+
import {toObservable} from '@angular/core/rxjs-interop';
34
import {RouterLink} from '@angular/router';
45
import {APIItem, UpdateItemRequest} from '@grpc/spec.pb';
56
import {ItemFields, ItemRequest} from '@grpc/spec.pb';
67
import {ItemsClient} from '@grpc/spec.pbsc';
78
import {FieldMask} from '@ngx-grpc/well-known-types';
89
import {AuthService, Role} from '@services/auth.service';
910
import {LanguageService} from '@services/language';
10-
import {BehaviorSubject, Observable, of} from 'rxjs';
11+
import {Observable, of} from 'rxjs';
1112
import {shareReplay, switchMap} from 'rxjs/operators';
1213

1314
import {ToastsService} from '../../../toasts/toasts.service';
@@ -23,12 +24,10 @@ export class CarsSpecificationsEditorEngineComponent {
2324
readonly #toastService = inject(ToastsService);
2425
readonly #languageService = inject(LanguageService);
2526

26-
@Input() set item(item: APIItem) {
27-
this.item$.next(item);
28-
}
29-
protected readonly item$ = new BehaviorSubject<APIItem | null>(null);
27+
readonly item = input.required<APIItem>();
28+
protected readonly item$ = toObservable(this.item);
3029

31-
@Output() changed = new EventEmitter<void>();
30+
readonly changed = output<void>();
3231
protected readonly isAllowedEditEngine$ = this.#auth
3332
.hasRole$(Role.CARS_MODER)
3433
.pipe(shareReplay({bufferSize: 1, refCount: false}));
@@ -65,7 +64,7 @@ export class CarsSpecificationsEditorEngineComponent {
6564
)
6665
.subscribe({
6766
error: (response: unknown) => this.#toastService.handleError(response),
68-
next: () => this.changed.emit(),
67+
next: () => this.changed.emit(void 0),
6968
});
7069
}
7170

src/app/cars/specifications-editor/engine/select/tree-item/tree-item.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@if (item) {
1+
@if (item(); as item) {
22
@if ((item.item?.childsCount || 0) > 0) {
33
<div>
44
<i class="bi bi-folder2 me-1" aria-hidden="true" [hidden]="open"></i>

src/app/cars/specifications-editor/engine/select/tree-item/tree-item.component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, EventEmitter, inject, Input, Output} from '@angular/core';
1+
import {Component, inject, input, output} from '@angular/core';
22
import {
33
ItemFields,
44
ItemListOptions,
@@ -24,16 +24,16 @@ export class CarsSelectEngineTreeItemComponent {
2424
readonly #itemsClient = inject(ItemsClient);
2525
readonly #languageService = inject(LanguageService);
2626

27-
@Input() item?: ItemParent;
28-
@Output() selected = new EventEmitter<string>();
27+
readonly item = input.required<ItemParent>();
28+
readonly selected = output<string>();
2929

3030
protected open = false;
3131
protected loading = false;
3232
protected childs: ItemParent[] = [];
3333

3434
private loadChildCatalogues() {
3535
this.loading = true;
36-
if (this.item) {
36+
if (this.item()) {
3737
this.#itemsClient
3838
.getItemParents(
3939
new ItemParentsRequest({
@@ -49,7 +49,7 @@ export class CarsSelectEngineTreeItemComponent {
4949
item: new ItemListOptions({
5050
typeId: ItemType.ITEM_TYPE_ENGINE,
5151
}),
52-
parentId: this.item.itemId,
52+
parentId: this.item().itemId,
5353
}),
5454
order: ItemParentsRequest.Order.AUTO,
5555
}),

src/app/cars/specifications-editor/result/result.component.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import {AsyncPipe} from '@angular/common';
2-
import {Component, inject, Input} from '@angular/core';
2+
import {Component, inject, input} from '@angular/core';
3+
import {toObservable} from '@angular/core/rxjs-interop';
34
import {DomSanitizer} from '@angular/platform-browser';
45
import {APIItem, GetSpecificationsRequest} from '@grpc/spec.pb';
56
import {AttrsClient} from '@grpc/spec.pbsc';
67
import {LanguageService} from '@services/language';
7-
import {BehaviorSubject, EMPTY} from 'rxjs';
8+
import {EMPTY} from 'rxjs';
89
import {map, switchMap} from 'rxjs/operators';
910

1011
@Component({
@@ -17,12 +18,9 @@ export class CarsSpecificationsEditorResultComponent {
1718
readonly #sanitizer = inject(DomSanitizer);
1819
readonly #languageService = inject(LanguageService);
1920

20-
@Input() set item(item: APIItem) {
21-
this.#item$.next(item);
22-
}
23-
readonly #item$ = new BehaviorSubject<APIItem | null>(null);
21+
readonly item = input.required<APIItem>();
2422

25-
protected readonly html$ = this.#item$.pipe(
23+
protected readonly html$ = toObservable(this.item).pipe(
2624
switchMap((item) =>
2725
item
2826
? this.#attrsClient.getSpecifications(

src/app/cars/specifications-editor/spec/spec.component.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {AsyncPipe, DatePipe, NgStyle} from '@angular/common';
2-
import {Component, inject, Input} from '@angular/core';
2+
import {Component, inject, input} from '@angular/core';
3+
import {toObservable} from '@angular/core/rxjs-interop';
34
import {FormArray, FormControl, FormsModule, ReactiveFormsModule} from '@angular/forms';
45
import {
56
APIItem,
@@ -96,10 +97,8 @@ export class CarsSpecificationsEditorSpecComponent {
9697
readonly #attrsClient = inject(AttrsClient);
9798
readonly #languageService = inject(LanguageService);
9899

99-
@Input() set item(item: APIItem) {
100-
this.item$.next(item);
101-
}
102-
protected readonly item$ = new BehaviorSubject<APIItem | null>(null);
100+
readonly item = input.required<APIItem>();
101+
readonly item$ = toObservable(this.item);
103102

104103
protected loading = 0;
105104
readonly #change$ = new BehaviorSubject<void>(void 0);

src/app/catalogue/item-menu/item-menu.component.html

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
<ul class="nav nav-pills mb-4">
2-
@if (childsCounts) {
2+
@if (childsCounts(); as childsCounts) {
33
@if (childsCounts.stock > 0) {
44
<li class="nav-item">
5-
<a class="nav-link" [class.active]="active === 'default'" [routerLink]="itemRouterLink">
5+
<a class="nav-link" [class.active]="active() === 'default'" [routerLink]="itemRouterLink()">
66
<i class="bi bi-list" aria-hidden="true"></i>
7-
<app-item-header [item]="{nameHTML: header?.nameHTML || ''}"></app-item-header>
7+
<app-item-header [item]="{nameHTML: header()?.nameHTML || ''}"></app-item-header>
88
<span class="badge rounded-pill text-bg-secondary">{{ childsCounts.stock }}</span>
99
</a>
1010
</li>
1111
}
1212
@if (childsCounts.tuning > 0) {
1313
<li class="nav-item">
14-
<a class="nav-link" [class.active]="active === 'tuning'" [routerLink]="itemRouterLink.concat(['tuning'])">
14+
<a class="nav-link" [class.active]="active() === 'tuning'" [routerLink]="itemRouterLink().concat(['tuning'])">
1515
<i class="bi bi-list" aria-hidden="true"></i>
1616
<ng-container i18n>Related</ng-container>
17-
<app-item-header [item]="{nameHTML: header?.nameHTML || ''}"></app-item-header>
17+
<app-item-header [item]="{nameHTML: header()?.nameHTML || ''}"></app-item-header>
1818
<span class="badge rounded-pill text-bg-secondary">{{ childsCounts.tuning }}</span>
1919
</a>
2020
</li>
2121
}
2222
@if (childsCounts.sport > 0) {
2323
<li class="nav-item">
24-
<a class="nav-link" [class.active]="active === 'sport'" [routerLink]="itemRouterLink.concat(['sport'])">
24+
<a class="nav-link" [class.active]="active() === 'sport'" [routerLink]="itemRouterLink().concat(['sport'])">
2525
<i class="bi bi-list" aria-hidden="true"></i>
26-
<app-item-header [item]="{nameHTML: header?.nameHTML || ''}"></app-item-header>
26+
<app-item-header [item]="{nameHTML: header()?.nameHTML || ''}"></app-item-header>
2727
<ng-container i18n>Sport</ng-container>
2828
<span class="badge rounded-pill text-bg-secondary">{{ childsCounts.sport }}</span>
2929
</a>
3030
</li>
3131
}
3232
}
33-
@if (picturesCount > 0) {
33+
@if (picturesCount() > 0) {
3434
<li class="nav-item">
35-
<a class="nav-link" [class.active]="active === 'pictures'" [routerLink]="itemRouterLink.concat(['pictures'])">
35+
<a class="nav-link" [class.active]="active() === 'pictures'" [routerLink]="itemRouterLink().concat(['pictures'])">
3636
<i class="bi bi-grid-3x2-gap-fill" aria-hidden="true"></i>
3737
<ng-container i18n>All pictures of</ng-container>
38-
<app-item-header [item]="{nameHTML: header?.nameHTML || ''}"></app-item-header>
39-
<span class="badge rounded-pill text-bg-secondary">{{ picturesCount }}</span>
38+
<app-item-header [item]="{nameHTML: header()?.nameHTML || ''}"></app-item-header>
39+
<span class="badge rounded-pill text-bg-secondary">{{ picturesCount() }}</span>
4040
</a>
4141
</li>
4242
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type {APIItemChildsCounts} from '@services/item';
22
import type {ItemHeader} from '@utils/item-header/item-header.component';
33

4-
import {Component, Input} from '@angular/core';
4+
import {Component, input} from '@angular/core';
55
import {RouterLink} from '@angular/router';
66
import {ItemHeaderComponent} from '@utils/item-header/item-header.component';
77

@@ -11,9 +11,9 @@ import {ItemHeaderComponent} from '@utils/item-header/item-header.component';
1111
templateUrl: './item-menu.component.html',
1212
})
1313
export class CatalogueItemMenuComponent {
14-
@Input() itemRouterLink: string[] = [];
15-
@Input() header?: ItemHeader;
16-
@Input() childsCounts?: APIItemChildsCounts;
17-
@Input() picturesCount = 0;
18-
@Input() active = 'default';
14+
readonly itemRouterLink = input.required<string[]>();
15+
readonly header = input.required<ItemHeader>();
16+
readonly childsCounts = input<APIItemChildsCounts | undefined>(undefined);
17+
readonly picturesCount = input.required<number>();
18+
readonly active = input.required<string>();
1919
}

0 commit comments

Comments
 (0)