List columns and actions separated

This commit is contained in:
James Barnsley
2017-11-20 15:49:52 +13:00
parent 7f851b3546
commit 7c9e2a5eba
6 changed files with 66 additions and 77 deletions

View File

@ -22,20 +22,17 @@ class ContextMenu extends React.Component{
submenu_expanded: false submenu_expanded: false
} }
this.handleScroll = this.handleScroll.bind(this); this.handleScroll = this.handleScroll.bind(this);
this.handleMouseUp = this.handleMouseUp.bind(this); this.handleMouseDown = this.handleMouseDown.bind(this);
this.handleTouchEnd = this.handleTouchEnd.bind(this);
} }
componentDidMount(){ componentDidMount(){
window.addEventListener("scroll", this.handleScroll, false); window.addEventListener("scroll", this.handleScroll, false);
window.addEventListener("mouseup", this.handleMouseUp, false); window.addEventListener("mousedown", this.handleMouseDown, false);
window.addEventListener("touchend", this.handleTouchEnd, false);
} }
componentWillUnmount(){ componentWillUnmount(){
window.removeEventListener("scroll", this.handleScroll, false); window.removeEventListener("scroll", this.handleScroll, false);
window.removeEventListener("mouseup", this.handleMouseUp, false); window.removeEventListener("mousedown", this.handleMouseDown, false);
window.removeEventListener("touchend", this.handleTouchEnd, false);
} }
componentWillReceiveProps(nextProps){ componentWillReceiveProps(nextProps){
@ -77,17 +74,7 @@ class ContextMenu extends React.Component{
} }
} }
handleTouchEnd(e){ handleMouseDown(e){
console.log('ContextMenu > handleTouchEnd');
this.handleClick(e);
}
handleMouseUp(e){
console.log('ContextMenu > handleMouseUp');
this.handleClick(e);
}
handleClick(e){
// if we click (touch or mouse) outside of the context menu or context menu trigger, kill it // if we click (touch or mouse) outside of the context menu or context menu trigger, kill it
if ($(e.target).closest('.context-menu').length <= 0 && $(e.target).closest('.context-menu-trigger').length <= 0){ if ($(e.target).closest('.context-menu').length <= 0 && $(e.target).closest('.context-menu-trigger').length <= 0){
this.props.uiActions.hideContextMenu() this.props.uiActions.hideContextMenu()

View File

@ -8,11 +8,15 @@ export default class ContextMenuTrigger extends React.Component{
super(props); super(props);
} }
handleMouseUp(e){ handleMouseDown(e){
e.preventDefault();
e.stopPropagation();
this.props.onTrigger(e); this.props.onTrigger(e);
} }
handleTouchEnd(e){ handleClick(e){
e.preventDefault();
e.stopPropagation();
this.props.onTrigger(e); this.props.onTrigger(e);
} }
@ -23,8 +27,7 @@ export default class ContextMenuTrigger extends React.Component{
} }
return ( return (
<span className={className} <span className={className}
onMouseUp={e => this.handleMouseUp(e)} onClick={e => this.handleClick(e)}>
onTouchEnd={e => this.handleTouchEnd(e)}>
<span className="dot"></span> <span className="dot"></span>
<span className="dot"></span> <span className="dot"></span>
<span className="dot"></span> <span className="dot"></span>

View File

@ -89,11 +89,11 @@ class List extends React.Component{
if (row.type ) class_name += ' '+row.type if (row.type ) class_name += ' '+row.type
return ( return (
<div className={class_name} key={row_index}>
<div <div
class="liner"
onClick={e => this.handleClick(e, row.uri)} onClick={e => this.handleClick(e, row.uri)}
onContextMenu={e => this.handleContextMenu(e,row)} onContextMenu={e => this.handleContextMenu(e,row)}>
className={class_name}
key={row_index}>
{ {
this.props.columns.map((col, col_index) => { this.props.columns.map((col, col_index) => {
var className = 'col '+col.name.replace('.','_') var className = 'col '+col.name.replace('.','_')
@ -104,6 +104,7 @@ class List extends React.Component{
) )
}) })
} }
</div>
{this.props.nocontext ? null : <ContextMenuTrigger onTrigger={e => this.handleContextMenu(e, row)} />} {this.props.nocontext ? null : <ContextMenuTrigger onTrigger={e => this.handleContextMenu(e, row)} />}
</div> </div>
) )

View File

@ -100,7 +100,6 @@ export default class Track extends React.Component{
} }
handleContextMenu(e){ handleContextMenu(e){
console.log('handle');
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
e.cancelBubble = true; e.cancelBubble = true;
@ -108,27 +107,29 @@ export default class Track extends React.Component{
} }
render(){ render(){
if (!this.props.track ) return null if (!this.props.track){
return null;
}
var track = this.props.track var track = this.props.track;
var className = 'list-item track' var className = 'list-item track';
if (this.props.selected) className += ' selected' if (this.props.selected) className += ' selected';
if (this.props.selected) className += ' selected' if (this.props.can_sort) className += ' can-sort';
if (this.props.can_sort) className += ' can-sort' if (track.type !== undefined) className += ' '+track.type;
if (track.type !== undefined) className += ' '+track.type if (track.playing) className += ' playing';
if (track.playing) className += ' playing' if (this.state.hover) className += ' hover';
if (this.state.hover) className += ' hover'
var album = '-' var album = '-';
if (track.album){ if (track.album){
if (track.album.uri){ if (track.album.uri){
album = <URILink type="album" uri={track.album.uri}>{track.album.name}</URILink> album = <URILink type="album" uri={track.album.uri}>{track.album.name}</URILink>;
} else { } else {
album = <span>{track.album.name}</span> album = <span>{track.album.name}</span>;
} }
} }
let track_columns = [] let track_columns = [];
let track_actions = [];
if (track.type == 'history'){ if (track.type == 'history'){
@ -228,7 +229,7 @@ export default class Track extends React.Component{
) )
} }
track_columns.push( track_actions.push(
<ContextMenuTrigger key="context" onTrigger={e => this.handleContextMenu(e)} /> <ContextMenuTrigger key="context" onTrigger={e => this.handleContextMenu(e)} />
) )
@ -236,7 +237,7 @@ export default class Track extends React.Component{
// Select zone handles selection events only // Select zone handles selection events only
// We use onClick to capture touch as well as mouse events in one tidy parcel // We use onClick to capture touch as well as mouse events in one tidy parcel
track_columns.push( track_actions.push(
<span <span
className="select-zone" className="select-zone"
key="select-zone" key="select-zone"
@ -246,7 +247,7 @@ export default class Track extends React.Component{
) )
if (this.props.can_sort){ if (this.props.can_sort){
track_columns.push( track_actions.push(
<span <span
className="drag-zone" className="drag-zone"
key="drag-zone" key="drag-zone"
@ -260,13 +261,15 @@ export default class Track extends React.Component{
// the appropriate select/drag zone sub-elements // the appropriate select/drag zone sub-elements
return ( return (
<div className={className}> <div className={className}>
{track_actions}
{track_columns} {track_columns}
</div> </div>
) )
} else { } else {
return ( return (
<div <div className={className}>
className={className} {track_actions}
<div className="liner"
onMouseEnter={e => this.setState({hover: true})} onMouseEnter={e => this.setState({hover: true})}
onMouseLeave={e => this.setState({hover: false})} onMouseLeave={e => this.setState({hover: false})}
//onTouchEnd={e => this.handleTouchEnd(e)} // When touch dragging is dropped on me //onTouchEnd={e => this.handleTouchEnd(e)} // When touch dragging is dropped on me
@ -277,6 +280,7 @@ export default class Track extends React.Component{
onContextMenu={e => {this.handleContextMenu(e)}}> onContextMenu={e => {this.handleContextMenu(e)}}>
{track_columns} {track_columns}
</div> </div>
</div>
) )
} }
} }

View File

@ -12,8 +12,9 @@ export function setSelectedTracks(keys = []){
} }
export function showContextMenu(data){ export function showContextMenu(data){
data.position_x = data.e.clientX data.position_x = data.e.clientX;
data.position_y = data.e.clientY data.position_y = data.e.clientY;
console.log(data);
return { return {
type: 'SHOW_CONTEXT_MENU', type: 'SHOW_CONTEXT_MENU',
data: data data: data

View File

@ -21,7 +21,7 @@
font-family: "Overpass"; font-family: "Overpass";
.title { .title {
display: block; display: none;
padding: 10px 14px; padding: 10px 14px;
font-weight: bold; font-weight: bold;
box-sizing: border-box; box-sizing: border-box;
@ -221,14 +221,6 @@
} }
} }
@include responsive(null, $bp_medium){
.liner {
.title {
display: none;
}
}
}
@include responsive($bp_medium){ @include responsive($bp_medium){
top: 0 !important; top: 0 !important;
right: 0 !important; right: 0 !important;
@ -256,6 +248,7 @@
border-radius: 3px; border-radius: 3px;
.title { .title {
display: block;
padding: 14px 18px; padding: 14px 18px;
box-sizing: border-box; box-sizing: border-box;
border-radius: 3px 3px 0 0; border-radius: 3px 3px 0 0;