2021-05-25 00:08:56 +00:00
|
|
|
import React, { useContext } from 'react'
|
2021-11-28 17:29:17 +00:00
|
|
|
import { useQuery } from '@apollo/client'
|
|
|
|
import { ME } from '../fragments/users'
|
2021-05-25 00:08:56 +00:00
|
|
|
|
|
|
|
export const MeContext = React.createContext({
|
|
|
|
me: null
|
|
|
|
})
|
|
|
|
|
2021-11-28 17:29:17 +00:00
|
|
|
export function MeProvider ({ me, children }) {
|
|
|
|
const { data } = useQuery(ME, { pollInterval: 1000 })
|
2021-05-25 00:08:56 +00:00
|
|
|
|
|
|
|
const contextValue = {
|
2021-11-28 17:29:17 +00:00
|
|
|
me: data ? data.me : me
|
2021-05-25 00:08:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<MeContext.Provider value={contextValue}>
|
|
|
|
{children}
|
|
|
|
</MeContext.Provider>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function useMe () {
|
|
|
|
const { me } = useContext(MeContext)
|
|
|
|
return me
|
|
|
|
}
|