2022-02-11 17:24:33 +00:00
|
|
|
import { gql } from 'graphql-request'
|
|
|
|
|
import useSWR from 'swr'
|
2024-03-28 07:27:37 +00:00
|
|
|
import { Feature, featureFragment } from '../fragments/featureFragment'
|
2022-02-11 17:24:33 +00:00
|
|
|
import { publicGqlFetcher } from '../networkHelpers'
|
|
|
|
|
|
|
|
|
|
type ViewerQueryResponse = {
|
2024-03-18 07:00:12 +00:00
|
|
|
mutate: () => void
|
2022-02-11 17:24:33 +00:00
|
|
|
viewerData?: ViewerQueryResponseData
|
|
|
|
|
viewerDataError?: unknown
|
|
|
|
|
isLoading: boolean
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type ViewerQueryResponseData = {
|
|
|
|
|
me?: UserBasicData
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type UserBasicData = {
|
|
|
|
|
id: string
|
|
|
|
|
name: string
|
|
|
|
|
isFullUser?: boolean
|
|
|
|
|
profile: UserProfile
|
2023-10-02 14:21:50 +00:00
|
|
|
email: string
|
|
|
|
|
source: string
|
2023-10-27 08:13:03 +00:00
|
|
|
intercomHash: string
|
2024-03-28 07:27:37 +00:00
|
|
|
featureList: Feature[]
|
2022-02-11 17:24:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type UserProfile = {
|
|
|
|
|
id: string
|
|
|
|
|
username: string
|
|
|
|
|
pictureUrl?: string
|
|
|
|
|
bio?: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function useGetViewerQuery(): ViewerQueryResponse {
|
|
|
|
|
const query = gql`
|
|
|
|
|
query Viewer {
|
|
|
|
|
me {
|
|
|
|
|
id
|
|
|
|
|
name
|
|
|
|
|
isFullUser
|
|
|
|
|
profile {
|
|
|
|
|
id
|
|
|
|
|
username
|
|
|
|
|
pictureUrl
|
|
|
|
|
bio
|
|
|
|
|
}
|
2023-10-02 14:21:50 +00:00
|
|
|
email
|
|
|
|
|
source
|
2023-10-27 08:13:03 +00:00
|
|
|
intercomHash
|
2024-03-28 07:27:37 +00:00
|
|
|
featureList {
|
|
|
|
|
...FeatureFields
|
|
|
|
|
}
|
2022-02-11 17:24:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
2024-03-28 07:27:37 +00:00
|
|
|
${featureFragment}
|
2022-02-11 17:24:33 +00:00
|
|
|
`
|
|
|
|
|
|
2024-03-18 07:00:12 +00:00
|
|
|
const { data, error, mutate } = useSWR(query, publicGqlFetcher)
|
2022-02-11 17:24:33 +00:00
|
|
|
|
|
|
|
|
return {
|
2024-03-18 07:00:12 +00:00
|
|
|
mutate,
|
2022-02-11 17:24:33 +00:00
|
|
|
viewerData: data as ViewerQueryResponseData,
|
|
|
|
|
viewerDataError: error, // TODO: figure out error possibilities
|
|
|
|
|
isLoading: !error && !data,
|
|
|
|
|
}
|
|
|
|
|
}
|