Check for confetti with interval
This commit is contained in:
parent
0098718ebd
commit
cc5862ff4a
|
@ -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,9 +140,7 @@ export function ContractPageContent(props: FirstArgument<typeof ContractPage>) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page rightSidebar={rightSidebar}>
|
<Page rightSidebar={rightSidebar}>
|
||||||
{user &&
|
{showConfetti && (
|
||||||
contract.creatorId === user.id &&
|
|
||||||
Date.now() - contract.createdTime < 10 * 1000 && (
|
|
||||||
<Confetti
|
<Confetti
|
||||||
width={width ? width : 500}
|
width={width ? width : 500}
|
||||||
height={height ? height : 500}
|
height={height ? height : 500}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user