diff --git a/client/src/components/TrainerSelector.vue b/client/src/components/TrainerSelector.vue index f1f501e..c1b68bc 100644 --- a/client/src/components/TrainerSelector.vue +++ b/client/src/components/TrainerSelector.vue @@ -22,21 +22,14 @@ export default { centers: Array }, async mounted() { - const filters = this.centers?.map(c => `center=${c}`).join("&"); - const res = await fetch(`${import.meta.env.VITE_BASE_API_URL}/trainer?${filters}`); - if (res.status === 200) { - this.trainers = await res.json(); - } + await this.fetchTrainers(); }, watch: { centers: { - async handler(centers: number[]) { + async handler() { this.selectedTrainers = []; - const filters = centers?.map(c => `center=${c}`).join("&"); - const res = await fetch(`${import.meta.env.VITE_BASE_API_URL}/trainer?${filters}`); - if (res.status === 200) { - this.trainers = await res.json(); - } + this.$emit("selectionChanged", this.selectedTrainers); + await this.fetchTrainers(); }, deep: true } @@ -55,6 +48,13 @@ export default { this.selectedTrainers.push(id); } this.$emit("selectionChanged", this.selectedTrainers); + }, + async fetchTrainers() { + const filters = this.centers?.map(c => `center=${c}`).join("&"); + const res = await fetch(`${import.meta.env.VITE_BASE_API_URL}/trainer?${filters}`); + if (res.status === 200) { + this.trainers = await res.json(); + } } } }