Skip to content

Commit

Permalink
Improvements of react-query queryKey params
Browse files Browse the repository at this point in the history
Co-authored-by: mab <benjamin.marguin@makina-corpus.com>
  • Loading branch information
dtrucs and mabhub committed Jul 18, 2024
1 parent f9a5b12 commit 889b81d
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const useActivitySearchFilter = () => {
const language = useRouter().locale ?? getDefaultLanguage();
const { data: activities } = useQuery<ActivityFilter[], Error>({
queryKey: ['homeActivities', language],

queryFn: () => getActivityBarContent(language, activityBar.links),
});

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/pages/details/useDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const useDetails = (
const parentIdString = isUrlString(parentId) ? parentId : '';
const { data: trekFamily } = useQuery<TrekFamily | null, Error>({
queryKey: ['trekFamily', parentIdString, language],
queryFn: () => getTrekFamily(isUrlString(parentId) ? parentId : '', language),
queryFn: () => getTrekFamily(parentIdString, language),
enabled: isUrlString(parentId),
staleTime: ONE_DAY,
});
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/pages/flatPage/useFlatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const useFlatPage = (flatPageUrl: string | undefined) => {
);

const { data: activitySuggestions = [] } = useQuery<ActivitySuggestion[] | [], Error>({
queryKey: ['activitySuggestions', ...activitySuggestionIds, id, language],
queryKey: ['activitySuggestions', activitySuggestionIds, language],
queryFn: () => getActivitySuggestions(suggestions, language, commonDictionaries),
enabled: suggestions.length > 0 && commonDictionaries !== undefined,
});
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/pages/home/useHome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const useHome = (): UseHome => {
const commonDictionaries = useQueryCommonDictionaries(language);

const { data = [] } = useQuery<ActivitySuggestion[] | [], Error>({
queryKey: ['activitySuggestions', `Suggestion-${activitySuggestionIds.join('-')}`, language],
queryKey: ['activitySuggestions', activitySuggestionIds, language],
queryFn: () => getActivitySuggestions(suggestions, language, commonDictionaries),
enabled: suggestions.length > 0 && commonDictionaries !== undefined,
});
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/pages/search/hooks/useTrekResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ export const useTrekResults = (
} = useInfiniteQuery<SearchResults, Error>({
queryKey: [
'trekResults',
JSON.stringify(parsedFiltersState),
parsedFiltersState,
language,
parseTextFilter(textFilterState),
parseBboxFilter(bboxState),
JSON.stringify(dateFilter),
dateFilter,
page,
],
queryFn: ({
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const getServerSideProps: GetServerSideProps = async context => {
);

await queryClient.prefetchQuery({
queryKey: ['activitySuggestions', `Suggestion-${activitySuggestionIds.join('-')}`, locale],
queryKey: ['activitySuggestions', activitySuggestionIds, locale],
queryFn: () => getActivitySuggestions(suggestions, locale, commonDictionaries),
});
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/information/[flatPage].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const getServerSideProps: GetServerSideProps = async context => {
);

await queryClient.prefetchQuery({
queryKey: ['activitySuggestions', ...activitySuggestionIds, id, locale],
queryKey: ['activitySuggestions', activitySuggestionIds, locale],
queryFn: () => getActivitySuggestions(suggestions, locale, commonDictionaries),
});

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ export const getServerSideProps: GetServerSideProps = async context => {
await queryClient.prefetchInfiniteQuery({
queryKey: [
'trekResults',
JSON.stringify(parsedInitialFiltersState),
parsedInitialFiltersState,
context.locale,
initialTextFilter,
bboxFilter,
JSON.stringify(dateFilter),
dateFilter,
page,
],
queryFn: () =>
Expand Down

0 comments on commit 889b81d

Please sign in to comment.