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 { useLayoutEffect, useState } from 'react'
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
import { FreeResponseContract } from 'common/contract'
|
||||
import { Col } from '../layout/col'
|
||||
|
@ -85,7 +85,7 @@ export function AnswersPanel(props: { contract: FreeResponseContract }) {
|
|||
})
|
||||
}
|
||||
|
||||
useLayoutEffect(() => {
|
||||
useEffect(() => {
|
||||
setChosenAnswers({})
|
||||
}, [resolveOption])
|
||||
|
||||
|
|
|
@ -18,10 +18,12 @@ export const useContract = (contractId: string) => {
|
|||
return result.isLoading ? undefined : result.data
|
||||
}
|
||||
|
||||
export const useContractWithPreload = (initial: Contract | null) => {
|
||||
const [contract, setContract] = useStateCheckEquality<Contract | null>(
|
||||
initial
|
||||
)
|
||||
export const useContractWithPreload = (
|
||||
initial: Contract | null | undefined
|
||||
) => {
|
||||
const [contract, setContract] = useStateCheckEquality<
|
||||
Contract | null | undefined
|
||||
>(initial)
|
||||
const contractId = initial?.id
|
||||
|
||||
useEffect(() => {
|
||||
|
|
|
@ -9,6 +9,7 @@ import { ContractSearch } from 'web/components/contract-search'
|
|||
import { Contract } from 'common/contract'
|
||||
import { ContractPageContent } from './[username]/[contractSlug]'
|
||||
import { getContractFromSlug } from 'web/lib/firebase/contracts'
|
||||
import { useContractWithPreload } from 'web/hooks/use-contract'
|
||||
|
||||
const Home = () => {
|
||||
const user = useUser()
|
||||
|
@ -104,7 +105,9 @@ const useContractPage = () => {
|
|||
if (contract) window.scrollTo(0, 0)
|
||||
}, [contract])
|
||||
|
||||
return [contract, setContract] as const
|
||||
const updatedContract = useContractWithPreload(contract)
|
||||
|
||||
return [updatedContract, setContract] as const
|
||||
}
|
||||
|
||||
export default Home
|
||||
|
|
Loading…
Reference in New Issue
Block a user