Skip to content

Commit

Permalink
fix: Handle side menu navigation correctly (#5503)
Browse files Browse the repository at this point in the history
Co-authored-by: iamareebjamal <jamal.areeb@gmail.com>
  • Loading branch information
DIVYAM TAYAL and iamareebjamal authored Nov 24, 2020
1 parent c83fcf9 commit c74edec
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 28 deletions.
38 changes: 26 additions & 12 deletions app/components/public/side-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { tracked } from '@glimmer/tracking';

@classic
export default class SideMenu extends Component {

activeSection = null;

@tracked
showSpeakers = false;

Expand Down Expand Up @@ -45,21 +48,32 @@ export default class SideMenu extends Component {
this.showSessions = this.showSessions || (await this.loader.load(`/events/${this.event.id}/sessions?fields[session]=id&page[size]=1&filter=${JSON.stringify(filters)}`)).data.length;
}

didRender() {
if (!this.activeSection) { return }
const target = document.querySelector(`[href='#${this.activeSection}']`);
if (target) {
// Delay click to give time to render
setTimeout(() => {
target.click();
}, 0);
}
}

@action
scrollToTarget() {
document.querySelectorAll('.scroll').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
goToSection(section) {
this.set('activeSection', section);
}

document.querySelectorAll('.scroll').forEach(node => {
node.classList.remove('active');
});
e.target.classList.add('active');
});
@action
scrollToTarget(section) {
document.querySelector(`#${section}`).scrollIntoView({
behavior: 'smooth'
});
this.set('activeSection', null);
document.querySelectorAll('.scroll').forEach(node => {
node.classList.remove('active');
});
document.querySelector(`[href='#${section}']`).classList.add('active');
}

@computed('event.schedulePublishedOn')
Expand Down
32 changes: 16 additions & 16 deletions app/templates/components/public/side-menu.hbs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{{#if (and (not-eq this.session.currentRouteName 'public.cfs.new-session') (not-eq this.session.currentRouteName 'public.cfs.new-speaker') (not-eq this.session.currentRouteName 'public.cfs.edit-speaker') (not-eq this.session.currentRouteName 'public.cfs.edit-session'))}}
<div class="ui fluid vertical {{unless this.device.isMobile 'pointing'}} menu">
{{#if (eq this.session.currentRouteName 'public.index')}}
<a href='#info' {{action "scrollToTarget"}} class='item active scroll'>
<a href='#info' {{action "scrollToTarget" 'info'}} class='item active scroll'>
{{t 'Info'}}
</a>
{{#if this.event.tickets.length}}
<a href='#tickets' {{action "scrollToTarget"}} class='item scroll'>
<a href='#tickets' {{action "scrollToTarget" 'tickets'}} class='item scroll'>
{{t 'Tickets'}}
</a>
{{/if}}
Expand All @@ -15,13 +15,13 @@
</LinkTo>
{{/if}}
{{else}}
<a class="item" href="{{href-to 'public.index'}}">
{{t 'Info'}}
</a>
<LinkTo class="item" @route="public.index" {{action 'goToSection' 'info'}}>
{{t 'Info'}}
</LinkTo>
{{#if this.event.tickets.length}}
<a class="item" href="{{href-to 'public.index'}}#tickets">
<LinkTo class="item" @route="public.index" {{action 'goToSection' 'tickets'}}>
{{t 'Tickets'}}
</a>
</LinkTo>
{{/if}}
{{#if this.showSpeakers}}
<LinkTo @route="public.speakers" class="item">
Expand All @@ -46,34 +46,34 @@
{{/if}}
{{#if this.event.isSponsorsEnabled}}
{{#if (eq this.session.currentRouteName 'public.index')}}
<a href='#sponsor' {{action "scrollToTarget"}} class='item scroll'>
<a href='#sponsor' {{action "scrollToTarget" 'sponsor'}} class='item scroll'>
{{t 'Sponsors'}}
</a>
{{else}}
<a class="item" href="{{href-to 'public.index'}}#sponsor">
<LinkTo class="item" @route="public.index" {{action 'goToSection' 'sponsor'}}>
{{t 'Sponsors'}}
</a>
</LinkTo>
{{/if}}
{{/if}}
{{#if this.event.hasOwnerInfo}}
{{#if (eq this.session.currentRouteName 'public.index')}}
<a href='#organizer' {{action "scrollToTarget"}} class='item scroll'>
<a href='#organizer' {{action "scrollToTarget" 'organizer'}} class='item scroll'>
{{t 'Organizer'}}
</a>
{{else}}
<a class="item" href="{{href-to 'public.index'}}#organizer">
<LinkTo class="item" @route="public.index" {{action 'goToSection' 'organizer'}}>
{{t 'Organizer'}}
</a>
</LinkTo>
{{/if}}
{{/if}}
{{#if (eq this.session.currentRouteName 'public.index')}}
<a href='#getting-here' class='item scroll'>
<a href='#getting-here' {{action "scrollToTarget" 'getting-here'}} class='item scroll'>
{{t 'Getting here'}}
</a>
{{else}}
<a class="item" href="{{href-to 'public.index'}}#getting-here">
<LinkTo class="item" @route="public.index" {{action 'goToSection' 'getting-here'}}>
{{t 'Getting here'}}
</a>
</LinkTo>
{{/if}}
{{#if this.event.codeOfConduct}}
<LinkTo @route="public.coc" class="item">
Expand Down

1 comment on commit c74edec

@vercel
Copy link

@vercel vercel bot commented on c74edec Nov 24, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.