Skip to content

Commit

Permalink
refactor: use sdk without provider
Browse files Browse the repository at this point in the history
  • Loading branch information
beeman committed Aug 6, 2024
1 parent d538704 commit 04a3beb
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 58 deletions.
1 change: 1 addition & 0 deletions libs/sdk/src/lib/get-graphql-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ import { getGraphQLClient } from './get-graphql-client'
export function getGraphQLSdk(url: string): Sdk {
return getSdk(getGraphQLClient(url))
}
export const sdk: Sdk = getGraphQLSdk('/graphql')
6 changes: 2 additions & 4 deletions libs/web/auth/data-access/src/lib/auth.provider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { LoginInput, RegisterInput, User } from '@pubkey-stack/sdk'
import { useSdk } from '@pubkey-stack/web-core-data-access'
import { LoginInput, RegisterInput, sdk, User } from '@pubkey-stack/sdk'
import { toastError, toastSuccess } from '@pubkey-ui/core'
import { createContext, ReactNode, useContext, useEffect, useReducer } from 'react'
import { useMe } from './use-me'
Expand Down Expand Up @@ -62,8 +61,7 @@ function authReducer(state: AuthState, { type, payload }: AuthAction): AuthState
}

export function AuthProvider({ children }: { children: ReactNode }) {
const sdk = useSdk()
const me = useMe(sdk)
const me = useMe()

const [state, dispatch] = useReducer(authReducer, { status: 'loading' })

Expand Down
4 changes: 2 additions & 2 deletions libs/web/auth/data-access/src/lib/use-me.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Sdk } from '@pubkey-stack/sdk'
import { sdk } from '@pubkey-stack/sdk'
import { useQuery } from '@tanstack/react-query'

export function useMe(sdk: Sdk) {
export function useMe() {
return useQuery({
queryKey: ['me'],
queryFn: async () => {
Expand Down
1 change: 0 additions & 1 deletion libs/web/core/data-access/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './lib/app-config.provider'
export * from './lib/sdk-provider'
14 changes: 0 additions & 14 deletions libs/web/core/data-access/src/lib/sdk-provider.tsx

This file was deleted.

14 changes: 6 additions & 8 deletions libs/web/core/feature/src/lib/web-core-providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import '@pubkey-ui/core'
import '@pubkey-ui/core/index.esm.css'
import 'mantine-datatable/styles.layer.css'
import { AuthProvider } from '@pubkey-stack/web-auth-data-access'
import { AppConfigProvider, SdkProvider } from '@pubkey-stack/web-core-data-access'
import { AppConfigProvider } from '@pubkey-stack/web-core-data-access'
import { SolanaClusterProvider } from '@pubkey-stack/web-solana-data-access'
import { toastError, UiTheme, UiThemeProvider } from '@pubkey-ui/core'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
Expand All @@ -23,13 +23,11 @@ export function WebCoreProviders({ children, theme }: { children: ReactNode; the
return (
<UiThemeProvider link={({ children, ...props }) => <Link {...props}>{children}</Link>} theme={theme}>
<QueryClientProvider client={client}>
<SdkProvider>
<AppConfigProvider>
<AuthProvider>
<SolanaClusterProvider>{children}</SolanaClusterProvider>
</AuthProvider>
</AppConfigProvider>
</SdkProvider>
<AppConfigProvider>
<AuthProvider>
<SolanaClusterProvider>{children}</SolanaClusterProvider>
</AuthProvider>
</AppConfigProvider>
</QueryClientProvider>
</UiThemeProvider>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { IdentityProvider } from '@pubkey-stack/sdk'
import { useSdk } from '@pubkey-stack/web-core-data-access'
import { IdentityProvider, sdk } from '@pubkey-stack/sdk'
import { toastError, toastSuccess } from '@pubkey-ui/core'
import { useWallet } from '@solana/wallet-adapter-react'
import { createContext, ReactNode, useContext } from 'react'
Expand All @@ -17,7 +16,6 @@ export interface IdentityProviderSolanaContext {
const Context = createContext<IdentityProviderSolanaContext>({} as IdentityProviderSolanaContext)

export function IdentityProviderSolanaLink({ children, refresh }: { children: ReactNode; refresh: () => void }) {
const sdk = useSdk()
const { signMessage } = useWallet()
const createSignature = useCreateSignature()
async function linkIdentity({ publicKey }: { publicKey: string }) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { IdentityProvider } from '@pubkey-stack/sdk'
import { useSdk } from '@pubkey-stack/web-core-data-access'
import { IdentityProvider, sdk } from '@pubkey-stack/sdk'
import { toastError, toastSuccess } from '@pubkey-ui/core'
import { useWallet } from '@solana/wallet-adapter-react'
import { createContext, ReactNode, useContext } from 'react'
Expand All @@ -13,7 +12,6 @@ export interface IdentityProviderSolanaLoginContext {
const Context = createContext<IdentityProviderSolanaLoginContext>({} as IdentityProviderSolanaLoginContext)

export function IdentityProviderSolanaLogin({ children, refresh }: { children: ReactNode; refresh: () => void }) {
const sdk = useSdk()
const { signMessage } = useWallet()
const createSignature = useCreateSignature()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { modals } from '@mantine/modals'
import { Identity, IdentityAdminCreateInput, IdentityAdminFindManyInput, IdentityProvider } from '@pubkey-stack/sdk'
import { useSdk } from '@pubkey-stack/web-core-data-access'
import {
Identity,
IdentityAdminCreateInput,
IdentityAdminFindManyInput,
IdentityProvider,
sdk,
} from '@pubkey-stack/sdk'
import { toastError, toastSuccess } from '@pubkey-ui/core'
import { useQuery } from '@tanstack/react-query'
import { useState } from 'react'

export function useAdminFindManyIdentity({ ownerId, provider }: { ownerId?: string; provider?: IdentityProvider }) {
const sdk = useSdk()

const [input] = useState<IdentityAdminFindManyInput>({
ownerId: ownerId,
provider: provider,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { Identity, IdentityProvider, IdentityUserFindManyInput } from '@pubkey-stack/sdk'
import { useSdk } from '@pubkey-stack/web-core-data-access'
import { Identity, IdentityProvider, IdentityUserFindManyInput, sdk } from '@pubkey-stack/sdk'
import { toastError, toastSuccess } from '@pubkey-ui/core'
import { useQuery } from '@tanstack/react-query'
import { useMemo } from 'react'

export function useUserFindManyIdentity({ username }: { username: string }) {
const sdk = useSdk()
const input: IdentityUserFindManyInput = useMemo(() => ({ username }), [username])
const query = useQuery({
queryKey: ['user', 'find-many-identity', input],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { UserAdminCreateInput, UserAdminFindManyInput, UserRole, UserStatus } from '@pubkey-stack/sdk'
import { useSdk } from '@pubkey-stack/web-core-data-access'
import { sdk, UserAdminCreateInput, UserAdminFindManyInput, UserRole, UserStatus } from '@pubkey-stack/sdk'
import { toastError, toastSuccess } from '@pubkey-ui/core'
import { useQuery } from '@tanstack/react-query'
import { useState } from 'react'

export function useAdminFindManyUser(props?: UserAdminFindManyInput) {
const sdk = useSdk()
const [role, setRole] = useState<UserRole | undefined>(undefined)
const [status, setStatus] = useState<UserStatus | undefined>(undefined)
const [limit, setLimit] = useState(props?.limit ?? 10)
Expand Down
4 changes: 1 addition & 3 deletions libs/web/user/data-access/src/lib/use-admin-find-one-user.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { UserAdminUpdateInput } from '@pubkey-stack/sdk'
import { useSdk } from '@pubkey-stack/web-core-data-access'
import { sdk, UserAdminUpdateInput } from '@pubkey-stack/sdk'
import { toastError, toastSuccess } from '@pubkey-ui/core'
import { useQuery } from '@tanstack/react-query'

export function useAdminFindOneUser({ userId }: { userId: string }) {
const sdk = useSdk()
const query = useQuery({
queryKey: ['admin', 'find-one-user', userId],
queryFn: () => sdk.adminFindOneUser({ userId }).then((res) => res.data),
Expand Down
4 changes: 1 addition & 3 deletions libs/web/user/data-access/src/lib/use-user-find-many-user.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { UserUserFindManyInput } from '@pubkey-stack/sdk'
import { useSdk } from '@pubkey-stack/web-core-data-access'
import { sdk, UserUserFindManyInput } from '@pubkey-stack/sdk'
import { useQuery } from '@tanstack/react-query'
import { useState } from 'react'

export function useUserFindManyUser(props?: UserUserFindManyInput) {
const sdk = useSdk()
const [limit, setLimit] = useState(props?.limit ?? 10)
const [page, setPage] = useState(props?.page ?? 1)
const [search, setSearch] = useState<string>('')
Expand Down
3 changes: 1 addition & 2 deletions libs/web/user/data-access/src/lib/use-user-fine-one-user.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { useSdk } from '@pubkey-stack/web-core-data-access'
import { sdk } from '@pubkey-stack/sdk'
import { useQuery } from '@tanstack/react-query'

export function useUserFineOneUser({ username }: { username: string }) {
const sdk = useSdk()
const query = useQuery({
queryKey: ['user', 'find-one-user', username],
queryFn: () => sdk.userFindOneUser({ username }).then((res) => res.data),
Expand Down
6 changes: 2 additions & 4 deletions libs/web/user/data-access/src/lib/use-user-profile.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { UserUserUpdateInput } from '@pubkey-stack/sdk'
import { sdk, UserUserUpdateInput } from '@pubkey-stack/sdk'
import { useAuth, useMe } from '@pubkey-stack/web-auth-data-access'
import { useSdk } from '@pubkey-stack/web-core-data-access'
import { toastError, toastSuccess } from '@pubkey-ui/core'
import { useUserFineOneUser } from './use-user-fine-one-user'

export function useUserProfile() {
const sdk = useSdk()
const me = useMe(sdk)
const me = useMe()
const { user } = useAuth()
const { query } = useUserFineOneUser({ username: user?.username as string })

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,6 @@
"*.{js,json,css,scss,md,ts,tsx,html,graphql}": [
"pnpm nx format --uncommitted"
]
}
},
"packageManager": "[email protected]+sha256.dae0f7e822c56b20979bb5965e3b73b8bdabb6b8b8ef121da6d857508599ca35"
}

0 comments on commit 04a3beb

Please sign in to comment.