Skip to content

Commit ba9d7b7

Browse files
authored
fix(projects-selector): fixed project fetching logic (#462)
1 parent b4b0b26 commit ba9d7b7

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

src/app/shared/components/project-selector/project-selector.component.ts

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,30 @@ export class ProjectSelectorComponent {
8484
effect(() => {
8585
const currentUser = this.currentUser();
8686
if (currentUser) {
87-
this.actions.getProjects(currentUser.id);
87+
this.fetchProjects();
8888
}
8989
});
9090

9191
effect(() => {
9292
const isProjectsLoading = this.isProjectsLoading();
9393
const projects = this.projects();
94-
const excludeIds = this.excludeProjectIds();
9594

9695
if (isProjectsLoading || !projects.length) {
97-
this.projectsOptions.set([]);
9896
return;
9997
}
10098

10199
this.projectsLoaded.emit(projects);
100+
});
101+
102+
effect(() => {
103+
const isProjectsLoading = this.isProjectsLoading();
104+
const projects = this.projects();
105+
const excludeIds = this.excludeProjectIds();
106+
107+
if (isProjectsLoading || !projects.length) {
108+
this.projectsOptions.set([]);
109+
return;
110+
}
102111

103112
const excludeSet = new Set(excludeIds);
104113
const availableProjects = projects.filter((project) => !excludeSet.has(project.id));
@@ -116,15 +125,22 @@ export class ProjectSelectorComponent {
116125
this.filterSubject
117126
.pipe(debounceTime(300), distinctUntilChanged(), takeUntilDestroyed(this.destroyRef))
118127
.subscribe((filterValue) => {
119-
const currentUser = this.currentUser();
120-
if (!currentUser) return;
128+
this.fetchProjects(filterValue);
129+
});
130+
}
121131

122-
const params: Record<string, string> = {
123-
'filter[current_user_permissions]': 'admin',
124-
'filter[title]': filterValue,
125-
};
132+
private fetchProjects(filterTitle?: string): void {
133+
const currentUser = this.currentUser();
134+
if (!currentUser) return;
126135

127-
this.actions.getProjects(currentUser.id, params);
128-
});
136+
const params: Record<string, string> = {
137+
'filter[current_user_permissions]': 'admin',
138+
};
139+
140+
if (filterTitle && filterTitle.trim()) {
141+
params['filter[title]'] = filterTitle;
142+
}
143+
144+
this.actions.getProjects(currentUser.id, params);
129145
}
130146
}

0 commit comments

Comments
 (0)