9a4e5763f5
* basic market categories * use tags to store market category * display category in market * display full category * category selector component on feed * Move feed data fetching to new file * Decrease batch size for updating feed to prevent out-of-memory error * Compute and update category feeds! * Show feeds based on category tabs * Add react-query package! * Use react query to cache contracts * Remove 'other' category * Add back personal / friends to feed categories * Show scrollbar temporarily for categories * Remove 5 categories, change geopolitics to world * finance => economics * Show categories on two lines on larger screens Co-authored-by: James Grugett <jahooma@gmail.com>
33 lines
957 B
TypeScript
33 lines
957 B
TypeScript
import { useEffect } from 'react'
|
|
import { useFirestoreDocumentData } from '@react-query-firebase/firestore'
|
|
import {
|
|
Contract,
|
|
contractDocRef,
|
|
listenForContract,
|
|
} from 'web/lib/firebase/contracts'
|
|
import { useStateCheckEquality } from './use-state-check-equality'
|
|
import { DocumentData } from 'firebase/firestore'
|
|
|
|
export const useContract = (contractId: string) => {
|
|
const result = useFirestoreDocumentData<DocumentData, Contract>(
|
|
['contracts', contractId],
|
|
contractDocRef(contractId),
|
|
{ subscribe: true, includeMetadataChanges: true }
|
|
)
|
|
|
|
return result.isLoading ? undefined : result.data
|
|
}
|
|
|
|
export const useContractWithPreload = (initial: Contract | null) => {
|
|
const [contract, setContract] = useStateCheckEquality<Contract | null>(
|
|
initial
|
|
)
|
|
const contractId = initial?.id
|
|
|
|
useEffect(() => {
|
|
if (contractId) return listenForContract(contractId, setContract)
|
|
}, [contractId, setContract])
|
|
|
|
return contract
|
|
}
|