From 51514d69d9a5f154d1c5c52598078e87523cf673 Mon Sep 17 00:00:00 2001 From: James Barnsley Date: Tue, 28 Feb 2017 20:58:15 +1300 Subject: [PATCH] Expandable playlists --- src/js/components/ContextMenu.js | 30 ++++++++++++++------------ src/scss/components/_context-menu.scss | 20 ++++++++++++++--- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/js/components/ContextMenu.js b/src/js/components/ContextMenu.js index 3803658d..51cd7773 100755 --- a/src/js/components/ContextMenu.js +++ b/src/js/components/ContextMenu.js @@ -15,12 +15,15 @@ import * as spotifyActions from '../services/spotify/actions' class ContextMenu extends React.Component{ constructor(props) { - super(props); + super(props) + this.state = { + submenu_expanded: false + } this.handleScroll = this.handleScroll.bind(this) this.handleClick = this.handleClick.bind(this) } - componentDidMount(){ + componentDidMount(){ window.addEventListener("scroll", this.handleScroll, false) window.addEventListener("click", this.handleClick, false) } @@ -31,9 +34,13 @@ class ContextMenu extends React.Component{ } componentWillReceiveProps( nextProps ){ - if (nextProps.menu){ + // if we've been given a menu object (ie activated) when we didn't have one prior + if (nextProps.menu && !this.props.menu){ + this.setState({ submenu_expanded: false }) $('body').addClass('context-menu-open') - } else { + + // we DID have one prior, and now we don't + } else if (this.props.menu && !nextProps.menu){ $('body').removeClass('context-menu-open') } } @@ -45,12 +52,8 @@ class ContextMenu extends React.Component{ } handleClick(e){ - if (helpers.isTouchDevice()){ - return null - } - - var target = e.target - if (this.props.menu && !target.classList.contains('context-menu-trigger')){ + // if we click outside of the context menu, kill it + if ($(e.target).closest('.context-menu').length <= 0){ this.props.uiActions.hideContextMenu() } } @@ -82,8 +85,7 @@ class ContextMenu extends React.Component{ } addToPlaylist(){ - this.props.uiActions.hideContextMenu(); - this.props.uiActions.openModal('add_to_playlist', { tracks_uris: this.props.menu.uris }) + this.setState({ submenu_expanded: !this.state.submenu_expanded }) } addToQueue(){ @@ -292,9 +294,9 @@ class ContextMenu extends React.Component{ this[item.handleClick](e)}> { item.label } - + - { this.renderPlaylistSubmenu() } + {this.state.submenu_expanded ? this.renderPlaylistSubmenu() : null} ) }else{ diff --git a/src/scss/components/_context-menu.scss b/src/scss/components/_context-menu.scss index 2243e01a..e5dad016 100755 --- a/src/scss/components/_context-menu.scss +++ b/src/scss/components/_context-menu.scss @@ -63,7 +63,7 @@ text-transform: capitalize; } - &:hover{ + .notouch &:hover{ .background { opacity: 0.7; } @@ -103,7 +103,7 @@ .menu-item { width: 140px; - &:hover { + .notouch &:hover { background: lighten($dark_grey, 10%); } } @@ -133,7 +133,7 @@ overflow-y: scroll; .background { - position: absolute; + position: fixed; top: 0; right: 0; bottom: 0; @@ -161,6 +161,20 @@ width: 100%; box-sizing: border-box; } + + .submenu { + display: block; + position: relative; + width: 100%; + top: auto; + right: auto; + bottom: auto; + left: auto; + + .menu-item { + width: 100%; + } + } } } }