Skip to content
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

enabled arrow icons to jump to previous and next lessons #1041

Open
wants to merge 24 commits into
base: master
Choose a base branch
from

Conversation

sunilj74
Copy link
Collaborator

No description provided.

@@ -49,7 +49,7 @@
</div>
<slide-deck slideShortcuts slidesRouting slides-tracking>
<codelab-progress-bar></codelab-progress-bar>
<slide-arrows></slide-arrows>
<slide-arrows previousLink="" nextLink="/angular/templates"></slide-arrows>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definitely want to avoid providing links manually

@kirjs
Copy link
Collaborator

kirjs commented Sep 14, 2019

Discussed offline, let's move to the deck component and populate using slides rather than inputs

1 similar comment
@kirjs
Copy link
Collaborator

kirjs commented Sep 14, 2019

Discussed offline, let's move to the deck component and populate using slides rather than inputs

@@ -10,7 +12,17 @@ export class CodelabClosingSlideComponent implements OnInit {
@Input() body: String;
@Input() footer: String;

constructor() {}
constructor(
@Optional() private readonly presentation: SlidesDeckComponent,
Copy link
Collaborator

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

Copy link
Collaborator Author

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.

this.goToSlide(this.activeSlideIndex + 1);
if (this.activeSlideIndex + 1 < this.slides.length) {
this.goToSlide(this.activeSlideIndex + 1);
} else if (this.nextLink != null && this.nextLink !== '') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if(this.nextLink)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noted will change

return this.activeSlideIndex > 0 || (this.previousLink != null && this.previousLink !== '');
}

public setupPreviousNext(allRoutes: string[]) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep the presentation simple:
setNextLink()
and
setNextLink()
All the router manipulations should be done outside of this component, as it is not supposed to know about the codelab routing structure

Comment on lines 31 to 42
if (currentUrl.startsWith('/')) {
currentUrl = currentUrl.substr(1);
}
const urlPaths = currentUrl.split('/');
if (urlPaths.length > 1) {
const idx = allRoutes.indexOf(urlPaths[1]);
if (idx > 0) {
previousLink = `/${urlPaths[0]}/${allRoutes[idx - 1]}`;
}
if (idx < allRoutes.length - 1) {
nextLink = `/${urlPaths[0]}/${allRoutes[idx + 1]}`;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very complicated, is there some activeRoute property we could use to avoid all the string manipulations?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is complicated for sure, if I can get or compute the full path from menu routes that will work too.

private readonly presentation: SlidesDeckComponent,
@Optional() @Inject(MENU_ROUTES) readonly menuRoutes
) {
if (this.menuRoutes != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At which point would menuRoutes be null?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️

}
}

private setupPreviousNext() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name seems outdated

let currentUrl = this.router.url;
if (currentUrl.startsWith('/')) {
currentUrl = currentUrl.substr(1);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code looks very complicated, what exactly is happening here?

nextLink: '',

setPrevious(link) {
this.previousLink = link;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened to the spies?

previousLink: '',
nextLink: '',

setPrevious(link) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just do setPrevious: createSpy(...)

@@ -21,4 +60,8 @@ describe('CodelabClosingSlideComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});

it('should call setNextLink', () => {
expect(slidesDeckComponentStub.setNext).toHaveBeenCalled();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we verify that it has been called with the proper argument?

private readonly presentation: SlidesDeckComponent,
@Optional() @Inject(MENU_ROUTES) readonly menuRoutes
) {
if (this.menuRoutes != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️

.find(r => r && (r as MenuRoute).prod);
const index = this.menuRoutes.findIndex(c => c.path === config.path);
let nextLink = '';
if (index < this.menuRoutes.length - 1) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious what's the value of this check?

}

private setupPrevious() {
const config = this.activeRoute.snapshot.pathFromRoot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're we planning to move this logic to a shared service since we're actually just copy-pasting it accross 2 components?

}

private getCurrentIndex(activeRoute: ActivatedRoute) {
// TODO: inject ActivatedRoute but figure out a way to fix snapshot update issue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be awesome for this comment to be more detailed so that next person who sees this knows what the issue is and how to reproduce

if (this.presentation != null) {
let nextLink = this.menuRouteService.getNextLink(this.activeRoute);
if (nextLink) {
nextLink = '../../' + nextLink;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should also prob be a TODO here to make it more generic

this.activeRoute
);
if (previousLink) {
previousLink = '../../' + previousLink;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We always do this for both next and previous link, I think this should move in


constructor(
private readonly cdr: ChangeDetectorRef,
private readonly router: Router,
@Optional() private readonly route: ActivatedRoute
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let's call (active|activated)Route to be consistent

if (config == null) {
return -1;
}
const index = this.menuRoutes.findIndex(c => c.path === config.path);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for an intermediate var, just return?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️

if (this.presentation != null) {
let nextLink = this.menuRouteService.getNextLink(this.activeRoute);
if (nextLink) {
nextLink = '../../' + nextLink;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should also prob be a TODO here to make it more generic

}

private getMenuRouteByIndex(index: number) {
if (index >= 0 && index < this.menuRoutes.length) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need these checks? Can it be just
return this.menuRoutes[index]; ?

) {
if (this.presentation != null) {
const nextLink = this.menuRouteService.getNextLink(this.activeRoute);
this.presentation.setNext(nextLink);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop empty ngOnInit while you're here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants