-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Develop #1526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Develop #1526
Changes from all commits
705da03
11964fa
981ba9b
2b207fd
3dd6adf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,35 @@ | ||
| import { Component, OnInit } from '@angular/core'; | ||
| import { CityStore } from '../../data-access/city.store'; | ||
| import { FakeHttpService } from '../../data-access/fake-http.service'; | ||
| import { CardType } from '../../model/card.model'; | ||
| import { City } from '../../model/city.model'; | ||
| import { CardComponent } from '../../ui/card/card.component'; | ||
|
|
||
| @Component({ | ||
| selector: 'app-city-card', | ||
| template: 'TODO City', | ||
| template: ` | ||
| <app-card | ||
| [list]="cities" | ||
| [type]="cardType" | ||
| [image]="image" | ||
| customClass="bg-light-red"></app-card> | ||
| `, | ||
| standalone: true, | ||
| imports: [], | ||
| imports: [CardComponent], | ||
| }) | ||
| export class CityCardComponent implements OnInit { | ||
| constructor() {} | ||
| cities: City[] = []; | ||
| image = 'city.png'; | ||
| cardType = CardType.CITY; | ||
|
|
||
| ngOnInit(): void {} | ||
| constructor( | ||
| private http: FakeHttpService, | ||
| private store: CityStore, | ||
| ) {} | ||
|
|
||
| ngOnInit(): void { | ||
| this.http.fetchCities$.subscribe((s) => this.store.addAll(s)); | ||
|
|
||
| this.store.cities$.subscribe((s) => (this.cities = s)); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { Injectable } from '@angular/core'; | ||
| import { CityStore } from '../data-access/city.store'; | ||
| import { | ||
| randomCity, | ||
| randStudent, | ||
| randTeacher, | ||
| } from '../data-access/fake-http.service'; | ||
| import { StudentStore } from '../data-access/student.store'; | ||
| import { TeacherStore } from '../data-access/teacher.store'; | ||
| import { CardType } from '../model/card.model'; | ||
|
|
||
| @Injectable({ | ||
| providedIn: 'root', | ||
| }) | ||
| export class CardService { | ||
| constructor( | ||
| private teacherStore: TeacherStore, | ||
| private studentStore: StudentStore, | ||
| private cityStore: CityStore, | ||
| ) {} | ||
|
|
||
| addOne(type: CardType) { | ||
| if (type === CardType.TEACHER) { | ||
| this.teacherStore.addOne(randTeacher()); | ||
| } else if (type === CardType.STUDENT) { | ||
| this.studentStore.addOne(randStudent()); | ||
| } else if (type === CardType.CITY) { | ||
| this.cityStore.addOne(randomCity()); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,9 +1,7 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { NgFor, NgIf } from '@angular/common'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { CommonModule } from '@angular/common'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Component, Input } from '@angular/core'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { randStudent, randTeacher } from '../../data-access/fake-http.service'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { StudentStore } from '../../data-access/student.store'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { TeacherStore } from '../../data-access/teacher.store'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { CardType } from '../../model/card.model'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { CardService } from '../../services/card.service'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { ListItemComponent } from '../list-item/list-item.component'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Component({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -12,50 +10,39 @@ import { ListItemComponent } from '../list-item/list-item.component'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class="flex w-fit flex-col gap-3 rounded-md border-2 border-black p-4" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [class]="customClass"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <img | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| *ngIf="type === CardType.TEACHER" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| src="assets/img/teacher.png" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| width="200px" /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <img | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| *ngIf="type === CardType.STUDENT" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| src="assets/img/student.webp" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| width="200px" /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <ng-template #cardContent> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <img src="assets/img/{{ image }}" width="200px" /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <section> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <app-list-item | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| *ngFor="let item of list" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [name]="item.firstName" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [id]="item.id" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [type]="type"></app-list-item> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </section> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <section> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <app-list-item | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| *ngFor="let item of list" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [name]="item.firstName ?? item.name" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [id]="item.id" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [type]="type"></app-list-item> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </section> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <button | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class="rounded-sm border border-blue-500 bg-blue-300 p-2" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (click)="addNewItem()"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Add | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </button> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <button | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class="rounded-sm border border-blue-500 bg-blue-300 p-2" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (click)="addNewItem()"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Add | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </button> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </ng-template> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <ng-container *ngTemplateOutlet="cardContent"></ng-container> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+13
to
32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
# Inspect the target component and nearby context
git ls-files apps/angular/projection/src/app/ui/card
echo "--- card.component.ts ---"
cat -n apps/angular/projection/src/app/ui/card/card.component.ts
echo "--- search for ng-content / ngTemplateOutlet in projection app ---"
rg -n "ng-content|ngTemplateOutlet|cardContent|CardType|alt=" apps/angular/projection/src/app -SRepository: tomalaforge/angular-challenges Length of output: 4295 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "--- usages of app-card ---"
rg -n "<app-card|selector: 'app-card'|selector: \"app-card\"" apps/angular/projection/src/app -S
echo "--- card-related component files ---"
git ls-files apps/angular/projection/src/app/component apps/angular/projection/src/app/ui
echo "--- card component and likely callers ---"
sed -n '1,220p' apps/angular/projection/src/app/component/city-card/city-card.component.ts
printf '\n---\n'
sed -n '1,220p' apps/angular/projection/src/app/component/student-card/student-card.component.ts
printf '\n---\n'
sed -n '1,220p' apps/angular/projection/src/app/component/teacher-card/teacher-card.component.tsRepository: tomalaforge/angular-challenges Length of output: 4184 Add an
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| `, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| standalone: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| imports: [NgIf, NgFor, ListItemComponent], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| imports: [CommonModule, ListItemComponent], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export class CardComponent { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Input() list: any[] | null = null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Input() list!: any[]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Input() type!: CardType; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Input() customClass = ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Input() image: string = ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CardType = CardType; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| constructor( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private teacherStore: TeacherStore, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private studentStore: StudentStore, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| constructor(private cardService: CardService) {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| addNewItem() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (this.type === CardType.TEACHER) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.teacherStore.addOne(randTeacher()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if (this.type === CardType.STUDENT) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.studentStore.addOne(randStudent()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.cardService.addOne(this.type); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
37
to
47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win Use
♻️ Proposed fix+import { CardModel } from '../../model/card.model';
...
- `@Input`() list!: any[];
+ `@Input`({ required: true }) list!: CardModel[];📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Reused
bg-light-redclass from TeacherCardComponent.Per the graph context,
TeacherCardComponentalready usescustomClass="bg-light-red".StudentCardComponentuses a distinctbg-light-green. Reusingbg-light-redforCityCardComponentmakes city and teacher cards visually indistinguishable — likely a copy/paste oversight rather than an intentional shared style.🎨 Suggested fix
<app-card [list]="cities" [type]="cardType" [image]="image" - customClass="bg-light-red"></app-card> + customClass="bg-light-blue"></app-card>📝 Committable suggestion
🤖 Prompt for AI Agents