RiddleHintPage
This commit is contained in:
1 parent
4a6a9595d4
commit
662d8023bb
18 files changed
+212
-17
No files matched your search
@@ -1,3 +1,103 @@
|
||||
import styles from "@/css/RiddleHintPage.module.css";
|
||||
"use client";
|
||||
|
||||
// TODO: this shit
|
||||
import styles from "@/css/RiddleHintPage.module.css";
|
||||
import { useLocalStorage } from "@/hooks/useLocalStorage";
|
||||
import { Riddle } from "@/types/riddle";
|
||||
import { PREF } from "@/utils/const";
|
||||
import clsx from "clsx";
|
||||
import { useMemo, useState } from "react";
|
||||
import OldButton from "./OldButton";
|
||||
import { addBoughtHint, getBoughtHints } from "@/utils/boughtHints";
|
||||
import OldPopUp from "./OldPopUp";
|
||||
import { getPoints, takePoints } from "@/utils/points";
|
||||
|
||||
interface RiddleHintProps {
|
||||
riddle: Riddle;
|
||||
onSkip?: (() => void) | null;
|
||||
dismissHintPage: () => void;
|
||||
};
|
||||
|
||||
export default function RiddleHintPage({
|
||||
riddle,
|
||||
onSkip,
|
||||
dismissHintPage
|
||||
}: RiddleHintProps) {
|
||||
const [ pointsStr, ] = useLocalStorage(PREF.points, "");
|
||||
const [ boughtHintsStr, ] = useLocalStorage(PREF.boughtHints, "");
|
||||
const [ showBuyHint, setShowBuyHint ] = useState(false);
|
||||
const [ showSkipRiddle, setShowSkipRiddle ] = useState(false);
|
||||
|
||||
const boughtHints = useMemo(() => {
|
||||
return getBoughtHints();
|
||||
}, [boughtHintsStr]);
|
||||
|
||||
const points = useMemo(() => {
|
||||
return getPoints();
|
||||
}, [pointsStr]);
|
||||
|
||||
const sortedHints = useMemo(() => {
|
||||
return [...riddle.hints].sort((a, b) => a.hintOrder - b.hintOrder);
|
||||
}, [riddle.hints]);
|
||||
|
||||
const boughtHintObjects = useMemo(() => {
|
||||
return sortedHints.filter(h => boughtHints.includes(h.id));
|
||||
}, [sortedHints, boughtHints]);
|
||||
|
||||
const nextHintToBuy = useMemo(() => {
|
||||
return sortedHints.find(h => !boughtHints.includes(h.id));
|
||||
}, [sortedHints, boughtHints]);
|
||||
|
||||
console.log(boughtHints);
|
||||
|
||||
return (
|
||||
<div className={clsx(styles["container"])}>
|
||||
<div className={styles["header"]}>
|
||||
<img src={"/icons/hinweis-dunkel.svg"} className={styles["hint-icon"]}/>
|
||||
<p className={clsx(styles["hint-p"], "eisenkraft-regular")}>Hinweise</p>
|
||||
</div>
|
||||
{ nextHintToBuy && nextHintToBuy.penaltyPoints > 0 && <p>Ein {boughtHintObjects.length > 0 ? "weiterer" : ""} Hinweis kostet euch {nextHintToBuy.penaltyPoints} Rufpunkte.</p> }
|
||||
{ nextHintToBuy && nextHintToBuy.penaltyPoints === 0 && <p>Ein {boughtHintObjects.length > 0 ? "weiterer" : ""} Hinweis kostet euch zum Glück keine Rufpunkte.</p> }
|
||||
{ riddle.hints.length === 0 && <p>Für das Rätsel gibt es keine Hinweise!</p> }
|
||||
{ riddle.skipPenaltyPoints === 0 && <p>Überspringt ihr das Rätsel, bekommt ihr keine Rufpunkte.</p> }
|
||||
{ riddle.skipPenaltyPoints > 0 && <p>Überspringt ihr das Rätsel, bekommt ihr {riddle.skipPenaltyPoints} Rufpunkte abgezogen.</p> }
|
||||
{ riddle.skipPenaltyPoints < 0 && <p>Das Rätsel kann nicht übersprungen werden!</p> }
|
||||
<div className="center-flex">
|
||||
{ nextHintToBuy && <OldButton red={false} onAction={() => setShowBuyHint(true)} style={{marginBottom: "1rem"}}>HINWEIS KAUFEN</OldButton> }
|
||||
</div>
|
||||
{boughtHintObjects.map((hint, index) => (
|
||||
<div key={hint.id}>
|
||||
<p><strong>Hinweis {index + 1}:</strong> <br></br>{hint.hint}</p>
|
||||
</div>
|
||||
))}
|
||||
<div className="center-flex">
|
||||
{ riddle.skipPenaltyPoints > -1 && <OldButton red={true} onAction={() => setShowSkipRiddle(true)} style={{marginTop: "1rem"}}>RÄTSEL ÜBERSPRINGEN</OldButton> }
|
||||
</div>
|
||||
{ (showBuyHint || showSkipRiddle) && <div className={clsx(styles["popup"])}>
|
||||
{ showBuyHint && nextHintToBuy &&
|
||||
<OldPopUp onDismiss={() => setShowBuyHint(false)}>
|
||||
<div className="center-flex">
|
||||
<p>Möchtet ihr diesen Hinweis für {nextHintToBuy.penaltyPoints} Rufpunkte kaufen?</p>
|
||||
<OldButton red={true} disabled={points >= nextHintToBuy.penaltyPoints} onAction={() => {
|
||||
addBoughtHint(nextHintToBuy.id);
|
||||
takePoints(nextHintToBuy.penaltyPoints);
|
||||
setShowBuyHint(false);
|
||||
}}>JA, KAUFEN!</OldButton>
|
||||
</div>
|
||||
</OldPopUp>
|
||||
}
|
||||
{ showSkipRiddle &&
|
||||
<OldPopUp onDismiss={() => setShowSkipRiddle(false)}>
|
||||
<div className="center-flex">
|
||||
<p>Wollt ihr das Rätsel wirklich überspringen?</p>
|
||||
<OldButton red={true} onAction={() => {
|
||||
dismissHintPage();
|
||||
if (onSkip) onSkip();
|
||||
//TODO: Add completeRiddle
|
||||
}}>JA, ÜBERSPRINGEN</OldButton>
|
||||
</div>
|
||||
</OldPopUp>
|
||||
}
|
||||
</div> }
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user