mirror of
https://github.com/opelly27/WinStudentGoalTracker.git
synced 2026-05-20 05:17:41 +00:00
fixed duplicative API calls
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { Component, computed, effect, inject, signal } from '@angular/core';
|
import { Component, computed, effect, inject, signal, untracked } from '@angular/core';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { StudentService } from '../../../shared/services/student.service';
|
import { StudentService } from '../../../shared/services/student.service';
|
||||||
import { StudentCardDto } from '../../../shared/classes/student-card.dto';
|
import { StudentCardDto } from '../../../shared/classes/student-card.dto';
|
||||||
@@ -41,12 +41,17 @@ export class Workspace {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// When dataVersion changes and we have a student loaded, refresh
|
// When dataVersion changes and we have a student loaded, refresh.
|
||||||
|
// Use untracked() for studentId so this effect only re-runs on
|
||||||
|
// dataVersion changes — route params already handle studentId changes.
|
||||||
let initialized = false;
|
let initialized = false;
|
||||||
effect(() => {
|
effect(() => {
|
||||||
this.studentService.dataVersion();
|
this.studentService.dataVersion();
|
||||||
if (initialized && this.studentId()) {
|
if (initialized) {
|
||||||
this.loadStudentData(this.studentId()!);
|
const id = untracked(() => this.studentId());
|
||||||
|
if (id) {
|
||||||
|
this.loadStudentData(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
initialized = true;
|
initialized = true;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user