Skip to content

Commit

Permalink
disable query if provider is not github
Browse files Browse the repository at this point in the history
  • Loading branch information
icedevera committed May 6, 2024
1 parent f5dcb35 commit 4f71588
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/components/sections/GitHub/GithubFileSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const GithubFileSelect = ({

const {data: repoFilesData, isLoading: repoFilesIsLoading} = useGetRepoFiles(
selectedRepo ?? undefined,
session.data?.user.provider,
)

if (session.data?.user.provider !== 'github') {
Expand Down
2 changes: 1 addition & 1 deletion src/components/sections/GitHub/GithubRepoSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const GithubRepoSelect = ({selectedRepo, onSelectRepo}: GithubRepoSelect) => {
const session = useSession()

const {data: publicReposData, isLoading: publicReposIsLoading} =
useGetPublicRepos()
useGetPublicRepos(session.data?.user.provider)

if (session.data?.user.provider !== 'github') {
return (
Expand Down
17 changes: 13 additions & 4 deletions src/lib/queries/github/getGitHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ const getPublicReposQueryOptions = (userId: string | undefined) => ({
queryFn: withApiErrorHandler(() => getPublicRepos()),
})

export const useGetPublicRepos = () => {
export const useGetPublicRepos = (provider: string | undefined) => {
const userId = useUserId()

return useQuery({...getPublicReposQueryOptions(userId), enabled: !!userId})
return useQuery({
...getPublicReposQueryOptions(userId),
enabled: !!userId && provider === 'github',
})
}

const getRepoFilesQueryOptions = (params: GetRepoFilesParams | undefined) => ({
Expand All @@ -32,5 +35,11 @@ const getRepoFilesQueryOptions = (params: GetRepoFilesParams | undefined) => ({
}),
})

export const useGetRepoFiles = (params: GetRepoFilesParams | undefined) =>
useQuery({...getRepoFilesQueryOptions(params), enabled: !!params})
export const useGetRepoFiles = (
params: GetRepoFilesParams | undefined,
provider: string | undefined,
) =>
useQuery({
...getRepoFilesQueryOptions(params),
enabled: !!params && provider === 'github',
})

0 comments on commit 4f71588

Please sign in to comment.