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