2021-12-09 22:44:04 +00:00
|
|
|
import { collection, onSnapshot, doc } from '@firebase/firestore'
|
|
|
|
import { db } from './init'
|
|
|
|
|
|
|
|
export type Contract = {
|
|
|
|
id: string
|
2021-12-10 06:21:12 +00:00
|
|
|
creatorId: string
|
|
|
|
creatorName: string
|
2021-12-09 22:44:04 +00:00
|
|
|
question: string
|
2021-12-10 06:21:12 +00:00
|
|
|
description: string
|
2021-12-09 22:44:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const contractCollection = collection(db, 'contracts')
|
|
|
|
|
|
|
|
export function listenForContract(
|
|
|
|
contractId: string,
|
|
|
|
setContract: (contract: Contract) => void
|
|
|
|
) {
|
|
|
|
const contractRef = doc(contractCollection, contractId)
|
|
|
|
|
|
|
|
return onSnapshot(contractRef, (contractSnap) => {
|
|
|
|
setContract(contractSnap.data() as Contract)
|
|
|
|
})
|
|
|
|
}
|