Finish Handler

This commit is contained in:
LionTion committed 2026-12-02 15:01:26 +01:00
1 parent 4787a5fec1
commit 8c0836bae6
5 files changed
+32 -3

No files matched your search

+2
View File
@@ -13,6 +13,7 @@ import ChargedButton from "../ChargedButton";
import { addCompletedRiddle } from "@/utils/completedRiddles"; import { addCompletedRiddle } from "@/utils/completedRiddles";
import { useLocalStorage } from "@/hooks/useLocalStorage"; import { useLocalStorage } from "@/hooks/useLocalStorage";
import { PREF } from "@/utils/const"; import { PREF } from "@/utils/const";
import { setFinishedTime } from "@/utils/finishHandler";
export default function Riddle_9({ export default function Riddle_9({
page, page,
@@ -127,6 +128,7 @@ export default function Riddle_9({
</div> </div>
<div className={styles["buttons"]}> <div className={styles["buttons"]}>
<ChargedButton red={false} disabled={false} onAction={() => { <ChargedButton red={false} disabled={false} onAction={() => {
setFinishedTime(new Date());
setScreenPage("3"); setScreenPage("3");
}}>ERGEBNIS ANZEIGEN</ChargedButton> }}>ERGEBNIS ANZEIGEN</ChargedButton>
</div> </div>
+8
View File
@@ -13,6 +13,7 @@ import VoiceOver from "../VoiceOver";
import { VoiceOverMode } from "@/types/voiceOverMode"; import { VoiceOverMode } from "@/types/voiceOverMode";
import { isDemoMode } from "@/utils/demoMode"; import { isDemoMode } from "@/utils/demoMode";
import { finishSession } from "@/utils/sessionHandler"; import { finishSession } from "@/utils/sessionHandler";
import { shouldReset } from "@/utils/finishHandler";
export default function Outro() { export default function Outro() {
const [ tourCode, setTourCode ] = useLocalStorage(PREF.code, ""); const [ tourCode, setTourCode ] = useLocalStorage(PREF.code, "");
@@ -57,6 +58,13 @@ export default function Outro() {
}); });
}, [tourCode]); }, [tourCode]);
useEffect(() => {
if (shouldReset(new Date())) {
localStorage.clear();
setStep("0");
}
}, []);
const pages = [ const pages = [
( (
<div className={styles["outro-video-container"]} key={0}> <div className={styles["outro-video-container"]} key={0}>
+7 -2
View File
@@ -125,8 +125,13 @@ export default function Tour() {
"bought_hints": boughtHintsStr, "bought_hints": boughtHintsStr,
"voice_over": voiceOverStr, "voice_over": voiceOverStr,
"reached_riddles": reachedRiddlesStr, "reached_riddles": reachedRiddlesStr,
}, code); }, code)
// TODO: Check if Code is valid. .then((res) => {
if (res.status === 404) {
localStorage.clear();
setStep("0");
}
});
}; };
const intervalId = setInterval(() => { const intervalId = setInterval(() => {
+2 -1
View File
@@ -11,10 +11,11 @@ export enum PREF {
bought_hints = "PREF_BOUGHT_HINTS", bought_hints = "PREF_BOUGHT_HINTS",
demo_mode = "PREF_DEMO_MODE", demo_mode = "PREF_DEMO_MODE",
reached_riddles = "PREF_REACHED_RIDDLES", reached_riddles = "PREF_REACHED_RIDDLES",
finished_time = "PREF_FINISHED_TIME"
}; };
const isDev = process.env.NODE_ENV === "development"; const isDev = process.env.NODE_ENV === "development";
export const HTTP_SCHEME = isDev ? "http" : "https"; export const HTTP_SCHEME = isDev ? "http" : "https";
export const WS_SCHEME = isDev ? "ws" : "wss"; export const WS_SCHEME = isDev ? "ws" : "wss";
export const API_PREFIX = isDev ? "192.168.0.110:8080" : "api.excaliburs-erben.de"; export const API_PREFIX = isDev ? "localhost:8080" : "api.excaliburs-erben.de";
+13
View File
@@ -0,0 +1,13 @@
import { PREF } from "./const";
export function setFinishedTime(date: Date) {
localStorage.setItem(PREF.finished_time, date.toISOString());
window.dispatchEvent(new Event('storage'));
}
export function shouldReset(currentTime: Date): boolean {
const finishedTimeStr = localStorage.getItem(PREF.finished_time);
if (finishedTimeStr === null) return false;
const finishedTime = new Date(finishedTimeStr);
return (currentTime - finishedTime) > 1000*60*60*8;
}