From b9119cb443dcbb38a39dd365605fea7512344cb4 Mon Sep 17 00:00:00 2001 From: tomas Date: Wed, 24 Jan 2024 12:28:40 +0000 Subject: [PATCH] add button to change stage background --- src/Header/Header.tsx | 66 ++++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 17 deletions(-) diff --git a/src/Header/Header.tsx b/src/Header/Header.tsx index 1a057db..f6b203f 100644 --- a/src/Header/Header.tsx +++ b/src/Header/Header.tsx @@ -67,11 +67,21 @@ const Header = () => { }, ] - const randomStage = useState( - possibleStageBackgrounds[ + const [currentStageIndex, setCurrentStageIndex] = useState( + Math.floor(Math.random() * possibleStageBackgrounds.length) + ) + + const nextStage = () => { + setCurrentStageIndex( + (prevIndex) => (prevIndex + 1) % possibleStageBackgrounds.length + ) + } + + useEffect(() => { + setCurrentStageIndex( Math.floor(Math.random() * possibleStageBackgrounds.length) - ] - )[0] + ) + }, []) return ( @@ -114,26 +124,48 @@ const Header = () => { width={stageWidth} height={stageHeight} options={{ backgroundAlpha: 0 }}> - {randomStage.stage} + {possibleStageBackgrounds[currentStageIndex].stage}
- - interaction by {randomStage.creator} - + + interaction by {possibleStageBackgrounds[currentStageIndex].creator} + + +
)