Skip to content

Commit

Permalink
Remove tutorialData from services and setup
Browse files Browse the repository at this point in the history
  • Loading branch information
francesar committed Jul 4, 2019
1 parent 847fc2f commit add3df4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
10 changes: 0 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ import {createSuperUser} from './services/superuser';
import './style/styles.scss';
import './style/index.scss';

/**
* If the app is online, we keep one reference to the lessons and chapters
* to avoid reintantiating it multiple times throughout the app
*/
export let tutorialData = {}
if (process.env.REACT_APP_ENV === "offline") {
tutorialData.lessons = lessons;
tutorialData.chapters = chapters;
}

export function initLocalStorage() {
localStorage.setItem("hasBeenSetup", true);
localStorage.setItem("users", JSON.stringify([]));
Expand Down
11 changes: 4 additions & 7 deletions src/services/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import axios from "axios";
import uuid from "uuid";

import {api_url} from "../constants";
import {tutorialData} from "..";
import {applyTextTransformer} from "../middleware/requestTextConverter";

const sendPostReq = (url, data) => {
Expand Down Expand Up @@ -303,8 +302,8 @@ class OnlineTutorialService {

class OfflineTutorialService {
constructor() {
this.lessons = tutorialData.lessons;
this.chapters = tutorialData.chapters;
this.lessons = getLocalStorageVal("lessons");
this.chapters = getLocalStorageVal("chapters");
}

lastLessonInChapter = {
Expand Down Expand Up @@ -568,9 +567,6 @@ class OnlineChapterService {
}

class OfflineChapterService {
constructor() {
this.tutorialChapters = tutorialData.chapters;
}

getChapterRecordsForUser(uid) {
const { chapterRecords } = getLocalStorageVal("records");
Expand All @@ -580,8 +576,9 @@ class OfflineChapterService {
}

getChapterProgressPercentage(uid) {
const chapters = getLocalStorageVal("chapters");
return new Promise((res, rej) => {
res(Number(this.getChapterRecordsForUser(uid).length / this.tutorialChapters.length));
res(Number(this.getChapterRecordsForUser(uid).length / chapters.length));
})
}

Expand Down

0 comments on commit add3df4

Please sign in to comment.