Check for confetti with interval

This commit is contained in:
Ian Philips 2022-04-28 15:22:05 -06:00
parent 0098718ebd
commit cc5862ff4a

View File

@ -35,7 +35,7 @@ import { DPM, FreeResponse, FullContract } from '../../../common/contract'
import { contractTextDetails } from '../../components/contract/contract-details' import { contractTextDetails } from '../../components/contract/contract-details'
import { useWindowSize } from '../../hooks/use-window-size' import { useWindowSize } from '../../hooks/use-window-size'
import Confetti from 'react-confetti' import Confetti from 'react-confetti'
import dayjs from 'dayjs'
export const getStaticProps = fromPropz(getStaticPropz) export const getStaticProps = fromPropz(getStaticPropz)
export async function getStaticPropz(props: { export async function getStaticPropz(props: {
params: { username: string; contractSlug: string } params: { username: string; contractSlug: string }
@ -92,6 +92,24 @@ export function ContractPageContent(props: FirstArgument<typeof ContractPage>) {
const contract = useContractWithPreload(props.contract) const contract = useContractWithPreload(props.contract)
const { bets, comments } = props const { bets, comments } = props
const [showConfetti, setShowConfetti] = useState(false)
useEffect(() => {
const timer = setInterval(() => {
const shouldSeeConfetti = !!(
user &&
contract &&
contract.creatorId === user.id &&
Date.now() - contract.createdTime < 10 * 1000
)
setShowConfetti(shouldSeeConfetti)
// Don't erase confetti mid-animation
if (shouldSeeConfetti) clearInterval(timer)
}, 1000)
return () => {
clearInterval(timer)
}
}, [contract, user])
// Sort for now to see if bug is fixed. // Sort for now to see if bug is fixed.
comments.sort((c1, c2) => c1.createdTime - c2.createdTime) comments.sort((c1, c2) => c1.createdTime - c2.createdTime)
@ -122,16 +140,14 @@ export function ContractPageContent(props: FirstArgument<typeof ContractPage>) {
return ( return (
<Page rightSidebar={rightSidebar}> <Page rightSidebar={rightSidebar}>
{user && {showConfetti && (
contract.creatorId === user.id && <Confetti
Date.now() - contract.createdTime < 10 * 1000 && ( width={width ? width : 500}
<Confetti height={height ? height : 500}
width={width ? width : 500} recycle={false}
height={height ? height : 500} numberOfPieces={300}
recycle={false} />
numberOfPieces={300} )}
/>
)}
{ogCardProps && ( {ogCardProps && (
<SEO <SEO