2022-01-05 06:32:52 +00:00
|
|
|
import _ from 'lodash'
|
2021-12-17 04:44:48 +00:00
|
|
|
import { useEffect, useState } from 'react'
|
2022-01-05 06:32:52 +00:00
|
|
|
import {
|
|
|
|
Contract,
|
2022-02-25 08:11:10 +00:00
|
|
|
listenForActiveContracts,
|
2022-01-05 06:32:52 +00:00
|
|
|
listenForContracts,
|
2022-01-09 20:26:51 +00:00
|
|
|
listenForHotContracts,
|
2022-02-27 21:37:04 +00:00
|
|
|
listenForInactiveContracts,
|
2022-01-05 06:32:52 +00:00
|
|
|
} from '../lib/firebase/contracts'
|
2022-01-31 04:12:12 +00:00
|
|
|
import { listenForTaggedContracts } from '../lib/firebase/folds'
|
2021-12-17 04:44:48 +00:00
|
|
|
|
|
|
|
export const useContracts = () => {
|
2022-01-09 20:51:20 +00:00
|
|
|
const [contracts, setContracts] = useState<Contract[] | undefined>()
|
2021-12-17 04:44:48 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
return listenForContracts(setContracts)
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
return contracts
|
|
|
|
}
|
2022-01-05 06:32:52 +00:00
|
|
|
|
2022-02-25 08:11:10 +00:00
|
|
|
export const useActiveContracts = () => {
|
|
|
|
const [contracts, setContracts] = useState<Contract[] | undefined>()
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
return listenForActiveContracts(setContracts)
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
return contracts
|
|
|
|
}
|
|
|
|
|
2022-02-27 21:37:04 +00:00
|
|
|
export const useInactiveContracts = () => {
|
|
|
|
const [contracts, setContracts] = useState<Contract[] | undefined>()
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
return listenForInactiveContracts(setContracts)
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
return contracts
|
|
|
|
}
|
|
|
|
|
2022-01-31 04:12:12 +00:00
|
|
|
export const useTaggedContracts = (tags: string[] | undefined) => {
|
|
|
|
const [contracts, setContracts] = useState<Contract[] | undefined>(
|
|
|
|
tags && tags.length === 0 ? [] : undefined
|
|
|
|
)
|
|
|
|
const tagsKey = tags?.map((tag) => tag.toLowerCase()).join(',') ?? ''
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!tags || tags.length === 0) return
|
|
|
|
return listenForTaggedContracts(tags, setContracts)
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, [tagsKey])
|
|
|
|
|
|
|
|
return contracts
|
|
|
|
}
|
|
|
|
|
2022-01-05 06:32:52 +00:00
|
|
|
export const useHotContracts = () => {
|
2022-01-09 20:26:51 +00:00
|
|
|
const [hotContracts, setHotContracts] = useState<Contract[] | undefined>()
|
2022-01-05 06:32:52 +00:00
|
|
|
|
2022-01-09 20:26:51 +00:00
|
|
|
useEffect(() => listenForHotContracts(setHotContracts), [])
|
2022-01-05 06:32:52 +00:00
|
|
|
|
2022-01-09 20:26:51 +00:00
|
|
|
return hotContracts
|
2022-01-05 06:32:52 +00:00
|
|
|
}
|