lbry-desktop/ui/js/component/drawer.js

68 lines
2.4 KiB
JavaScript
Raw Normal View History

2016-11-22 21:19:08 +01:00
import lbry from '../lbry.js';
import React from 'react';
import {Link} from './link.js';
2016-08-07 23:05:04 +02:00
var DrawerItem = React.createClass({
2016-11-11 12:36:02 +01:00
getDefaultProps: function() {
return {
subPages: [],
};
},
2016-08-07 23:05:04 +02:00
render: function() {
2017-03-26 20:30:18 +02:00
var isSelected = (this.props.viewingPage == this.props.href.substr(1) ||
2016-11-11 12:36:02 +01:00
this.props.subPages.indexOf(this.props.viewingPage) != -1);
return <Link {...this.props} className={ 'drawer-item ' + (isSelected ? 'drawer-item-selected' : '') } />
2016-08-07 23:05:04 +02:00
}
});
var drawerImageStyle = { //@TODO: remove this, img should be properly scaled once size is settled
height: '36px'
};
var Drawer = React.createClass({
2017-03-26 20:30:18 +02:00
_balanceSubscribeId: null,
handleLogoClicked: function(event) {
if ((event.ctrlKey || event.metaKey) && event.shiftKey) {
2017-03-26 20:30:18 +02:00
window.location.href = '?developer'
event.preventDefault();
}
},
getInitialState: function() {
return {
balance: 0,
};
},
componentDidMount: function() {
2017-03-26 20:30:18 +02:00
this._balanceSubscribeId = lbry.balanceSubscribe(function(balance) {
this.setState({
balance: balance
});
}.bind(this));
},
2017-03-26 20:30:18 +02:00
componentWillUnmount: function() {
if (this._balanceSubscribeId) {
lbry.balanceUnsubscribe(this._balanceSubscribeId)
}
},
render: function() {
return (
<nav id="drawer">
<div id="drawer-handle">
<Link title="Close" onClick={this.props.onCloseDrawer} icon="icon-bars" className="close-drawer-link"/>
2017-03-26 20:30:18 +02:00
<a href="?discover" onMouseUp={this.handleLogoClicked}><img src={lbry.imagePath("lbry-dark-1600x528.png")} style={drawerImageStyle}/></a>
</div>
2017-03-26 20:30:18 +02:00
<DrawerItem href='?discover' viewingPage={this.props.viewingPage} label="Discover" icon="icon-search" />
<DrawerItem href='?publish' viewingPage={this.props.viewingPage} label="Publish" icon="icon-upload" />
<DrawerItem href='?downloaded' subPages={['published']} viewingPage={this.props.viewingPage} label="My Files" icon='icon-cloud-download' />
2017-04-10 14:32:40 +02:00
<DrawerItem href="?wallet" subPages={['send', 'receive', 'rewards']} viewingPage={this.props.viewingPage} label="My Wallet" badge={lbry.formatCredits(this.state.balance) } icon="icon-bank" />
2017-03-26 20:30:18 +02:00
<DrawerItem href='?settings' viewingPage={this.props.viewingPage} label="Settings" icon='icon-gear' />
<DrawerItem href='?help' viewingPage={this.props.viewingPage} label="Help" icon='icon-question-circle' />
</nav>
);
}
2016-11-22 21:19:08 +01:00
});
export default Drawer;