From c59090a64ace9bc645cd4603330d7b96f6f78856 Mon Sep 17 00:00:00 2001 From: Borgia Leiva Date: Tue, 10 Feb 2026 11:31:06 +0100 Subject: [PATCH] Made project item redirect to project details on click --- .../project-item/project-item.component.css | 5 ++++ .../project-item/project-item.component.html | 6 ++++- .../project-item/project-item.component.ts | 24 +++++++++++++++---- src/app/pages/home/home.component.html | 2 +- src/app/pages/home/home.component.ts | 4 ---- 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/app/components/project-item/project-item.component.css b/src/app/components/project-item/project-item.component.css index c4cde1f..d7b13f1 100644 --- a/src/app/components/project-item/project-item.component.css +++ b/src/app/components/project-item/project-item.component.css @@ -8,6 +8,11 @@ border-left: 4px solid #667eea; } +.project-item.is-disabled { + cursor: not-allowed; + opacity: 0.7; +} + .project-item:hover { box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); transform: translateY(-2px); diff --git a/src/app/components/project-item/project-item.component.html b/src/app/components/project-item/project-item.component.html index 768f418..cb456a0 100644 --- a/src/app/components/project-item/project-item.component.html +++ b/src/app/components/project-item/project-item.component.html @@ -1,4 +1,8 @@ -
+

{{ project.name }}

diff --git a/src/app/components/project-item/project-item.component.ts b/src/app/components/project-item/project-item.component.ts index 058b360..2bc601d 100644 --- a/src/app/components/project-item/project-item.component.ts +++ b/src/app/components/project-item/project-item.component.ts @@ -1,19 +1,33 @@ -import { Component, Input, Output, EventEmitter } from '@angular/core'; +import { Component, Input } from '@angular/core'; import { CommonModule } from '@angular/common'; +import { RouterLink } from '@angular/router'; import { Project } from '../../models/projects.models'; @Component({ selector: 'app-project-item', standalone: true, - imports: [CommonModule], + imports: [CommonModule, RouterLink], templateUrl: './project-item.component.html', styleUrl: './project-item.component.css' }) export class ProjectItemComponent { @Input({ required: true }) project!: Project; - @Output() projectClick = new EventEmitter(); - onProjectClick() { - this.projectClick.emit(this.project); + get projectRoute(): Array | null { + const id = this.getProjectId(); + return id == null ? null : ['/projects', id]; + } + + get projectState(): { project: Project } | null { + return this.projectRoute ? { project: this.project } : null; + } + + private getProjectId(): string | number | null { + const projectAsAny = this.project as Project & { + _id?: string | number; + projectId?: string | number; + }; + + return projectAsAny.id ?? projectAsAny.projectId ?? projectAsAny._id ?? null; } } diff --git a/src/app/pages/home/home.component.html b/src/app/pages/home/home.component.html index 53bba30..18aeb08 100644 --- a/src/app/pages/home/home.component.html +++ b/src/app/pages/home/home.component.html @@ -10,7 +10,7 @@
@if (projectList.length > 0) { @for (project of projectList; track project.id) { - + } } @else {
diff --git a/src/app/pages/home/home.component.ts b/src/app/pages/home/home.component.ts index e0c7217..be3247b 100644 --- a/src/app/pages/home/home.component.ts +++ b/src/app/pages/home/home.component.ts @@ -20,10 +20,6 @@ export class HomeComponent { return this.authService.currentUser()?.projects ?? []; } - onProjectClick(project: Project) { - this.router.navigate(['/projects', project.id]); - } - onCreateProject() { this.router.navigate(['/projects/new']); }