Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
selfcontained committed Oct 11, 2023
1 parent 74b480f commit 563c635
Showing 1 changed file with 3 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ export const useUnifiedRepositorySearch = ({ searchString, excludeProjects = fal

const filteredRepos = useMemo(() => {
const repoMap = new Map<string, SuggestedRepository>();
// combine & flatten suggestions and search results, then merge them into a map
const flattenedRepos = [suggestedQuery.data || [], searchQuery.data || []].flat();

// Add suggested results to map
for (const repo of suggestedQuery.data || []) {
for (const repo of flattenedRepos) {
const key = excludeProjects ? repo.url : `${repo.url}:${repo.projectId || ""}`;

const newEntry = {
Expand All @@ -38,21 +39,6 @@ export const useUnifiedRepositorySearch = ({ searchString, excludeProjects = fal
repoMap.set(key, newEntry);
}

// Merge the search results into the suggested results
for (const repo of searchQuery.data || []) {
const key = excludeProjects ? repo.url : `${repo.url}:${repo.projectId || ""}`;

const newEntry = {
...(repoMap.get(key) || {}),
...repo,
};
if (excludeProjects) {
newEntry.repositoryName = newEntry.repositoryName || newEntry.projectName;
newEntry.projectName = undefined;
}
repoMap.set(key, newEntry);
}

return filterRepos(searchString, Array.from(repoMap.values()));
}, [excludeProjects, searchQuery.data, searchString, suggestedQuery.data]);

Expand Down

0 comments on commit 563c635

Please sign in to comment.