From 7319a17837ded625c5213b58696eba7fa8f9a743 Mon Sep 17 00:00:00 2001 From: Gal Podlipnik Date: Tue, 5 Aug 2025 12:54:12 +0200 Subject: [PATCH] more fixes --- src/app/app.component.ts | 9 +- src/app/edit-student.component.ts | 135 ++++++++++++++++-------------- src/app/student.service.ts | 5 +- 3 files changed, 83 insertions(+), 66 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 24bce17..30ba670 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -22,8 +22,10 @@ import { LocaleStore } from './translations/locale.service'; StudentInfo - - - - -
- -

Student not found. Please return to the overview page.

+ @if (student()) { +
+
+ + +
+
+ + +
+
+ + +
+
+
- +
+ } @if (!student()) { +
+ +

Student not found. Please return to the overview page.

+ +
+ }
`, styles: [ @@ -155,6 +153,13 @@ export class EditStudentComponent implements OnInit { this.studentService.getStudentById(this.queryId() ?? '') ); + protected editedStudent = signal({ + id: '', + name: '', + email: '', + courses: [] as string[], + }); + protected courseOptions = computed(() => { return [ 'Mathematics', @@ -169,13 +174,21 @@ export class EditStudentComponent implements OnInit { }); ngOnInit() { - if (!this.student()) { + const currentStudent = this.student(); + if (currentStudent) { + this.editedStudent.set({ + id: currentStudent.id, + name: currentStudent.name, + email: currentStudent.email, + courses: [...currentStudent.courses], + }); + } else { console.error('Student not found'); } } save() { - this.studentService.updateStudent(this.student()!); + this.studentService.updateStudent(this.editedStudent()); this.router.navigate([`/${this.localeStore.getCurrentLocale()}/students`]); } diff --git a/src/app/student.service.ts b/src/app/student.service.ts index 65ff46b..8f6728a 100644 --- a/src/app/student.service.ts +++ b/src/app/student.service.ts @@ -35,9 +35,9 @@ export class StudentService { return this.students().find((student) => student.id === id); } - updateStudent(student: Student) { + updateStudent(student: Partial) { this.students.update((students) => - students.map((s) => (s.id === student.id ? student : s)) + students.map((s) => (s.id === student.id ? { ...s, ...student } : s)) ); } @@ -56,4 +56,3 @@ export class StudentService { this.students.update((students) => students.filter((s) => s.id !== id)); } } -