From 49055248c7df1d7032d645570cafe003d9d2674a Mon Sep 17 00:00:00 2001 From: digvijay26 Date: Wed, 24 Feb 2021 14:52:01 +0530 Subject: [PATCH] offline synching --- src/auth/index.js | 27 +++- src/components/AuthorIntro.vue | 135 ++++++++++++++++++- src/components/AuthorReadingBreak.vue | 137 ++++++++++++++++++- src/components/AuthorReadingNow.vue | 136 ++++++++++++++++++- src/components/EpisodeIntro.vue | 142 +++++++++++++++++++- src/components/Header.vue | 40 ++++-- src/components/NoScreenshotSingleAuthor.vue | 168 ++++++++++++++++++++++-- src/components/Profile.vue | 2 +- src/components/SingleMobileScreenInsightOne.vue | 156 +++++++++++++++++++++- src/components/SingleMobileScreenInsightTwo.vue | 160 +++++++++++++++++++++- src/components/TwoScreenWithInsight.vue | 155 +++++++++++++++++++++- src/components/TwoScreenWithoutInsight.vue | 153 ++++++++++++++++++++- src/components/noscreenshotSingleautho.vue | 156 +++++++++++++++++++++- src/components/outro.vue | 137 ++++++++++++++++++- 14 files changed, 1641 insertions(+), 63 deletions(-) diff --git a/src/auth/index.js b/src/auth/index.js index 67460a4..f4ab903 100644 --- a/src/auth/index.js +++ b/src/auth/index.js @@ -115,7 +115,7 @@ export const useAuth0 = ({ // handle the redirect and retrieve tokens const { appState } = await this.auth0Client.handleRedirectCallback(); const u = await this.auth0Client.getUser(); - console.log("u",u) + console.log("u", u) axios.post('/profile', { name: u.name, email: u.email, @@ -124,12 +124,29 @@ export const useAuth0 = ({ verified: true // profileImage: u.picture }).then(res => { - console.log("res",res); + console.log("res", res); this.$toaster.success(res.data.message); localStorage.setItem('spotlight_usertoken', JSON.stringify(res.data.data)) - console.log("onboarding", res) - router.push({ name: 'Profile' }) - + + var previousUrl = localStorage.getItem("previous_url_spotlight"); + console.log("onboarding", previousUrl) + if (!previousUrl) { + router.push({ name: 'Profile' }); + } else { + previousUrl = JSON.parse(previousUrl); + console.log("onboarding-2", previousUrl) + router.push({ + name: previousUrl.ur, + params: { + caseStudyId: previousUrl.caseStudyId, + slideId: previousUrl.slideId, + }, + }); + localStorage.removeItem("previous_url_spotlight"); + + } + + }).catch(err => { console.log(err) }) diff --git a/src/components/AuthorIntro.vue b/src/components/AuthorIntro.vue index 6359812..5360ef3 100644 --- a/src/components/AuthorIntro.vue +++ b/src/components/AuthorIntro.vue @@ -64,6 +64,7 @@ import Vue from "vue"; import router from "../router"; import Header from "./Header"; +import axios from "axios"; export default { components: { @@ -85,11 +86,143 @@ export default { this.allSlide = JSON.parse(allSlideData); this.getCurrentSlideData(); }else{ - this.$router.push("/login"); + this.generatecaseStudies(); } }, methods: { + generatecaseStudies(){ + axios + .get("/caseStudy?caseStudyId="+this.$route.params.caseStudyId, { + headers: { + Authorization: "Bearer " + this.usertoken, + }, + }) + .then((response) => { + + console.log('response',response.data.data); + this.openStudy(response.data.data); + }) + .catch((error) => console.log(error)); + }, + + + + openStudy(payload) { + console.log("payload-", payload); + payload.intro.date = payload.createdAt; + payload.intro.focusPoint = payload.focusAreas; + axios + .get("/caseStudy/slides?caseStudyId=" + payload._id, { + headers: { + Authorization: "Bearer " + this.usertoken, + }, + }) + .then((response) => { + this.createSlide(payload, response.data.data); + }) + .catch((error) => console.log(error)); + }, + + createSlide(payload, slides) { + var finalSlides = []; + slides.forEach((slides_) => { + var url = this.assignRoutes(slides_.templateId); + var obj = { + forward: true, + backward: true, + ur: url, + slideId: slides_._id, + caseStudyId: slides_.caseStudyId, + payload: { + metaData: slides_.metaData, + comments: slides_.comments, + insight: slides_.insight ? slides_.insight : null, + }, + }; + // slides_ + finalSlides.push(obj); + }); + console.log("payload", payload); + // add first slide at begining + finalSlides.unshift({ + forward: true, + backward: false, + ur: "EpisodeIntro", + slideId: "INTRO_oqkdMOVDrwRptsdWJ6Ye", + caseStudyId: payload._id, + payload: { + metaData: payload.intro, + comments: [], + }, + }); + finalSlides.push({ + forward: true, + backward: false, + ur: "Outro", + slideId: "OUTRO_oqkdMOVDrwRptsdWJ6Ye", + caseStudyId: payload._id, + payload: { + metaData: payload.outro, + comments: [], + }, + }); + + console.log(finalSlides); + console.log("payload", payload); + localStorage.setItem( + "spotlight_slide" + payload._id, + JSON.stringify(finalSlides) + ); + this.allSlide = finalSlides; + this.getCurrentSlideData(); + }, + assignRoutes(tempId) { + // /episode-intro + // /outro + var routes = [ + { + url: "AuthorIntro", + tempId: "T1_RoeMG8130Xko1DvhC3Ou", + }, + { + url: "NoScreenshotSingleAuthor", + tempId: "T2_ROsUOEy3vxsRAiQ72XdI", + }, + { + url: "SingleMobileScreenInsightTwo", + tempId: "T3_cqNIf7tuqL4jyON63dA7", + }, + { + url: "TwoScreenWithoutInsight", + tempId: "T4_4QC8W7kIYnJtZ26Jt0Go", + }, + { + url: "noscreenshotSingleautho", + tempId: "T5_za3c3sYgx7bVvtKz5r0e", + }, + { + url: "SingleMobileScreenInsightOne", + tempId: "T6_za3c3sYgx7bVvtKz5sgf", + }, + { + url: "TwoScreenWithInsight", + tempId: "T7_za3c3sYgx7bVvtKzasdf", + }, + { + url: "AuthorReadingNow", + tempId: "T8_zb4d4fYgx7bVvtKzasdf", + }, + { + url: "AuthorReadingBreak", + tempId: "T9_zb3e4fYgy7dVvfKdasdf", + }, + ]; + var i = routes.findIndex((routes_) => routes_.tempId == tempId); + return routes[i].url; + }, + + getCurrentSlideData(){ var i = this.allSlide.findIndex((slide_) => slide_.slideId == this.$route.params.slideId); this.currentSlideIndex = i; diff --git a/src/components/AuthorReadingBreak.vue b/src/components/AuthorReadingBreak.vue index b68a6ff..48d2b00 100644 --- a/src/components/AuthorReadingBreak.vue +++ b/src/components/AuthorReadingBreak.vue @@ -87,6 +87,7 @@ import Vue from "vue"; import router from "../router"; import Header from "./Header"; +import axios from "axios"; export default { components: { @@ -108,11 +109,143 @@ export default { if (allSlideData) { this.allSlide = JSON.parse(allSlideData); this.getCurrentSlideData(); - }else{ - this.$router.push("/login"); + }else{ + this.generatecaseStudies(); } + }, methods: { + generatecaseStudies(){ + axios + .get("/caseStudy?caseStudyId="+this.$route.params.caseStudyId, { + headers: { + Authorization: "Bearer " + this.usertoken, + }, + }) + .then((response) => { + + console.log('response',response.data.data); + this.openStudy(response.data.data); + }) + .catch((error) => console.log(error)); + }, + + + + openStudy(payload) { + console.log("payload-", payload); + payload.intro.date = payload.createdAt; + payload.intro.focusPoint = payload.focusAreas; + axios + .get("/caseStudy/slides?caseStudyId=" + payload._id, { + headers: { + Authorization: "Bearer " + this.usertoken, + }, + }) + .then((response) => { + this.createSlide(payload, response.data.data); + }) + .catch((error) => console.log(error)); + }, + + createSlide(payload, slides) { + var finalSlides = []; + slides.forEach((slides_) => { + var url = this.assignRoutes(slides_.templateId); + var obj = { + forward: true, + backward: true, + ur: url, + slideId: slides_._id, + caseStudyId: slides_.caseStudyId, + payload: { + metaData: slides_.metaData, + comments: slides_.comments, + insight: slides_.insight ? slides_.insight : null, + }, + }; + // slides_ + finalSlides.push(obj); + }); + console.log("payload", payload); + // add first slide at begining + finalSlides.unshift({ + forward: true, + backward: false, + ur: "EpisodeIntro", + slideId: "INTRO_oqkdMOVDrwRptsdWJ6Ye", + caseStudyId: payload._id, + payload: { + metaData: payload.intro, + comments: [], + }, + }); + finalSlides.push({ + forward: true, + backward: false, + ur: "Outro", + slideId: "OUTRO_oqkdMOVDrwRptsdWJ6Ye", + caseStudyId: payload._id, + payload: { + metaData: payload.outro, + comments: [], + }, + }); + + console.log(finalSlides); + console.log("payload", payload); + localStorage.setItem( + "spotlight_slide" + payload._id, + JSON.stringify(finalSlides) + ); + this.allSlide = finalSlides; + this.getCurrentSlideData(); + }, + assignRoutes(tempId) { + // /episode-intro + // /outro + var routes = [ + { + url: "AuthorIntro", + tempId: "T1_RoeMG8130Xko1DvhC3Ou", + }, + { + url: "NoScreenshotSingleAuthor", + tempId: "T2_ROsUOEy3vxsRAiQ72XdI", + }, + { + url: "SingleMobileScreenInsightTwo", + tempId: "T3_cqNIf7tuqL4jyON63dA7", + }, + { + url: "TwoScreenWithoutInsight", + tempId: "T4_4QC8W7kIYnJtZ26Jt0Go", + }, + { + url: "noscreenshotSingleautho", + tempId: "T5_za3c3sYgx7bVvtKz5r0e", + }, + { + url: "SingleMobileScreenInsightOne", + tempId: "T6_za3c3sYgx7bVvtKz5sgf", + }, + { + url: "TwoScreenWithInsight", + tempId: "T7_za3c3sYgx7bVvtKzasdf", + }, + { + url: "AuthorReadingNow", + tempId: "T8_zb4d4fYgx7bVvtKzasdf", + }, + { + url: "AuthorReadingBreak", + tempId: "T9_zb3e4fYgy7dVvfKdasdf", + }, + ]; + var i = routes.findIndex((routes_) => routes_.tempId == tempId); + return routes[i].url; + }, + getCurrentSlideData() { var i = this.allSlide.findIndex( (slide_) => slide_.slideId == this.$route.params.slideId diff --git a/src/components/AuthorReadingNow.vue b/src/components/AuthorReadingNow.vue index f93f3ca..9a8b05e 100644 --- a/src/components/AuthorReadingNow.vue +++ b/src/components/AuthorReadingNow.vue @@ -48,6 +48,7 @@ import Vue from "vue"; import router from "../router"; import Header from "./Header"; +import axios from "axios"; export default { components: { @@ -68,12 +69,143 @@ components: { if (allSlideData) { this.allSlide = JSON.parse(allSlideData); this.getCurrentSlideData(); - }else{ - this.$router.push("/login"); + }else{ + this.generatecaseStudies(); } }, methods: { + generatecaseStudies(){ + axios + .get("/caseStudy?caseStudyId="+this.$route.params.caseStudyId, { + headers: { + Authorization: "Bearer " + this.usertoken, + }, + }) + .then((response) => { + + console.log('response',response.data.data); + this.openStudy(response.data.data); + }) + .catch((error) => console.log(error)); + }, + + + + openStudy(payload) { + console.log("payload-", payload); + payload.intro.date = payload.createdAt; + payload.intro.focusPoint = payload.focusAreas; + axios + .get("/caseStudy/slides?caseStudyId=" + payload._id, { + headers: { + Authorization: "Bearer " + this.usertoken, + }, + }) + .then((response) => { + this.createSlide(payload, response.data.data); + }) + .catch((error) => console.log(error)); + }, + + createSlide(payload, slides) { + var finalSlides = []; + slides.forEach((slides_) => { + var url = this.assignRoutes(slides_.templateId); + var obj = { + forward: true, + backward: true, + ur: url, + slideId: slides_._id, + caseStudyId: slides_.caseStudyId, + payload: { + metaData: slides_.metaData, + comments: slides_.comments, + insight: slides_.insight ? slides_.insight : null, + }, + }; + // slides_ + finalSlides.push(obj); + }); + console.log("payload", payload); + // add first slide at begining + finalSlides.unshift({ + forward: true, + backward: false, + ur: "EpisodeIntro", + slideId: "INTRO_oqkdMOVDrwRptsdWJ6Ye", + caseStudyId: payload._id, + payload: { + metaData: payload.intro, + comments: [], + }, + }); + finalSlides.push({ + forward: true, + backward: false, + ur: "Outro", + slideId: "OUTRO_oqkdMOVDrwRptsdWJ6Ye", + caseStudyId: payload._id, + payload: { + metaData: payload.outro, + comments: [], + }, + }); + + console.log(finalSlides); + console.log("payload", payload); + localStorage.setItem( + "spotlight_slide" + payload._id, + JSON.stringify(finalSlides) + ); + this.allSlide = finalSlides; + this.getCurrentSlideData(); + }, + assignRoutes(tempId) { + // /episode-intro + // /outro + var routes = [ + { + url: "AuthorIntro", + tempId: "T1_RoeMG8130Xko1DvhC3Ou", + }, + { + url: "NoScreenshotSingleAuthor", + tempId: "T2_ROsUOEy3vxsRAiQ72XdI", + }, + { + url: "SingleMobileScreenInsightTwo", + tempId: "T3_cqNIf7tuqL4jyON63dA7", + }, + { + url: "TwoScreenWithoutInsight", + tempId: "T4_4QC8W7kIYnJtZ26Jt0Go", + }, + { + url: "noscreenshotSingleautho", + tempId: "T5_za3c3sYgx7bVvtKz5r0e", + }, + { + url: "SingleMobileScreenInsightOne", + tempId: "T6_za3c3sYgx7bVvtKz5sgf", + }, + { + url: "TwoScreenWithInsight", + tempId: "T7_za3c3sYgx7bVvtKzasdf", + }, + { + url: "AuthorReadingNow", + tempId: "T8_zb4d4fYgx7bVvtKzasdf", + }, + { + url: "AuthorReadingBreak", + tempId: "T9_zb3e4fYgy7dVvfKdasdf", + }, + ]; + var i = routes.findIndex((routes_) => routes_.tempId == tempId); + return routes[i].url; + }, + getCurrentSlideData(){ var i = this.allSlide.findIndex((slide_) => slide_.slideId == this.$route.params.slideId); this.currentSlideIndex = i; diff --git a/src/components/EpisodeIntro.vue b/src/components/EpisodeIntro.vue index 831c950..feee233 100644 --- a/src/components/EpisodeIntro.vue +++ b/src/components/EpisodeIntro.vue @@ -1,5 +1,5 @@