From 624cd9735893fcf76db9e318f7a8dc9bd1c89197 Mon Sep 17 00:00:00 2001 From: kj1352 Date: Fri, 3 Jul 2020 12:33:04 +0530 Subject: [PATCH] Removed subscriptions for demotype and implemented local storage --- src/app/app.component.ts | 6 ++++- src/app/services/demo.service.ts | 8 ------- .../course-details.component.ts | 19 ++++----------- src/app/tabs/courses/courses.component.ts | 22 +++++++---------- src/app/tabs/home/home.component.ts | 24 +++++++------------ src/app/tabs/more/more.component.html | 9 ++++--- src/app/tabs/more/more.component.ts | 22 +++++++++++++---- src/app/welcome/welcome.component.ts | 23 +++++++----------- 8 files changed, 60 insertions(+), 73 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index ce035d7..c910cbb 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -7,5 +7,9 @@ import { Component } from '@angular/core'; styleUrls: ['./app.component.scss'] }) export class AppComponent { - + constructor() { + if (!localStorage.demoType) { + localStorage.demoType = 'Teacher'; + } + } } diff --git a/src/app/services/demo.service.ts b/src/app/services/demo.service.ts index 2b5f591..3f4e3e6 100644 --- a/src/app/services/demo.service.ts +++ b/src/app/services/demo.service.ts @@ -1,14 +1,10 @@ import { Injectable } from '@angular/core'; -import { Observable, Observer } from 'rxjs'; import * as moment from 'moment'; @Injectable({ providedIn: 'root' }) export class DemoService { - demoType: Observable; - demoTypeObserver: Observer; - courseData = [{ classLevel: '10', courses: [{ @@ -328,9 +324,5 @@ export class DemoService { }]; constructor() { - this.demoType = Observable.create((observer: Observer) => { - this.demoTypeObserver = observer; - this.demoTypeObserver.next('Teacher'); - }); } } diff --git a/src/app/tabs/courses/course-details/course-details.component.ts b/src/app/tabs/courses/course-details/course-details.component.ts index 3e5da68..b25129d 100644 --- a/src/app/tabs/courses/course-details/course-details.component.ts +++ b/src/app/tabs/courses/course-details/course-details.component.ts @@ -19,7 +19,6 @@ export class CourseDetailsComponent implements OnInit { selectedTopic: number; classLevel: string; - demoTypeSubscriber: Subscription; demoType: string; chapterList = []; @@ -38,19 +37,11 @@ export class CourseDetailsComponent implements OnInit { courseId = params['courseId']; }); - this.demoTypeSubscriber = this.demoService.demoType.subscribe((type) => { - this.demoType = type; - - let courseData = this.demoService.courseData; - - let course = courseData.find((courseClass) => courseClass.classLevel === classLevel).courses.find((course) => course.id === courseId); - - this.heading = course.name; - - this.chapterList = course.chapterList; - - console.log(this.chapterList); - }); + this.demoType = localStorage.demoType; + let courseData = this.demoService.courseData; + let course = courseData.find((courseClass) => courseClass.classLevel === classLevel).courses.find((course) => course.id === courseId); + this.heading = course.name; + this.chapterList = course.chapterList; } ngOnDestroy() { diff --git a/src/app/tabs/courses/courses.component.ts b/src/app/tabs/courses/courses.component.ts index b268ac3..9372dba 100644 --- a/src/app/tabs/courses/courses.component.ts +++ b/src/app/tabs/courses/courses.component.ts @@ -1,6 +1,5 @@ import { Component, OnInit } from '@angular/core'; import { DemoService } from '../../services/demo.service'; -import { Subscription } from 'rxjs'; import { Router } from '@angular/router'; @Component({ @@ -9,7 +8,6 @@ import { Router } from '@angular/router'; styleUrls: ['./courses.component.scss'] }) export class CoursesComponent implements OnInit { - demoTypeSubscriber: Subscription; demoType: string; classCourseList = []; @@ -19,17 +17,15 @@ export class CoursesComponent implements OnInit { ) { } ngOnInit(): void { - this.demoTypeSubscriber = this.demoService.demoType.subscribe((type) => { - this.demoType = type; - if (type === 'Student') { - this.classCourseList = this.demoService.courseData; - this.classCourseList = this.classCourseList.filter((courseClass) => { - return courseClass.level === '10'; - }) - } else { - this.classCourseList = this.demoService.courseData; - } - }); + this.demoType = localStorage.demoType; + if (this.demoType === 'Student') { + this.classCourseList = this.demoService.courseData; + this.classCourseList = this.classCourseList.filter((courseClass) => { + return courseClass.classLevel === '10'; + }); + } else { + this.classCourseList = this.demoService.courseData; + } } goToCourse(classLevel: string, courseId: string) { diff --git a/src/app/tabs/home/home.component.ts b/src/app/tabs/home/home.component.ts index 5d6344d..84ce7cf 100644 --- a/src/app/tabs/home/home.component.ts +++ b/src/app/tabs/home/home.component.ts @@ -1,7 +1,6 @@ import { Component, OnInit } from '@angular/core'; import { ScrollEvent } from 'ngx-scroll-event'; import { DemoService } from '../../services/demo.service'; -import { Subscription } from 'rxjs'; @Component({ selector: 'app-home', @@ -13,7 +12,6 @@ export class HomeComponent implements OnInit { showClassDetails: boolean; selectedSegment: string = 'transcript'; showVideo: boolean = false; - demoTypeSubscriber: Subscription; demoType: string; classList = []; @@ -29,17 +27,15 @@ export class HomeComponent implements OnInit { this.showClassDetails = false; } - this.demoTypeSubscriber = this.demoService.demoType.subscribe((type) => { - this.demoType = type; - if (type === 'Student') { - this.classList = this.demoService.studentClassList; - this.showVideo = true; - } + this.demoType = localStorage.demoType; + if (this.demoType === 'Student') { + this.classList = this.demoService.studentClassList; + this.showVideo = true; + } - if (type === 'Teacher') { - this.classList = this.demoService.teacherClassList; - } - }); + if (this.demoType === 'Teacher') { + this.classList = this.demoService.teacherClassList; + } } public handleScroll(event: ScrollEvent) { @@ -58,8 +54,4 @@ export class HomeComponent implements OnInit { } } - ngOnDestroy() { - this.demoTypeSubscriber.unsubscribe(); - } - } diff --git a/src/app/tabs/more/more.component.html b/src/app/tabs/more/more.component.html index 1c441ac..db2ca48 100644 --- a/src/app/tabs/more/more.component.html +++ b/src/app/tabs/more/more.component.html @@ -12,8 +12,8 @@
-
Dwayne The Rock
-

3000 XP

+
{{ demoType }}
+

3000 XP

@@ -139,7 +139,10 @@ - + + diff --git a/src/app/tabs/more/more.component.ts b/src/app/tabs/more/more.component.ts index a075e87..bf62cd7 100644 --- a/src/app/tabs/more/more.component.ts +++ b/src/app/tabs/more/more.component.ts @@ -1,4 +1,5 @@ import { Component, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; @Component({ selector: 'app-more', @@ -6,12 +7,25 @@ import { Component, OnInit } from '@angular/core'; styleUrls: ['./more.component.scss'] }) export class MoreComponent implements OnInit { - selectedSegment: string = 'badges'; - profileDetails: boolean = false; + selectedSegment: string = 'badges'; + profileDetails: boolean = false; + demoType: string; - constructor() { } + constructor( + private router: Router + ) { } - ngOnInit(): void { + ngOnInit(): void { + this.demoType = localStorage.demoType; } + ngOnDestroy() { + + } + + changeLogin(type: string) { + localStorage.demoType = type; + this.router.navigate(['welcome']); + } + } diff --git a/src/app/welcome/welcome.component.ts b/src/app/welcome/welcome.component.ts index cc8c760..5df0a3f 100644 --- a/src/app/welcome/welcome.component.ts +++ b/src/app/welcome/welcome.component.ts @@ -1,6 +1,5 @@ import { Component, OnInit } from '@angular/core'; import { DemoService } from '../services/demo.service'; -import { Subscription } from 'rxjs'; @Component({ selector: 'app-welcome', @@ -8,30 +7,26 @@ import { Subscription } from 'rxjs'; styleUrls: ['./welcome.component.scss'] }) export class WelcomeComponent implements OnInit { - demoTypeSubscriber: Subscription; - demoType: string; - classList = []; + demoType: string; constructor( private demoService: DemoService ) { } ngOnInit(): void { - this.demoTypeSubscriber = this.demoService.demoType.subscribe((type) => { - this.demoType = type; - if (type === 'Student') { - this.classList = this.demoService.studentClassList; - } + this.demoType = localStorage.demoType; + if (this.demoType === 'Student') { + this.classList = this.demoService.studentClassList; + } - if (type === 'Teacher') { - this.classList = this.demoService.teacherClassList; - } - }); + if (this.demoType === 'Teacher') { + this.classList = this.demoService.teacherClassList; + } } ngOnDestroy() { - this.demoTypeSubscriber.unsubscribe(); + } }