refactor: Move the tracking model into commons
This commit is contained in:
@@ -14,11 +14,13 @@ import SummaryPage from "../containers/SummaryPage";
|
||||
import WelcomePage from "../pages/intro";
|
||||
import RegisterPage from "../containers/Register";
|
||||
import VocabPage from "../containers/VocabPage";
|
||||
|
||||
import Drawer from "../containers/Drawer";
|
||||
|
||||
import { trackAction } from "../api/tracker";
|
||||
|
||||
import { BACKEND_URL } from "../config.in";
|
||||
|
||||
import { TrackerEvent } from "../models/tracker";
|
||||
import { ILevel } from "../models/level";
|
||||
import { TopTen } from "../models/learner";
|
||||
import { IVocab } from "../models/vocab";
|
||||
@@ -56,16 +58,7 @@ export default class Application extends React.Component<IProps> {
|
||||
|
||||
checkAuthStatus = (token: string): Promise<IUser> => {
|
||||
// Track the end of a review
|
||||
fetch(`${BACKEND_URL}/api/tracker`, {
|
||||
headers: new Headers({
|
||||
"Content-Type": "application/json",
|
||||
}),
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
session: window.sessionStorage.getItem("tracker_session"),
|
||||
event: "LOG_IN",
|
||||
}),
|
||||
});
|
||||
trackAction(TrackerEvent.LOG_IN);
|
||||
|
||||
return new Promise((res, rej) => {
|
||||
fetch(`${BACKEND_URL}/api/user/me`, {
|
||||
@@ -161,16 +154,7 @@ export default class Application extends React.Component<IProps> {
|
||||
});
|
||||
|
||||
// Track the end of a review
|
||||
fetch(`${BACKEND_URL}/api/tracker`, {
|
||||
headers: new Headers({
|
||||
"Content-Type": "application/json",
|
||||
}),
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
session: window.sessionStorage.getItem("tracker_session"),
|
||||
event: "FINISH_LEARNING",
|
||||
}),
|
||||
});
|
||||
trackAction(TrackerEvent.FINISH_LEARNING);
|
||||
}
|
||||
|
||||
getReviewQueue = (): Promise<IVocab[]> => {
|
||||
@@ -300,16 +284,7 @@ export default class Application extends React.Component<IProps> {
|
||||
|
||||
login = (username: string, password: string): Promise<IUser | IResponse> => {
|
||||
// Track the login
|
||||
fetch(`${BACKEND_URL}/api/tracker`, {
|
||||
headers: new Headers({
|
||||
"Content-Type": "application/json",
|
||||
}),
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
session: window.sessionStorage.getItem("tracker_session"),
|
||||
event: "LOG_IN",
|
||||
}),
|
||||
});
|
||||
trackAction(TrackerEvent.LOG_IN);
|
||||
|
||||
return new Promise((res, rej) => {
|
||||
fetch(`${BACKEND_URL}/api/login`, {
|
||||
@@ -344,16 +319,7 @@ export default class Application extends React.Component<IProps> {
|
||||
|
||||
logout = () => {
|
||||
// Track the logout
|
||||
fetch(`${BACKEND_URL}/api/tracker`, {
|
||||
headers: new Headers({
|
||||
"Content-Type": "application/json",
|
||||
}),
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
session: window.sessionStorage.getItem("tracker_session"),
|
||||
event: "LOG_OUT",
|
||||
}),
|
||||
});
|
||||
trackAction(TrackerEvent.LOG_OUT);
|
||||
|
||||
// NOTE: No promise, since we don't care about the result
|
||||
fetch(`${BACKEND_URL}/api/user/logout`, {
|
||||
|
||||
Reference in New Issue
Block a user