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('');
},
renderInfo : function(){
if(!this.props.lastUpdated) return null;
return [
' + content + '