-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathstudent-card.component.ts
More file actions
77 lines (69 loc) · 1.94 KB
/
student-card.component.ts
File metadata and controls
77 lines (69 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { NgOptimizedImage } from '@angular/common';
import {
ChangeDetectionStrategy,
Component,
inject,
OnInit,
} from '@angular/core';
import {
FakeHttpService,
randStudent,
} from '../../data-access/fake-http.service';
import { StudentStore } from '../../data-access/student.store';
import { CardType } from '../../model/card.model';
import { CardComponent } from '../../ui/card/card.component';
import { ListItemComponent } from '../../ui/list-item/list-item.component';
@Component({
selector: 'app-student-card',
template: `
<app-card [list]="students()" customClass="bg-light-green">
<div card-header class="flex flex-col items-center">
<img
ngSrc="assets/img/student.webp"
width="200"
height="200"
alt="Students list view banner"
priority />
</div>
<ng-template #itemTemplate let-item>
<app-list-item
[name]="item.firstName"
[id]="item.id"
[type]="cardType"
(emitDelete)="deleteSingle($event)" />
</ng-template>
<div card-action>
<button
class="rounded-sm border border-blue-500 bg-blue-300 p-2"
(click)="addNew()">
Add
</button>
</div>
</app-card>
`,
styles: [
`
:host {
--card-bg: rgba(0, 250, 0, 0.1);
}
`,
],
imports: [CardComponent, NgOptimizedImage, ListItemComponent],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class StudentCardComponent implements OnInit {
private readonly studentStore = inject(StudentStore);
private http = inject(FakeHttpService);
private store = inject(StudentStore);
students = this.store.students;
cardType = CardType.STUDENT;
ngOnInit(): void {
this.http.fetchStudents$.subscribe((s) => this.store.addAll(s));
}
addNew(): void {
this.studentStore.addOne(randStudent());
}
deleteSingle(id: number): void {
this.studentStore.deleteOne(id);
}
}