Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add query staletime default #124

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Loading