Skip to content

Commit

Permalink
Initial history management
Browse files Browse the repository at this point in the history
  • Loading branch information
blockspeiser committed May 29, 2015
1 parent f570a38 commit 2f580fa
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion templates/s2.html
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,22 @@
contents: [{type: "TextRange", ref: this.props.initialRef }]
}
},
componentDidMount: function() {
window.onpopstate = function(event) {
this.setState({contents: [event.state]});
}.bind(this);
},
componentDidUpdate: function() {
var current = this.state.contents.slice(-1)[0];
if (!history.state || history.state.type !== current.type || history.state.ref !== current.ref) {
var url = normRef(current.ref);
if (current.type == "TextList") {
url += "?with=" + (this.state.currentFilter.length ? this.state.currentFilter[0] : "all");
}
history.pushState(current, current.ref, url);
console.log("pushing " + current.ref);
}
},
showTextList: function(ref) {
this.state.contents.push({type: "TextList", ref: ref});
this.setState({contents: this.state.contents});
Expand Down Expand Up @@ -563,7 +579,7 @@
}.bind(this)).map(function(link) {
return link.sourceRef;
}).sort();

console.log(refs);
return (
<div className={classes}>
<div className="textListTop">
Expand Down

0 comments on commit 2f580fa

Please sign in to comment.