Change usePrivateUser
hook to use the auth context data
This commit is contained in:
parent
50aff668dd
commit
3cc7bd2135
|
@ -31,7 +31,7 @@ export function GroupChat(props: {
|
|||
}) {
|
||||
const { messages, user, group, tips } = props
|
||||
|
||||
const privateUser = usePrivateUser(user?.id)
|
||||
const privateUser = usePrivateUser()
|
||||
|
||||
const { editor, upload } = useTextEditor({
|
||||
simple: true,
|
||||
|
|
|
@ -44,7 +44,7 @@ export function BottomNavBar() {
|
|||
const currentPage = router.pathname
|
||||
|
||||
const user = useUser()
|
||||
const privateUser = usePrivateUser(user?.id)
|
||||
const privateUser = usePrivateUser()
|
||||
|
||||
const isIframe = useIsIframe()
|
||||
if (isIframe) {
|
||||
|
|
|
@ -221,7 +221,7 @@ export default function Sidebar(props: { className?: string }) {
|
|||
const currentPage = router.pathname
|
||||
|
||||
const user = useUser()
|
||||
const privateUser = usePrivateUser(user?.id)
|
||||
const privateUser = usePrivateUser()
|
||||
// usePing(user?.id)
|
||||
|
||||
const navigationOptions = !user ? signedOutNavigation : getNavigation()
|
||||
|
|
|
@ -2,15 +2,14 @@ import { BellIcon } from '@heroicons/react/outline'
|
|||
import clsx from 'clsx'
|
||||
import { Row } from 'web/components/layout/row'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { usePrivateUser, useUser } from 'web/hooks/use-user'
|
||||
import { usePrivateUser } from 'web/hooks/use-user'
|
||||
import { useRouter } from 'next/router'
|
||||
import { useUnseenPreferredNotificationGroups } from 'web/hooks/use-notifications'
|
||||
import { NOTIFICATIONS_PER_PAGE } from 'web/pages/notifications'
|
||||
import { PrivateUser } from 'common/user'
|
||||
|
||||
export default function NotificationsIcon(props: { className?: string }) {
|
||||
const user = useUser()
|
||||
const privateUser = usePrivateUser(user?.id)
|
||||
const privateUser = usePrivateUser()
|
||||
|
||||
return (
|
||||
<Row className={clsx('justify-center')}>
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import { isAdmin } from 'common/envs/constants'
|
||||
import { usePrivateUser, useUser } from './use-user'
|
||||
import { usePrivateUser } from './use-user'
|
||||
|
||||
export const useAdmin = () => {
|
||||
const user = useUser()
|
||||
const privateUser = usePrivateUser(user?.id)
|
||||
const privateUser = usePrivateUser()
|
||||
return isAdmin(privateUser?.email || '')
|
||||
}
|
||||
|
|
|
@ -1,15 +1,9 @@
|
|||
import { useContext, useEffect, useState } from 'react'
|
||||
import { useContext } from 'react'
|
||||
import { useFirestoreDocumentData } from '@react-query-firebase/firestore'
|
||||
import { QueryClient } from 'react-query'
|
||||
|
||||
import { doc, DocumentData, where } from 'firebase/firestore'
|
||||
import { PrivateUser } from 'common/user'
|
||||
import {
|
||||
getUser,
|
||||
listenForPrivateUser,
|
||||
User,
|
||||
users,
|
||||
} from 'web/lib/firebase/users'
|
||||
import { doc, DocumentData } from 'firebase/firestore'
|
||||
import { getUser, User, users } from 'web/lib/firebase/users'
|
||||
import { AuthContext } from 'web/components/auth-context'
|
||||
|
||||
export const useUser = () => {
|
||||
|
@ -17,16 +11,9 @@ export const useUser = () => {
|
|||
return authUser ? authUser.user : authUser
|
||||
}
|
||||
|
||||
export const usePrivateUser = (userId?: string) => {
|
||||
const [privateUser, setPrivateUser] = useState<
|
||||
PrivateUser | null | undefined
|
||||
>(undefined)
|
||||
|
||||
useEffect(() => {
|
||||
if (userId) return listenForPrivateUser(userId, setPrivateUser)
|
||||
}, [userId])
|
||||
|
||||
return privateUser
|
||||
export const usePrivateUser = () => {
|
||||
const authUser = useContext(AuthContext)
|
||||
return authUser ? authUser.privateUser : authUser
|
||||
}
|
||||
|
||||
export const useUserById = (userId = '_') => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user