import React from 'react'; import {connect} from 'react-redux'; import {close, setSkinFromFilename} from './actionCreators'; import '../css/context-menu.css'; class ContextMenu extends React.Component { constructor(props) { super(props); this.openFileDialog = this.openFileDialog.bind(this); this.close = this.close.bind(this); this.toggleMenu = this.toggleMenu.bind(this); this.closeMenu = this.closeMenu.bind(this); this.setSkin = this.setSkin.bind(this); } componantWillMount() { // Clicking anywhere outside the context menu will close the window document.addEventListener('click', this.closeMenu); } componantWillUnmount() { document.removeEventListener('click', this.closeMenu); } openFileDialog() { this.props.dispatch({type: 'OPEN_FILE_DIALOG'}); } close() { this.props.dispatch(close(this.props.mediaPlayer)); } closeMenu() { this.props.dispatch({type: 'CLOSE_CONTEXT_MENU'}); } toggleMenu(event) { this.props.dispatch({type: 'TOGGLE_CONTEXT_MENU'}); event.stopPropagation(); } setSkin(e) { setSkinFromFilename(this.props.winamp, e.target.dataset.filename); } render() { var classes = this.props.selected ? 'selected' : ''; return
; } } module.exports = connect(state => state.contextMenu)(ContextMenu);