Skip to content

Commit b1f88e4

Browse files
add randomized button text
1 parent 22f2e2b commit b1f88e4

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

src/components/question-node.tsx

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,32 @@
33
import { useState } from "react"
44
import { motion, AnimatePresence } from "framer-motion"
55

6+
const POSITIVE_RESPONSES = [
7+
"Sounds Awesome!",
8+
"Yes, Please!",
9+
"Let's Do It!",
10+
"Count Me In!",
11+
"Absolutely!",
12+
"That's Perfect!",
13+
"I'm In!",
14+
"Show Me More!",
15+
]
16+
17+
const NEGATIVE_RESPONSES = [
18+
"Not on your life!",
19+
"No Thanks!",
20+
"Pass!",
21+
"Next Option!",
22+
"Not For Me!",
23+
"Skip This!",
24+
"Nope!",
25+
"Let's Try Something Else!",
26+
]
27+
28+
const getRandomItem = (array: string[]) => {
29+
return array[Math.floor(Math.random() * array.length)]
30+
}
31+
632
interface Node {
733
id: string
834
titleKey: string
@@ -14,6 +40,8 @@ interface Node {
1440
export function QuestionNode({ node }: { node: Node }) {
1541
const [currentNode, setCurrentNode] = useState(node)
1642
const [optionIndex, setOptionIndex] = useState(0)
43+
const [positiveButtonText, setPositiveButtonText] = useState(getRandomItem(POSITIVE_RESPONSES))
44+
const [negativeButtonText, setNegativeButtonText] = useState(getRandomItem(NEGATIVE_RESPONSES))
1745
const currentOption = currentNode.options?.[optionIndex]
1846

1947
return (
@@ -49,10 +77,12 @@ export function QuestionNode({ node }: { node: Node }) {
4977
} else if (currentOption.options) {
5078
setCurrentNode(currentOption)
5179
setOptionIndex(0)
80+
setPositiveButtonText(getRandomItem(POSITIVE_RESPONSES))
81+
setNegativeButtonText(getRandomItem(NEGATIVE_RESPONSES))
5282
}
5383
}}
5484
>
55-
Sounds Awesome!
85+
{positiveButtonText}
5686
</motion.button>
5787
<motion.button
5888
whileHover={{ scale: 1.02 }}
@@ -61,12 +91,14 @@ export function QuestionNode({ node }: { node: Node }) {
6191
onClick={() => {
6292
if (currentNode.options && optionIndex + 1 < currentNode.options.length) {
6393
setOptionIndex(optionIndex + 1)
94+
setPositiveButtonText(getRandomItem(POSITIVE_RESPONSES))
95+
setNegativeButtonText(getRandomItem(NEGATIVE_RESPONSES))
6496
} else {
6597
window.location.reload()
6698
}
6799
}}
68100
>
69-
Not on your life!
101+
{negativeButtonText}
70102
</motion.button>
71103
</div>
72104
</motion.div>

0 commit comments

Comments
 (0)