From c587ebcce79fcfc2d73969b9dcfa4690e8002204 Mon Sep 17 00:00:00 2001 From: mildrrnt Date: Fri, 12 Jan 2024 14:37:24 +0700 Subject: [PATCH] feat: choices and result logic --- src/components/story/Score.tsx | 17 +++++ src/components/story/TapLast.tsx | 40 ++++++++++++ .../story/\340\270\272ButtonScore.tsx" | 2 +- src/pages/story/1.astro | 20 ------ src/pages/story/4.astro | 7 --- src/pages/story/Q1.astro | 31 ++++++++++ src/pages/story/Q10.astro | 15 +++++ src/pages/story/Q2.astro | 15 +++++ src/pages/story/Q3A.astro | 31 ++++++++++ src/pages/story/Q3B.astro | 31 ++++++++++ src/pages/story/Q3C.astro | 37 +++++++++++ src/pages/story/Q4.astro | 17 +++++ src/pages/story/Q5.astro | 45 ++++++++++++++ src/pages/story/Q6.astro | 39 ++++++++++++ src/pages/story/{2.astro => Q7.astro} | 62 +++++++++---------- src/pages/story/Q8.astro | 25 ++++++++ src/pages/story/Q9.astro | 31 ++++++++++ src/pages/story/Scene10.astro | 9 +++ src/pages/story/Scene14.astro | 9 +++ src/pages/story/{3.astro => Scene3.astro} | 18 +++--- src/pages/story/Scene4.astro | 9 +++ src/pages/story/Scene5.astro | 9 +++ src/pages/story/Scene6.astro | 9 +++ src/pages/story/Scene7.astro | 9 +++ src/pages/story/Scene8.astro | 9 +++ src/pages/story/Scene9.astro | 9 +++ 26 files changed, 487 insertions(+), 68 deletions(-) create mode 100644 src/components/story/Score.tsx create mode 100644 src/components/story/TapLast.tsx delete mode 100644 src/pages/story/1.astro delete mode 100644 src/pages/story/4.astro create mode 100644 src/pages/story/Q1.astro create mode 100644 src/pages/story/Q10.astro create mode 100644 src/pages/story/Q2.astro create mode 100644 src/pages/story/Q3A.astro create mode 100644 src/pages/story/Q3B.astro create mode 100644 src/pages/story/Q3C.astro create mode 100644 src/pages/story/Q4.astro create mode 100644 src/pages/story/Q5.astro create mode 100644 src/pages/story/Q6.astro rename src/pages/story/{2.astro => Q7.astro} (55%) create mode 100644 src/pages/story/Q8.astro create mode 100644 src/pages/story/Q9.astro create mode 100644 src/pages/story/Scene10.astro create mode 100644 src/pages/story/Scene14.astro rename src/pages/story/{3.astro => Scene3.astro} (83%) create mode 100644 src/pages/story/Scene4.astro create mode 100644 src/pages/story/Scene5.astro create mode 100644 src/pages/story/Scene6.astro create mode 100644 src/pages/story/Scene7.astro create mode 100644 src/pages/story/Scene8.astro create mode 100644 src/pages/story/Scene9.astro diff --git a/src/components/story/Score.tsx b/src/components/story/Score.tsx new file mode 100644 index 0000000..fae4ab1 --- /dev/null +++ b/src/components/story/Score.tsx @@ -0,0 +1,17 @@ +import scores from "../../store/score.ts"; +const score = scores.get(); + +const Score = () => { + return ( +
+

{score[0]}

+

{score[1]}

+

{score[2]}

+

{score[3]}

+

{score[4]}

+

{score[5]}

+
+ ); +}; + +export default Score; diff --git a/src/components/story/TapLast.tsx b/src/components/story/TapLast.tsx new file mode 100644 index 0000000..1264e32 --- /dev/null +++ b/src/components/story/TapLast.tsx @@ -0,0 +1,40 @@ +import scores from "../../store/score.ts"; +const score = scores.get(); +const url = { + 0: "../cocktail/sangria", + 1: "../cocktail/cosmopolitan", + 2: "../cocktail/pinacolada", + 3: "../cocktail/ginandtonic", + 4: "../cocktail/bluelagoon", + 5: "../cocktail/lavenderlemonade", +}; + +const TapLast = () => { + const handleEvents = () => { + console.log(score); + let maxKey: string; + const scoreMap: { [key: string]: number } = score; + const maxScore = Math.max(...Object.values(scoreMap)); + Object.keys(scoreMap).forEach((key) => { + if (scoreMap[key] === maxScore) { + maxKey = key; + } + }); + location.href = url[maxKey]; + }; + + return ( +
+

+ Tap to +
+ continue +

+
+ ); +}; + +export default TapLast; diff --git "a/src/components/story/\340\270\272ButtonScore.tsx" "b/src/components/story/\340\270\272ButtonScore.tsx" index a7e1454..adb5469 100644 --- "a/src/components/story/\340\270\272ButtonScore.tsx" +++ "b/src/components/story/\340\270\272ButtonScore.tsx" @@ -14,7 +14,7 @@ const ButtonScore = ({ text, scoreArray, redirect }: Props) => { return (