migrate useUsers hook to react-query (#674)
This commit is contained in:
parent
ace39ef73d
commit
aa554ca9f6
|
@ -1,32 +1,28 @@
|
|||
import { useState, useEffect } from 'react'
|
||||
import { PrivateUser, User } from 'common/user'
|
||||
import {
|
||||
listenForAllUsers,
|
||||
listenForPrivateUsers,
|
||||
} from 'web/lib/firebase/users'
|
||||
import { groupBy, sortBy, difference } from 'lodash'
|
||||
import { getContractsOfUserBets } from 'web/lib/firebase/bets'
|
||||
import { useFollows } from './use-follows'
|
||||
import { useUser } from './use-user'
|
||||
import { useFirestoreQueryData } from '@react-query-firebase/firestore'
|
||||
import { DocumentData } from 'firebase/firestore'
|
||||
import { users, privateUsers } from 'web/lib/firebase/users'
|
||||
|
||||
export const useUsers = () => {
|
||||
const [users, setUsers] = useState<User[]>([])
|
||||
|
||||
useEffect(() => {
|
||||
listenForAllUsers(setUsers)
|
||||
}, [])
|
||||
|
||||
return users
|
||||
const result = useFirestoreQueryData<DocumentData, User[]>(['users'], users, {
|
||||
subscribe: true,
|
||||
includeMetadataChanges: true,
|
||||
})
|
||||
return result.data ?? []
|
||||
}
|
||||
|
||||
export const usePrivateUsers = () => {
|
||||
const [users, setUsers] = useState<PrivateUser[]>([])
|
||||
|
||||
useEffect(() => {
|
||||
listenForPrivateUsers(setUsers)
|
||||
}, [])
|
||||
|
||||
return users
|
||||
const result = useFirestoreQueryData<DocumentData, PrivateUser[]>(
|
||||
['private users'],
|
||||
privateUsers,
|
||||
{ subscribe: true, includeMetadataChanges: true }
|
||||
)
|
||||
return result.data || []
|
||||
}
|
||||
|
||||
export const useDiscoverUsers = (userId: string | null | undefined) => {
|
||||
|
|
|
@ -258,16 +258,6 @@ export async function listAllUsers() {
|
|||
return docs.map((doc) => doc.data())
|
||||
}
|
||||
|
||||
export function listenForAllUsers(setUsers: (users: User[]) => void) {
|
||||
listenForValues(users, setUsers)
|
||||
}
|
||||
|
||||
export function listenForPrivateUsers(
|
||||
setUsers: (users: PrivateUser[]) => void
|
||||
) {
|
||||
listenForValues(privateUsers, setUsers)
|
||||
}
|
||||
|
||||
export function getTopTraders(period: Period) {
|
||||
const topTraders = query(
|
||||
users,
|
||||
|
|
Loading…
Reference in New Issue
Block a user