Skip to content

Commit

Permalink
refactor: add query staletime default (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnshift authored Mar 26, 2024
1 parent 999ecd7 commit 4565569
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/filters/hooks/use-filter-config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from '@tanstack/react-query';

import { RouteSection } from '~/shared/core/constants';
import { QUERY_STALETIME, RouteSection } from '~/shared/core/constants';

import { filterQueryKeys } from '~/filters/core/query-keys';
import { sanitizeFilterParams } from '~/filters/utils/sanitizeFilterParams';
Expand All @@ -13,6 +13,7 @@ export const useFilterConfig = (
const query = useQuery({
queryKey: filterQueryKeys.list(searchParams, routeSection),
queryFn: () => getFilterConfig(`/${routeSection}`),
staleTime: QUERY_STALETIME.DEFAULT,
// Filter show-flag and then sort by position
select: (data) =>
Object.values(data)
Expand Down
3 changes: 3 additions & 0 deletions src/jobs/hooks/use-job-details.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { useQuery } from '@tanstack/react-query';

import { QUERY_STALETIME } from '~/shared/core/constants';

import { jobQueryKeys } from '~/jobs/core/query-keys';
import { getJobDetails } from '~/jobs/api/get-job-details';

export const useJobDetails = (id: string) => {
return useQuery({
queryKey: jobQueryKeys.details(id),
queryFn: () => getJobDetails(id),
staleTime: QUERY_STALETIME.DEFAULT,
});
};
3 changes: 3 additions & 0 deletions src/jobs/hooks/use-job-list-query.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { InfiniteData, useInfiniteQuery } from '@tanstack/react-query';

import { QUERY_STALETIME } from '~/shared/core/constants';

import { JobQueryKeys, jobQueryKeys } from '~/jobs/core/query-keys';
import { JobListQueryPage } from '~/jobs/core/schemas';
import { getJobList } from '~/jobs/api/get-job-list';
Expand All @@ -21,5 +23,6 @@ export const useJobListQuery = () => {
initialPageParam: 1,
getNextPageParam: ({ page, data }) =>
page > 0 && data.length > 0 ? page + 1 : undefined,
staleTime: QUERY_STALETIME.DEFAULT,
});
};
3 changes: 3 additions & 0 deletions src/orgs/hooks/use-org-details.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { useQuery } from '@tanstack/react-query';

import { QUERY_STALETIME } from '~/shared/core/constants';

import { orgQueryKeys } from '~/orgs/core/query-keys';
import { getOrgDetails } from '~/orgs/api/get-org-details';

export const useOrgDetails = (orgId: string) => {
return useQuery({
queryKey: orgQueryKeys.details(orgId),
queryFn: () => getOrgDetails(orgId),
staleTime: QUERY_STALETIME.DEFAULT,
});
};
3 changes: 3 additions & 0 deletions src/orgs/hooks/use-org-list-query.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { InfiniteData, useInfiniteQuery } from '@tanstack/react-query';

import { QUERY_STALETIME } from '~/shared/core/constants';

import { OrgQueryKeys, orgQueryKeys } from '~/orgs/core/query-keys';
import { OrgListQueryPage } from '~/orgs/core/schemas';
import { getOrgList } from '~/orgs/api/get-org-list';
Expand All @@ -21,5 +23,6 @@ export const useOrgListQuery = () => {
initialPageParam: 1,
getNextPageParam: ({ page, data }) =>
page > 0 && data.length > 0 ? page + 1 : undefined,
staleTime: QUERY_STALETIME.DEFAULT,
});
};
4 changes: 4 additions & 0 deletions src/shared/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ export const METADATA = {
TWITTER_CREATOR: '@jobstash_xyz',
IMAGE_DIMENSION: { width: 1100, height: 576 } as const,
} as const;

export const QUERY_STALETIME = {
DEFAULT: 1000 * 60 * 60, // 1 hr
} as const;

0 comments on commit 4565569

Please sign in to comment.