Skip to content

Commit abdbfe5

Browse files
committed
refactor: migrate to signals for projects
1 parent 5151dc5 commit abdbfe5

File tree

5 files changed

+17
-36
lines changed

5 files changed

+17
-36
lines changed

src/app/checklist/checklist-search/checklist-search.component.html

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
<input
2-
placeholder="Search"
3-
spellcheck="false"
4-
(focus)="focused()"
5-
[formControl]="searchField"
6-
[matAutocomplete]="auto"
7-
/>
1+
<input placeholder="Search" spellcheck="false" [formControl]="searchField" [matAutocomplete]="auto" />
82
<mat-autocomplete
93
#auto="matAutocomplete"
104
[displayWith]="getOptionText.bind(this)"

src/app/checklist/checklist-search/checklist-search.component.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,13 @@ export class ChecklistSearchComponent {
2323
private router = inject(Router);
2424
searchField = new FormControl<string>('');
2525
search = toSignal(this.searchField.valueChanges.pipe(debounceTime(150)));
26-
focus = signal(0);
2726

2827
results = computed<any>(() => {
29-
const _ = this.focus();
3028
const search = this.search();
3129
const results = this.searchService.search(search);
3230
return results.map(this.mapToSearchResult);
3331
});
3432

35-
focused() {
36-
this.focus.update(prev => prev + 1);
37-
}
38-
3933
getOptionText(value: SearchResult) {
4034
return value?.document?.title || '';
4135
}

src/app/projects/project-dialog/project-dialog.component.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Inject, OnInit } from '@angular/core';
1+
import { Component, inject } from '@angular/core';
22
import { FormControl, Validators, ReactiveFormsModule } from '@angular/forms';
33
import { ErrorStateMatcher } from '@angular/material/core';
44
import {
@@ -91,7 +91,10 @@ const verifyProjectName = (projectName: string) => {
9191
MatDialogClose
9292
]
9393
})
94-
export class ProjectDialogComponent implements OnInit {
94+
export class ProjectDialogComponent {
95+
public data = inject<ProjectDialogData>(MAT_DIALOG_DATA);
96+
private store = inject<Store<ApplicationState>>(Store);
97+
public dialogRef = inject<MatDialogRef<ProjectDialogComponent, ProjectDialogResult>>(MatDialogRef);
9598
mode: ProjectDialogMode;
9699
title: string;
97100
project: Partial<Project>;
@@ -104,13 +107,7 @@ export class ProjectDialogComponent implements OnInit {
104107
verifyProjectName = new FormControl('');
105108
errorStateMatcher = new CustomErrorStateMatcher();
106109

107-
constructor(
108-
@Inject(MAT_DIALOG_DATA) public data: ProjectDialogData,
109-
private store: Store<ApplicationState>,
110-
public dialogRef: MatDialogRef<ProjectDialogComponent, ProjectDialogResult>
111-
) {}
112-
113-
ngOnInit() {
110+
constructor() {
114111
const { title, project, mode = ProjectDialogMode.Create, submitButtonText } = this.data;
115112

116113
this.project = project ? project : { name: '' };

src/app/projects/projects-view/projects-view.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ <h5>Your Projects</h5>
1818
<mat-icon>add</mat-icon>
1919
Add Project
2020
</mat-card>
21-
<mat-card appearance="outlined" (click)="navigateToProject(project.id)" *ngFor="let project of projects$ | async">
21+
<mat-card appearance="outlined" (click)="navigateToProject(project.id)" *ngFor="let project of projects()">
2222
<div class="card-ripple" matRipple></div>
2323
<mat-card-content>
2424
<h2 class="project-name">{{ project.name }}</h2>

src/app/projects/projects-view/projects-view.component.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, inject } from '@angular/core';
22
import { MatDialog } from '@angular/material/dialog';
33
import { Router } from '@angular/router';
4-
import { select, Store } from '@ngrx/store';
5-
import { asyncScheduler, Observable } from 'rxjs';
4+
import { Store } from '@ngrx/store';
5+
import { asyncScheduler } from 'rxjs';
66
import { filter, map, observeOn } from 'rxjs/operators';
77
import { ApplicationState } from '../../state/app.state';
88
import { Project } from '../models/projects.model';
@@ -18,7 +18,7 @@ import {
1818
import { AddProject, DeleteProject, EditProject } from '../state/projects.actions';
1919
import { ProjectsSelectors } from '../state/projects.selectors';
2020
import { MatIconButton } from '@angular/material/button';
21-
import { NgFor, AsyncPipe, PercentPipe } from '@angular/common';
21+
import { NgFor, PercentPipe } from '@angular/common';
2222
import { MatIcon } from '@angular/material/icon';
2323
import { MatRipple } from '@angular/material/core';
2424
import { MatCard, MatCardContent, MatCardActions } from '@angular/material/card';
@@ -40,22 +40,18 @@ import { FooterComponent } from 'src/app/shared/footer/footer.component';
4040
MatCardContent,
4141
MatCardActions,
4242
MatIconButton,
43-
AsyncPipe,
4443
PercentPipe,
4544
ToolbarComponent,
4645
ToolbarLogoComponent,
4746
ScoreChartComponent,
4847
FooterComponent
4948
]
5049
})
51-
export class ProjectsViewComponent implements OnInit {
52-
projects$: Observable<Array<Project>>;
53-
54-
constructor(private store: Store<ApplicationState>, private router: Router, private dialog: MatDialog) {}
55-
56-
ngOnInit() {
57-
this.projects$ = this.store.pipe(select(ProjectsSelectors.getProjects));
58-
}
50+
export class ProjectsViewComponent {
51+
private store = inject<Store<ApplicationState>>(Store);
52+
private router = inject(Router);
53+
private dialog = inject(MatDialog);
54+
projects = this.store.selectSignal(ProjectsSelectors.getProjects);
5955

6056
navigateToProject(projectId: string) {
6157
this.router.navigate([`/${projectId}/checklist`]);

0 commit comments

Comments
 (0)