49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
|
|
import { Component, OnInit, signal } from '@angular/core';
|
||
|
|
import { Router } from '@angular/router';
|
||
|
|
import { CommonModule } from '@angular/common';
|
||
|
|
import { MatCardModule } from '@angular/material/card';
|
||
|
|
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||
|
|
import { ApiService } from '../../services';
|
||
|
|
import { Project } from '../../models';
|
||
|
|
|
||
|
|
@Component({
|
||
|
|
selector: 'app-projects-dashboard',
|
||
|
|
standalone: true,
|
||
|
|
imports: [CommonModule, MatCardModule, MatProgressSpinnerModule],
|
||
|
|
templateUrl: './projects-dashboard.component.html',
|
||
|
|
styleUrls: ['./projects-dashboard.component.scss']
|
||
|
|
})
|
||
|
|
export class ProjectsDashboardComponent implements OnInit {
|
||
|
|
projects = signal<Project[]>([]);
|
||
|
|
loading = signal(true);
|
||
|
|
error = signal<string | null>(null);
|
||
|
|
|
||
|
|
constructor(
|
||
|
|
private apiService: ApiService,
|
||
|
|
private router: Router
|
||
|
|
) {}
|
||
|
|
|
||
|
|
ngOnInit() {
|
||
|
|
this.loadProjects();
|
||
|
|
}
|
||
|
|
|
||
|
|
loadProjects() {
|
||
|
|
this.loading.set(true);
|
||
|
|
this.apiService.getProjects().subscribe({
|
||
|
|
next: (projects) => {
|
||
|
|
this.projects.set(projects);
|
||
|
|
this.loading.set(false);
|
||
|
|
},
|
||
|
|
error: (err) => {
|
||
|
|
this.error.set('Failed to load projects');
|
||
|
|
this.loading.set(false);
|
||
|
|
console.error(err);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
openProject(projectId: string) {
|
||
|
|
this.router.navigate(['/project', projectId]);
|
||
|
|
}
|
||
|
|
}
|