feat: Implement the tracker
This commit is contained in:
@@ -54,6 +54,19 @@ export default class Application extends React.Component<IProps> {
|
||||
}
|
||||
|
||||
checkAuthStatus = (token: string): Promise<IUser> => {
|
||||
// Track the end of a review
|
||||
console.log("Sending trcaker request");
|
||||
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",
|
||||
}),
|
||||
});
|
||||
|
||||
return new Promise((res, rej) => {
|
||||
fetch(`${BACKEND_URL}/api/user/me`, {
|
||||
headers: new Headers({
|
||||
@@ -128,6 +141,18 @@ export default class Application extends React.Component<IProps> {
|
||||
}).then(resp => resp.json(), err => {
|
||||
console.log("Application::setLastReview: POSTing last results failed");
|
||||
});
|
||||
|
||||
// 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",
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
getReviewQueue = (): Promise<IVocab[]> => {
|
||||
@@ -256,6 +281,18 @@ 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",
|
||||
}),
|
||||
});
|
||||
|
||||
return new Promise((res, rej) => {
|
||||
fetch(`${BACKEND_URL}/api/login`, {
|
||||
method: "POST",
|
||||
@@ -288,6 +325,18 @@ 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",
|
||||
}),
|
||||
});
|
||||
|
||||
// NOTE: No promise, since we don't care about the result
|
||||
fetch(`${BACKEND_URL}/api/user/logout`, {
|
||||
headers: new Headers({
|
||||
|
||||
Reference in New Issue
Block a user