Skip to content

Commit

Permalink
fix: add uniqWith to useSearchedProjects
Browse files Browse the repository at this point in the history
  • Loading branch information
aziolek committed Jan 14, 2025
1 parent 0a5a0bb commit 3de0e6b
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions client/src/hooks/queries/useSearchedProjects.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { UseQueryResult, useQuery } from '@tanstack/react-query';
import uniqWith from 'lodash/uniqWith';

import { apiGetProjectsSearch } from 'api/calls/projects';
import { QUERY_KEYS } from 'api/queryKeys';
Expand Down Expand Up @@ -26,10 +27,26 @@ export default function useSearchedProjects(
),
// No point in strigifying params, they will just flood the memory.
queryKey: QUERY_KEYS.searchResults,
select: data =>
data.projectsDetails.map(element => ({
select: data => {
const dataWithEpochNumber = data.projectsDetails.map(element => ({
...element,
epoch: Number(element.epoch),
})),
}));

/**
* Because of the bug, BE sometimes returns the same
* name, address & epoch combination multiple times.
*
* Please check e.g.
* GET https://backend.mainnet.octant.app/projects/details?epochs=1,2,3,4,5,6,7&searchPhrases=Open,Source,Observer
*
* Hence the requirement to check uniqueness.
*
* More context: https://chat.wildland.dev/wildland/pl/gghcfgjndjyjieei8axn3opdeh
*/
return uniqWith(dataWithEpochNumber, (elementA, elementB) => {
return elementA.address === elementB.address && elementA.epoch === elementB.epoch;
});
},
});
}

0 comments on commit 3de0e6b

Please sign in to comment.