2021-07-21 22:04:23 +02:00
|
|
|
import React, { useEffect, useRef, useState } from "react";
|
2021-07-21 02:21:00 +02:00
|
|
|
import "../../App.css";
|
|
|
|
import Footer from "../../Footer";
|
|
|
|
import InputField from "../InputField";
|
|
|
|
import SubmitField from "../SubmitField";
|
|
|
|
import { Logger } from "@behametrics/logger-web";
|
|
|
|
import BehaviorStudyInfo from "../BehaviorStudyInfo";
|
|
|
|
import BehaviorNormal from "../BehaviorNormal";
|
2021-07-21 04:33:52 +02:00
|
|
|
import { Button } from "../Button";
|
2021-07-21 23:41:10 +02:00
|
|
|
import BehaviorPhone from "../BehaviorPhone";
|
|
|
|
import BehaviorStanding from "../BehaviorStanding";
|
2021-07-21 02:21:00 +02:00
|
|
|
|
|
|
|
export default function Study() {
|
2021-07-21 22:04:23 +02:00
|
|
|
const _logger = useRef(0);
|
2021-07-21 21:53:57 +02:00
|
|
|
|
|
|
|
useEffect(() => {
|
2021-07-21 22:04:23 +02:00
|
|
|
_logger.current = new Logger({
|
2021-07-21 21:53:57 +02:00
|
|
|
//inputs: ["cursor", "wheel", "keyboard", "touch"],
|
|
|
|
inputs: ["keyboard"],
|
|
|
|
// apiUrl: "https://behavior.marcocamenzind.ch",
|
|
|
|
apiUrl: "http://localhost:5000",
|
|
|
|
logToConsole: true,
|
|
|
|
});
|
2021-07-21 22:04:23 +02:00
|
|
|
_logger.current.init();
|
2021-07-21 21:53:57 +02:00
|
|
|
}, []);
|
|
|
|
|
2021-07-21 02:21:00 +02:00
|
|
|
let username = "";
|
|
|
|
const setUsername = (tmp_username) => {
|
|
|
|
username = tmp_username;
|
|
|
|
};
|
|
|
|
|
|
|
|
let password = "";
|
|
|
|
const setPassword = (tmp_password) => {
|
|
|
|
password = tmp_password;
|
|
|
|
};
|
|
|
|
|
2021-07-21 21:53:57 +02:00
|
|
|
const [isStepStart, setIsStepStart] = useState(true);
|
|
|
|
const [isStepNormal, setIsStepNormal] = useState(false);
|
2021-07-21 23:41:10 +02:00
|
|
|
const [isStepPhone, setIsStepPhone] = useState(false);
|
|
|
|
const [isStepStanding, setIsStepStanding] = useState(false);
|
|
|
|
const [isStepEnd, setIsStepEnd] = useState(false);
|
2021-07-21 02:21:00 +02:00
|
|
|
|
|
|
|
const handleLoggerOff = () => {
|
2021-07-21 22:04:23 +02:00
|
|
|
_logger.current.stop();
|
2021-07-21 02:21:00 +02:00
|
|
|
console.log("Logger ausgeschaltet");
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleLoggerOn = () => {
|
2021-07-21 22:04:23 +02:00
|
|
|
_logger.current.start();
|
2021-07-21 02:21:00 +02:00
|
|
|
console.log("start logging ");
|
|
|
|
};
|
|
|
|
|
|
|
|
const handlePasswordChange = (e) => {
|
|
|
|
setPassword(e.target.value);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleUsernameChange = (e) => {
|
|
|
|
setUsername(e.target.value);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleOnPasteEvent = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2021-07-21 23:41:10 +02:00
|
|
|
const handleClickAtStepStart = () => {
|
2021-07-21 04:33:52 +02:00
|
|
|
setIsStepStart(false);
|
|
|
|
setIsStepNormal(true);
|
2021-07-21 22:38:31 +02:00
|
|
|
handleLoggerOn();
|
2021-07-21 21:53:57 +02:00
|
|
|
// forceUpdate();
|
2021-07-21 04:33:52 +02:00
|
|
|
};
|
|
|
|
|
2021-07-21 23:41:10 +02:00
|
|
|
const handleClickAtStepNormal = () => {
|
|
|
|
setIsStepNormal(false);
|
|
|
|
setIsStepPhone(true);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleClickAtStepPhone = () => {
|
|
|
|
setIsStepPhone(false);
|
|
|
|
setIsStepStanding(true);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleClickAtStepStanding = () => {
|
|
|
|
setIsStepStanding(false);
|
|
|
|
setIsStepEnd(true);
|
|
|
|
handleLoggerOff();
|
|
|
|
};
|
|
|
|
|
2021-07-21 02:21:00 +02:00
|
|
|
const onSubmitClick = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
let opts = {
|
|
|
|
username: username,
|
|
|
|
password: password,
|
|
|
|
};
|
|
|
|
fetch("/api/protected/behavior", {
|
|
|
|
method: "post",
|
|
|
|
body: JSON.stringify(opts),
|
|
|
|
}).then((response) => {
|
|
|
|
console.log(response.status);
|
|
|
|
if (response.status === 401) {
|
|
|
|
response.json().then((resp) => {
|
|
|
|
console.log("nicht so wirklich gut");
|
|
|
|
// setErrorMessage(resp.message);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
response.json().then((token) => {
|
|
|
|
console.log("Alles gut :-)");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-07-21 23:41:10 +02:00
|
|
|
const study_start = (
|
|
|
|
<>
|
|
|
|
<BehaviorStudyInfo />
|
|
|
|
<Button
|
|
|
|
className="btns"
|
|
|
|
buttonStyle="btn--primary"
|
|
|
|
buttonSize="btn--full"
|
|
|
|
onClick={handleClickAtStepStart}
|
|
|
|
newTo="study"
|
|
|
|
>
|
|
|
|
Starten mit der Studie
|
|
|
|
</Button>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
const study_normal = (
|
|
|
|
<>
|
|
|
|
<BehaviorNormal />
|
|
|
|
<form id="behaviorNormal">
|
|
|
|
<InputField
|
|
|
|
LabelName="Benutzername"
|
|
|
|
onChange={handleUsernameChange}
|
|
|
|
InputType="text"
|
|
|
|
InputName="Benutzername"
|
|
|
|
InputPlaceHolder="Benutzername"
|
|
|
|
onPaste={handleOnPasteEvent}
|
|
|
|
/>
|
|
|
|
<InputField
|
|
|
|
LabelName="Passwort"
|
|
|
|
onChange={handlePasswordChange}
|
|
|
|
InputType="password"
|
|
|
|
InputName="Passwort"
|
|
|
|
InputPlaceHolder="Benutzername"
|
|
|
|
onPaste={handleOnPasteEvent}
|
|
|
|
/>
|
|
|
|
<SubmitField
|
|
|
|
LabelName="Weiter zur nächsten Situation"
|
|
|
|
InputValue="next-situation"
|
|
|
|
InputName="Weiter"
|
|
|
|
onClick={handleClickAtStepNormal}
|
|
|
|
/>
|
|
|
|
</form>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
const study_phone = (
|
|
|
|
<>
|
|
|
|
<BehaviorPhone />
|
|
|
|
<form id="behaviorPhone">
|
|
|
|
<InputField
|
|
|
|
LabelName="Benutzername"
|
|
|
|
onChange={handleUsernameChange}
|
|
|
|
InputType="text"
|
|
|
|
InputName="Benutzername"
|
|
|
|
InputPlaceHolder="Benutzername"
|
|
|
|
onPaste={handleOnPasteEvent}
|
|
|
|
/>
|
|
|
|
<InputField
|
|
|
|
LabelName="Passwort"
|
|
|
|
onChange={handlePasswordChange}
|
|
|
|
InputType="password"
|
|
|
|
InputName="Passwort"
|
|
|
|
InputPlaceHolder="Benutzername"
|
|
|
|
onPaste={handleOnPasteEvent}
|
|
|
|
/>
|
|
|
|
<SubmitField
|
|
|
|
LabelName="Weiter zur nächsten Situation"
|
|
|
|
InputValue="next-situation"
|
|
|
|
InputName="Weiter"
|
|
|
|
onClick={handleClickAtStepPhone}
|
|
|
|
/>
|
|
|
|
</form>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
const study_standing = (
|
|
|
|
<>
|
|
|
|
<BehaviorStanding />
|
|
|
|
<form id="behaviorPhone">
|
|
|
|
<InputField
|
|
|
|
LabelName="Benutzername"
|
|
|
|
onChange={handleUsernameChange}
|
|
|
|
InputType="text"
|
|
|
|
InputName="Benutzername"
|
|
|
|
InputPlaceHolder="Benutzername"
|
|
|
|
onPaste={handleOnPasteEvent}
|
|
|
|
/>
|
|
|
|
<InputField
|
|
|
|
LabelName="Passwort"
|
|
|
|
onChange={handlePasswordChange}
|
|
|
|
InputType="password"
|
|
|
|
InputName="Passwort"
|
|
|
|
InputPlaceHolder="Benutzername"
|
|
|
|
onPaste={handleOnPasteEvent}
|
|
|
|
/>
|
|
|
|
<SubmitField
|
|
|
|
LabelName="Studie beenden"
|
|
|
|
InputValue="stopStudy"
|
|
|
|
InputName="quit"
|
|
|
|
onClick={handleClickAtStepStanding}
|
|
|
|
/>
|
|
|
|
</form>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
const study_end = <p>Merci :-)</p>;
|
|
|
|
|
2021-07-21 02:21:00 +02:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className="sitePage">
|
|
|
|
<h1>Studie</h1>
|
2021-07-21 23:41:10 +02:00
|
|
|
{isStepStart ? study_start : null}
|
|
|
|
{isStepNormal ? study_normal : null}
|
|
|
|
{isStepPhone ? study_phone : null}
|
|
|
|
{isStepStanding ? study_standing : null}
|
|
|
|
{isStepEnd ? study_end : null}
|
2021-07-21 02:21:00 +02:00
|
|
|
</div>
|
|
|
|
<Footer />
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|