Listen for contract updates when navigating from home to contract page. (#494)
This commit is contained in:
parent
68da02ec00
commit
f3d4827115
|
@ -1,5 +1,5 @@
|
||||||
import { sortBy, partition, sum, uniq } from 'lodash'
|
import { sortBy, partition, sum, uniq } from 'lodash'
|
||||||
import { useLayoutEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
|
|
||||||
import { FreeResponseContract } from 'common/contract'
|
import { FreeResponseContract } from 'common/contract'
|
||||||
import { Col } from '../layout/col'
|
import { Col } from '../layout/col'
|
||||||
|
@ -85,7 +85,7 @@ export function AnswersPanel(props: { contract: FreeResponseContract }) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useEffect(() => {
|
||||||
setChosenAnswers({})
|
setChosenAnswers({})
|
||||||
}, [resolveOption])
|
}, [resolveOption])
|
||||||
|
|
||||||
|
|
|
@ -18,10 +18,12 @@ export const useContract = (contractId: string) => {
|
||||||
return result.isLoading ? undefined : result.data
|
return result.isLoading ? undefined : result.data
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useContractWithPreload = (initial: Contract | null) => {
|
export const useContractWithPreload = (
|
||||||
const [contract, setContract] = useStateCheckEquality<Contract | null>(
|
initial: Contract | null | undefined
|
||||||
initial
|
) => {
|
||||||
)
|
const [contract, setContract] = useStateCheckEquality<
|
||||||
|
Contract | null | undefined
|
||||||
|
>(initial)
|
||||||
const contractId = initial?.id
|
const contractId = initial?.id
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import { ContractSearch } from 'web/components/contract-search'
|
||||||
import { Contract } from 'common/contract'
|
import { Contract } from 'common/contract'
|
||||||
import { ContractPageContent } from './[username]/[contractSlug]'
|
import { ContractPageContent } from './[username]/[contractSlug]'
|
||||||
import { getContractFromSlug } from 'web/lib/firebase/contracts'
|
import { getContractFromSlug } from 'web/lib/firebase/contracts'
|
||||||
|
import { useContractWithPreload } from 'web/hooks/use-contract'
|
||||||
|
|
||||||
const Home = () => {
|
const Home = () => {
|
||||||
const user = useUser()
|
const user = useUser()
|
||||||
|
@ -104,7 +105,9 @@ const useContractPage = () => {
|
||||||
if (contract) window.scrollTo(0, 0)
|
if (contract) window.scrollTo(0, 0)
|
||||||
}, [contract])
|
}, [contract])
|
||||||
|
|
||||||
return [contract, setContract] as const
|
const updatedContract = useContractWithPreload(contract)
|
||||||
|
|
||||||
|
return [updatedContract, setContract] as const
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Home
|
export default Home
|
||||||
|
|
Loading…
Reference in New Issue
Block a user