var React = require('react'); var _ = require('lodash'); var cx = require('classnames'); var Moment = require('moment'); 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); }, openSourceWindow : function(){ var sourceWindow = window.open(); var content = replaceAll(this.props.sourceText, '<', '<'); content = replaceAll(content, '>', '>'); console.log(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()}
]; }, 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 }, renderShare : function(){ if(!this.props.shareId) return null; return Share Link }, renderPrintButton : function(){ if(!this.props.printId) return null; return Print View }, renderStatus : function(){ if(!this.props.editId) return null; var text = 'Saved.' if(this.props.isPending){ text = 'Saving...' } return
{text}
}, render : function(){ return
{this.renderStatus()} {this.renderInfo()} {this.renderSourceButton()} {this.renderPrintButton()} {this.renderShare()} {this.renderNewButton()}
} }); module.exports = Statusbar;