Finish Handler
This commit is contained in:
1 parent
4787a5fec1
commit
8c0836bae6
5 files changed
+32
-3
No files matched your search
@@ -13,6 +13,7 @@ import ChargedButton from "../ChargedButton";
|
||||
import { addCompletedRiddle } from "@/utils/completedRiddles";
|
||||
import { useLocalStorage } from "@/hooks/useLocalStorage";
|
||||
import { PREF } from "@/utils/const";
|
||||
import { setFinishedTime } from "@/utils/finishHandler";
|
||||
|
||||
export default function Riddle_9({
|
||||
page,
|
||||
@@ -127,6 +128,7 @@ export default function Riddle_9({
|
||||
</div>
|
||||
<div className={styles["buttons"]}>
|
||||
<ChargedButton red={false} disabled={false} onAction={() => {
|
||||
setFinishedTime(new Date());
|
||||
setScreenPage("3");
|
||||
}}>ERGEBNIS ANZEIGEN</ChargedButton>
|
||||
</div>
|
||||
|
||||
@@ -13,6 +13,7 @@ import VoiceOver from "../VoiceOver";
|
||||
import { VoiceOverMode } from "@/types/voiceOverMode";
|
||||
import { isDemoMode } from "@/utils/demoMode";
|
||||
import { finishSession } from "@/utils/sessionHandler";
|
||||
import { shouldReset } from "@/utils/finishHandler";
|
||||
|
||||
export default function Outro() {
|
||||
const [ tourCode, setTourCode ] = useLocalStorage(PREF.code, "");
|
||||
@@ -57,6 +58,13 @@ export default function Outro() {
|
||||
});
|
||||
}, [tourCode]);
|
||||
|
||||
useEffect(() => {
|
||||
if (shouldReset(new Date())) {
|
||||
localStorage.clear();
|
||||
setStep("0");
|
||||
}
|
||||
}, []);
|
||||
|
||||
const pages = [
|
||||
(
|
||||
<div className={styles["outro-video-container"]} key={0}>
|
||||
|
||||
@@ -125,8 +125,13 @@ export default function Tour() {
|
||||
"bought_hints": boughtHintsStr,
|
||||
"voice_over": voiceOverStr,
|
||||
"reached_riddles": reachedRiddlesStr,
|
||||
}, code);
|
||||
// TODO: Check if Code is valid.
|
||||
}, code)
|
||||
.then((res) => {
|
||||
if (res.status === 404) {
|
||||
localStorage.clear();
|
||||
setStep("0");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const intervalId = setInterval(() => {
|
||||
|
||||
+2
-1
@@ -11,10 +11,11 @@ export enum PREF {
|
||||
bought_hints = "PREF_BOUGHT_HINTS",
|
||||
demo_mode = "PREF_DEMO_MODE",
|
||||
reached_riddles = "PREF_REACHED_RIDDLES",
|
||||
finished_time = "PREF_FINISHED_TIME"
|
||||
};
|
||||
|
||||
const isDev = process.env.NODE_ENV === "development";
|
||||
|
||||
export const HTTP_SCHEME = isDev ? "http" : "https";
|
||||
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";
|
||||
@@ -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;
|
||||
}
|
||||
Reference in new issue
Block a user