From add3df44f278341f043ac867848ed76312644146 Mon Sep 17 00:00:00 2001 From: Cesar Ibarra Date: Wed, 3 Jul 2019 20:22:24 -0700 Subject: [PATCH] Remove tutorialData from services and setup --- src/index.js | 10 ---------- src/services/index.js | 11 ++++------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/src/index.js b/src/index.js index c26204ea5..af8cb63e6 100644 --- a/src/index.js +++ b/src/index.js @@ -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([])); diff --git a/src/services/index.js b/src/services/index.js index 0f490a634..98ccfe89f 100644 --- a/src/services/index.js +++ b/src/services/index.js @@ -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) => { @@ -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 = { @@ -568,9 +567,6 @@ class OnlineChapterService { } class OfflineChapterService { - constructor() { - this.tutorialChapters = tutorialData.chapters; - } getChapterRecordsForUser(uid) { const { chapterRecords } = getLocalStorageVal("records"); @@ -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)); }) }