-
Notifications
You must be signed in to change notification settings - Fork 63
enabled arrow icons to jump to previous and next lessons #1041
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 5 commits
6b8794c
7798eb3
d3758f2
0667163
e3be024
bfc44b7
89831ea
e84f72b
caeb0bc
60f6141
5fe9484
52958ef
feb7744
ef0f7d5
e91ae03
d9ad958
f524ec9
28ddb49
4126829
65c6403
f5acd63
c9c3956
5bde57b
154b746
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ import { | |
TemplateRef | ||
} from '@angular/core'; | ||
|
||
import { ActivatedRoute } from '@angular/router'; | ||
import { ActivatedRoute, Router } from '@angular/router'; | ||
|
||
@Component({ | ||
selector: 'slide-deck', | ||
|
@@ -27,10 +27,13 @@ export class SlidesDeckComponent { | |
@Output() slideAdded = new EventEmitter<{ index: number; id: string }>(); | ||
@HostBinding('class.has-milestone') hasMilestone = false; | ||
private milestone = ''; | ||
private previousLink: string; | ||
private nextLink: string; | ||
|
||
constructor( | ||
private readonly cdr: ChangeDetectorRef, | ||
@Optional() private readonly route: ActivatedRoute | ||
private readonly router: Router, | ||
@Optional() private readonly route: ActivatedRoute | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: let's call (active|activated)Route to be consistent |
||
) { | ||
if (route) { | ||
this.milestone = route.snapshot.queryParams.milestone; | ||
|
@@ -51,18 +54,45 @@ export class SlidesDeckComponent { | |
} | ||
|
||
nextSlide() { | ||
this.goToSlide(this.activeSlideIndex + 1); | ||
if (this.activeSlideIndex + 1 < this.slides.length) { | ||
this.goToSlide(this.activeSlideIndex + 1); | ||
} else if (this.nextLink != null && this.nextLink !== '') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if(this.nextLink) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. noted will change |
||
this.router.navigateByUrl(this.nextLink); | ||
} | ||
} | ||
|
||
previousSlide() { | ||
this.goToSlide(this.activeSlideIndex - 1); | ||
if (this.activeSlideIndex > 0) { | ||
this.goToSlide(this.activeSlideIndex - 1); | ||
} else if (this.previousLink != null && this.previousLink !== '') { | ||
this.router.navigateByUrl(this.previousLink); | ||
} | ||
} | ||
|
||
canGoNext(): boolean { | ||
return this.activeSlideIndex + 1 < this.slides.length; | ||
return this.activeSlideIndex + 1 < this.slides.length || (this.nextLink != null && this.nextLink !== ''); | ||
} | ||
|
||
canGoPrevious(): boolean { | ||
return this.activeSlideIndex > 0; | ||
return this.activeSlideIndex > 0 || (this.previousLink != null && this.previousLink !== ''); | ||
} | ||
|
||
public setupPreviousNext(allRoutes: string[]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's keep the presentation simple: |
||
this.previousLink = ''; | ||
this.nextLink = ''; | ||
let currentUrl = this.router.url; | ||
if (currentUrl.startsWith('/')) { | ||
currentUrl = currentUrl.substr(1); | ||
} | ||
const urlPaths = currentUrl.split('/'); | ||
if (urlPaths.length > 1) { | ||
const idx = allRoutes.indexOf(urlPaths[1]); | ||
if (idx > 0) { | ||
this.previousLink = `/${urlPaths[0]}/${allRoutes[idx - 1]}`; | ||
} | ||
if (idx < (allRoutes.length - 1)) { | ||
this.nextLink = `/${urlPaths[0]}/${allRoutes[idx + 1]}`; | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment on why it's optional?
I'm actually curious what the use case would be, since it's always supposed to be inside of the slide deck
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ng test was failing so made it optional.