2022-01-16 03:09:15 +00:00
|
|
|
import { useState, useEffect } from 'react'
|
2022-01-24 06:48:06 +00:00
|
|
|
import { PrivateUser, User } from '../../common/user'
|
2022-03-21 01:07:45 +00:00
|
|
|
import {
|
|
|
|
getUser,
|
|
|
|
listenForAllUsers,
|
|
|
|
listenForPrivateUsers,
|
|
|
|
} from '../lib/firebase/users'
|
2022-01-16 03:09:15 +00:00
|
|
|
|
|
|
|
export const useUsers = () => {
|
|
|
|
const [users, setUsers] = useState<User[]>([])
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
listenForAllUsers(setUsers)
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
return users
|
|
|
|
}
|
2022-01-24 06:48:06 +00:00
|
|
|
|
2022-03-21 01:07:45 +00:00
|
|
|
export const useUserById = (userId: string) => {
|
|
|
|
const [user, setUser] = useState<User | undefined>(undefined)
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
getUser(userId).then(setUser)
|
|
|
|
}, [userId])
|
|
|
|
|
|
|
|
return user
|
|
|
|
}
|
|
|
|
|
2022-01-24 06:48:06 +00:00
|
|
|
export const usePrivateUsers = () => {
|
|
|
|
const [users, setUsers] = useState<PrivateUser[]>([])
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
listenForPrivateUsers(setUsers)
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
return users
|
|
|
|
}
|