var React = require('react'); var _ = require('lodash'); var cx = require('classnames'); var Moment = require('moment'); var request = require('superagent') var Logo = require('naturalcrit/logo/logo.jsx'); var replaceAll = function(str, find, replace) { return str.replace(new RegExp(find, 'g'), replace); } var Statusbar = React.createClass({ getDefaultProps: function() { return { editId: null, sourceText : null, shareId : null, printId : null, isPending : false, lastUpdated : null, info : null, views : 0 }; }, componentDidMount: function() { //Updates the last updated text every 10 seconds if(this.props.lastUpdated){ this.refreshTimer = setInterval(()=>{ this.forceUpdate(); }, 10000) } }, componentWillUnmount: function() { clearInterval(this.refreshTimer); }, deleteBrew : function(){ if(!confirm("are you sure you want to delete this brew?")) return; if(!confirm("are you REALLY sure? You will not be able to recover it")) return; request.get('/homebrew/api/remove/' + this.props.editId) .send() .end(function(err, res){ window.location.href = '/homebrew'; }); }, openSourceWindow : function(){ var sourceWindow = window.open(); var content = replaceAll(this.props.sourceText, '<', '<'); content = replaceAll(content, '>', '>'); sourceWindow.document.write('
' + content + '
'); }, renderInfo : function(){ if(!this.props.lastUpdated) return null; return [
Views: {this.props.views}
,
Last updated: {Moment(this.props.lastUpdated).fromNow()}
]; }, renderChromeTip : function(){ if(typeof window !== 'undefined' && window.chrome) return; return
Optimized for Chrome
}, renderSourceButton : function(){ if(!this.props.sourceText) return null; return View Source }, renderNewButton : function(){ if(this.props.editId || this.props.shareId) return null; return New Brew }, renderChangelogButton : function(){ if(this.props.editId || this.props.shareId) return null; return Changelog }, renderShare : function(){ if(!this.props.shareId) return null; return Share Link }, renderPrintButton : function(){ if(!this.props.printId) return null; return Print View }, renderDeleteButton : function(){ if(!this.props.editId) return null; return
Delete
}, renderStatus : function(){ if(!this.props.editId) return null; var text = 'Saved.' if(this.props.isPending){ text = 'Saving...' } return
{text}
}, render : function(){ return
{this.renderChromeTip()} {this.renderChangelogButton()} {this.renderStatus()} {this.renderInfo()} {this.renderSourceButton()} {this.renderDeleteButton()} {this.renderPrintButton()} {this.renderShare()} {this.renderNewButton()}
} }); module.exports = Statusbar;