stacker.news/components/me.js

44 lines
723 B
JavaScript
Raw Normal View History

2021-05-25 00:08:56 +00:00
import React, { useContext } from 'react'
import { gql, useQuery } from '@apollo/client'
export const MeContext = React.createContext({
me: null
})
export function MeProvider ({ children }) {
const query = gql`
{
me {
id
2021-09-07 17:52:59 +00:00
name
2021-05-25 00:08:56 +00:00
sats
stacked
freePosts
freeComments
2021-06-24 23:56:01 +00:00
hasNewNotes
2021-09-12 16:55:38 +00:00
tipDefault
2021-09-24 21:56:51 +00:00
bio {
id
}
2021-10-15 23:07:51 +00:00
hasInvites
2021-11-04 23:07:41 +00:00
theme
2021-05-25 00:08:56 +00:00
}
}`
const { data } = useQuery(query, { pollInterval: 1000 })
const contextValue = {
me: data ? data.me : null
}
return (
<MeContext.Provider value={contextValue}>
{children}
</MeContext.Provider>
)
}
export function useMe () {
const { me } = useContext(MeContext)
return me
}