Skip to content

Commit

Permalink
[TOOL-2773] Fix incorrect caching in useCsvUpload hook (#5820)
Browse files Browse the repository at this point in the history
## Problem solved

Fixes: #5791

Problem:

User uploads a CSV1 and then uploads a CSV2 - CSV2 is ignored and CSV1's data is sent instead of CSV2 because of incorrect query cache key

<!-- start pr-codex -->

---

## PR-Codex overview
This PR focuses on refactoring the `normalizeQuery` in the `useCsvUpload` hook to improve clarity and consistency in parameter naming.

### Detailed summary
- Changed the parameter name from `o` to `item` in the `rawData.map` function for better readability.
- Updated the `queryKey` to use `item` directly instead of `o.address`.
- Maintained the same functionality while enhancing code clarity.

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`

<!-- end pr-codex -->
  • Loading branch information
MananTank committed Dec 20, 2024
1 parent cfbe8c3 commit cb66be4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions apps/dashboard/src/hooks/useCsvUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ export function useCsvUpload<
const { getRootProps, getInputProps, isDragActive } = useDropzone({
onDrop,
});

const normalizeQuery = useQueries({
queries: rawData.map((o) => ({
queryKey: ["snapshot-check-isAddress", o.address],
queryFn: () => checkIsAddress({ item: o, thirdwebClient }),
queries: rawData.map((item) => ({
queryKey: ["snapshot-check-isAddress", item],
queryFn: () => checkIsAddress({ item: item, thirdwebClient }),
})),
combine: (results) => {
return {
Expand All @@ -149,6 +150,7 @@ export function useCsvUpload<
};
},
});

const removeInvalid = useCallback(() => {
const filteredData = normalizeQuery.data?.result.filter(
({ isValid }) => isValid,
Expand Down

0 comments on commit cb66be4

Please sign in to comment.