Finish Method
This commit is contained in:
1 parent
c70141b26a
commit
ff6f3e6f4f
3 files changed
+31
-2
No files matched your search
@@ -2,7 +2,7 @@ import { useLocalStorage } from "@/hooks/useLocalStorage"
|
||||
import { PREF } from "@/utils/const"
|
||||
import ChargedButton from "../ChargedButton";
|
||||
import styles from "@/css/Outro.module.css";
|
||||
import { ChangeEvent, InputEvent, MouseEvent, MouseEventHandler, PointerEvent, useMemo, useRef, useState } from "react";
|
||||
import { ChangeEvent, InputEvent, MouseEvent, MouseEventHandler, PointerEvent, useEffect, useMemo, useRef, useState } from "react";
|
||||
import Image from "next/image";
|
||||
import StyledContainer from "../StyledContainer";
|
||||
import OldButton from "../OldButton";
|
||||
@@ -12,8 +12,10 @@ import { getPoints } from "@/utils/points";
|
||||
import VoiceOver from "../VoiceOver";
|
||||
import { VoiceOverMode } from "@/types/voiceOverMode";
|
||||
import { isDemoMode } from "@/utils/demoMode";
|
||||
import { finishSession } from "@/utils/sessionHandler";
|
||||
|
||||
export default function Outro() {
|
||||
const [ tourCode, setTourCode ] = useLocalStorage(PREF.code, "");
|
||||
const [ resultPage, setResultPage ] = useState(0);
|
||||
const [ stepStr, setStep ] = useLocalStorage(PREF.step, "0");
|
||||
const [ pointsStr, setPoints ] = useLocalStorage(PREF.points, "0");
|
||||
@@ -37,6 +39,24 @@ export default function Outro() {
|
||||
return true;
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!tourCode || tourCode.length === 0 || demoMode) {
|
||||
return;
|
||||
}
|
||||
|
||||
finishSession(tourCode).then((res) => {
|
||||
if (!res.ok) {
|
||||
finishSession(tourCode).finally(() => {
|
||||
setTourCode("");
|
||||
});
|
||||
} else {
|
||||
setTourCode("");
|
||||
}
|
||||
}).catch(() => {
|
||||
setTourCode("");
|
||||
});
|
||||
}, [tourCode]);
|
||||
|
||||
const pages = [
|
||||
(
|
||||
<div className={styles["outro-video-container"]} key={0}>
|
||||
|
||||
+1
-1
@@ -16,4 +16,4 @@ 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";
|
||||
@@ -29,4 +29,13 @@ export function setSessionData(data: SessionData) {
|
||||
localStorage.setItem(PREF.points, data.points);
|
||||
localStorage.setItem(PREF.bought_hints, data.bought_hints);
|
||||
localStorage.setItem(PREF.voice_over, data.voice_over);
|
||||
}
|
||||
|
||||
export async function finishSession(code: string): Promise<Response> {
|
||||
return await fetch(`${HTTP_SCHEME}://${API_PREFIX}/sessions/finish?code=${code}`,
|
||||
{
|
||||
"method": "PATCH",
|
||||
"cache": "no-cache"
|
||||
}
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user