Skip to content

Commit

Permalink
useSession in useQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
icedevera committed May 6, 2024
1 parent 2b42965 commit 68e5486
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/components/sections/GitHub/GithubFileSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ 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(session.data?.user.provider)
useGetPublicRepos()

if (session.data?.user.provider !== 'github') {
return (
Expand Down
18 changes: 10 additions & 8 deletions src/lib/queries/github/getGitHub.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {useQuery} from '@tanstack/react-query'
import {useSession} from 'next-auth/react'

import {queryKeys} from '../keys'

Expand All @@ -15,12 +16,13 @@ const getPublicReposQueryOptions = (userId: string | undefined) => ({
queryFn: withApiErrorHandler(() => getPublicRepos()),
})

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

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

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

export const useGetRepoFiles = (
params: GetRepoFilesParams | undefined,
provider: string | undefined,
) =>
useQuery({
export const useGetRepoFiles = (params: GetRepoFilesParams | undefined) => {
const session = useSession()

return useQuery({
...getRepoFilesQueryOptions(params),
enabled: !!params && provider === 'github',
enabled: !!params && session.data?.user.provider === 'github',
})
}

0 comments on commit 68e5486

Please sign in to comment.