diff --git a/client/homebrew/editor/snippetbar/snippetbar.jsx b/client/homebrew/editor/snippetbar/snippetbar.jsx
index 3a7b48916..29ce4d8c8 100644
--- a/client/homebrew/editor/snippetbar/snippetbar.jsx
+++ b/client/homebrew/editor/snippetbar/snippetbar.jsx
@@ -50,8 +50,9 @@ const Snippetbar = createClass({
renderer : this.props.renderer,
themeSelector : false,
snippets : [],
+ showHistory : false,
historyExists : false,
- showHistory : false
+ historyItems : []
};
},
@@ -75,6 +76,17 @@ const Snippetbar = createClass({
historyExists : checkHistoryExists
});
}
+
+ // Update history list if it has changed
+ const checkHistoryItems = await loadHistory(this.props.brew);
+ if(checkHistoryItems.some((historyItem, index)=>{
+ return !index < this.state.historyItems.length || historyItem != this.state.historyItems[index];
+ })){
+ this.setState({
+ historyItems : checkHistoryItems
+ });
+ }
+
},
mergeCustomizer : function(oldValue, newValue, key) {
@@ -152,34 +164,36 @@ const Snippetbar = createClass({
return this.props.updateBrew(item);
},
- renderHistoryItems : async function() {
- if(!this.state.historyExists || !this.state.showHistory) return;
+ toggleHistoryMenu : function(){
+ this.setState({
+ showHistory : !this.state.showHistory
+ });
+ },
- const historyItems = await loadHistory(this.props.brew);
- console.log('renderHistoryItems', historyItems);
- return;
+ renderHistoryItems : function() {
+ if(this.state.historyItems.length == 0) return;
- // return
- // {_.map(historyItems, (item, index)=>{
- // if(!item[1].savedAt) return;
+ return
+ {_.map(this.state.historyItems, (item, index)=>{
+ if(item.noData || !item.savedAt) return;
- // const saveTime = new Date(item[1].savedAt);
- // const diffMs = new Date() - saveTime;
- // const diffSecs = Math.floor(diffMs / 1000);
+ const saveTime = new Date(item.savedAt);
+ const diffMs = new Date() - saveTime;
+ const diffSecs = Math.floor(diffMs / 1000);
- // let diffString = `about ${diffSecs} seconds ago`;
+ let diffString = `about ${diffSecs} seconds ago`;
- // if(diffSecs > 60) diffString = `about ${Math.floor(diffSecs / 60)} minutes ago`;
- // if(diffSecs > (60 * 60)) diffString = `about ${Math.floor(diffSecs / (60 * 60))} hours ago`;
- // if(diffSecs > (24 * 60 * 60)) diffString = `about ${Math.floor(diffSecs / (24 * 60 * 60))} days ago`;
- // if(diffSecs > (7 * 24 * 60 * 60)) diffString = `about ${Math.floor(diffSecs / (7 * 24 * 60 * 60))} weeks ago`;
+ if(diffSecs > 60) diffString = `about ${Math.floor(diffSecs / 60)} minutes ago`;
+ if(diffSecs > (60 * 60)) diffString = `about ${Math.floor(diffSecs / (60 * 60))} hours ago`;
+ if(diffSecs > (24 * 60 * 60)) diffString = `about ${Math.floor(diffSecs / (24 * 60 * 60))} days ago`;
+ if(diffSecs > (7 * 24 * 60 * 60)) diffString = `about ${Math.floor(diffSecs / (7 * 24 * 60 * 60))} weeks ago`;
- // return
{this.replaceContent(item);}} >
- //
- // v{item.version} : {diffString}
- //
;
- // })}
- //
;
+ return
{this.replaceContent(item);}} >
+
+ v{item.version} : {diffString}
+
;
+ })}
+
;
},
renderEditorButtons : function(){
@@ -202,9 +216,10 @@ const Snippetbar = createClass({
}
return
-
+
- {/* { this.renderHistoryItems() } */}
+ { this.state.showHistory && this.renderHistoryItems() }