Skip to content
Prev Previous commit
Next Next commit
Offline mode: enable for permalink comments
  • Loading branch information
addyosmani committed May 9, 2016
commit 83ebc1b4fa9e03c38476bc6f07b036d3404efa67
12 changes: 11 additions & 1 deletion src/PermalinkedComment.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var withRouter = require('react-router/lib/withRouter')

var CommentThreadStore = require('./stores/CommentThreadStore')
var HNService = require('./services/HNService')
var HNServiceRest = require('./services/HNServiceRest')
var SettingsStore = require('./stores/SettingsStore')
var UpdatesStore = require('./stores/UpdatesStore')

Expand Down Expand Up @@ -32,7 +33,16 @@ var PermalinkedComment = React.createClass({
},

componentWillMount() {
this.bindAsObject(HNService.itemRef(this.props.params.id), 'comment')
if (SettingsStore.offlineMode) {
HNServiceRest.itemRef(this.props.params.id).then(function(res) {
return res.json()
}).then(function(snapshot) {
this.replaceState({ comment: snapshot })
}.bind(this))
}
else {
this.bindAsObject(HNService.itemRef(this.props.params.id), 'comment')
}
if (this.state.comment.id) {
this.commentLoaded(this.state.comment)
}
Expand Down