refactor: Move the tracking model into commons

This commit is contained in:
Alexander Polynomdivision
2018-10-15 16:30:40 +02:00
parent 2963e089d8
commit 22ded2ec38
7 changed files with 59 additions and 63 deletions

View File

@@ -20,6 +20,9 @@ import { withRouter } from "react-router-dom";
import VocabularyData from "../components/VocabularyData";
import { TrackerEvent } from "../models/tracker";
import { trackAction } from "../api/tracker";
import { IVocab, VocabType } from "../models/vocab";
interface IProps {
@@ -100,6 +103,10 @@ const LevelPageWithRouter = withRouter(
}
cancelLevel = () => {
// Track the cancellation of a level
trackAction(TrackerEvent.CANCEL_LEARNING);
// Close the dialog and go to the dashboard
this.closeLeave();
this.props.history.push("/dashboard");
}

View File

@@ -27,6 +27,9 @@ import {
} from "../models/vocab";
import { ReviewType, IReviewMetadata } from "../models/review";
import { TrackerEvent } from "../models/tracker";
import { trackAction } from "../api/tracker";
//@ts-ignore
import lev from "js-levenshtein";
import {
@@ -104,16 +107,7 @@ const ReviewPageWithRouter = withRouter(
}[reviewType];
// Track the start of a session
fetch(`${BACKEND_URL}/api/tracker`, {
headers: new Headers({
"Content-Type": "application/json",
}),
method: "POST",
body: JSON.stringify({
session: window.sessionStorage.getItem("tracker_session"),
event: "START_LEARNING",
}),
});
trackAction(TrackerEvent.START_LEARNING);
getVocab().then((res: IVocab[]) => {
// Check if we received any vocabulary
@@ -158,16 +152,7 @@ const ReviewPageWithRouter = withRouter(
this.closeDialog();
// Track the cancellation of a learning session
fetch(`${BACKEND_URL}/api/tracker`, {
headers: new Headers({
"Content-Type": "application/json",
}),
method: "POST",
body: JSON.stringify({
session: window.sessionStorage.getItem("tracker_session"),
event: "CANCEL_LEARNING",
}),
});
trackAction(TrackerEvent.CANCEL_LEARNING);
// Show the drawer button again
this.props.drawerButtonState(true);