@@ -3,6 +3,7 @@ var ReactFireMixin = require('reactfire')
33var TimeAgo = require ( 'react-timeago' ) . default
44
55var HNService = require ( './services/HNService' )
6+ var HNServiceRest = require ( './services/HNServiceRest' )
67var StoryCommentThreadStore = require ( './stores/StoryCommentThreadStore' )
78var ItemStore = require ( './stores/ItemStore' )
89
@@ -14,6 +15,8 @@ var ItemMixin = require('./mixins/ItemMixin')
1415var cx = require ( './utils/buildClassName' )
1516var setTitle = require ( './utils/setTitle' )
1617
18+ var SettingsStore = require ( './stores/SettingsStore' )
19+
1720function timeUnitsAgo ( value , unit , suffix ) {
1821 if ( value === 1 ) {
1922 return unit
@@ -31,7 +34,17 @@ var Item = React.createClass({
3134 } ,
3235
3336 componentWillMount ( ) {
34- this . bindAsObject ( HNService . itemRef ( this . props . params . id ) , 'item' )
37+ if ( SettingsStore . offlineMode ) {
38+ HNServiceRest . itemRef ( this . props . params . id ) . then ( function ( res ) {
39+ return res . json ( )
40+ } ) . then ( function ( snapshot ) {
41+ this . replaceState ( { item : snapshot } )
42+ } . bind ( this ) )
43+ }
44+ else {
45+ this . bindAsObject ( HNService . itemRef ( this . props . params . id ) , 'item' )
46+ }
47+
3548 if ( this . state . item . id ) {
3649 this . threadStore = new StoryCommentThreadStore ( this . state . item , this . handleCommentsChanged , { cached : true } )
3750 setTitle ( this . state . item . title )
@@ -58,8 +71,18 @@ var Item = React.createClass({
5871 this . threadStore = new StoryCommentThreadStore ( item , this . handleCommentsChanged , { cached : true } )
5972 setTitle ( item . title )
6073 }
61- this . bindAsObject ( HNService . itemRef ( nextProps . params . id ) , 'item' )
62- this . setState ( { item : item || { } } )
74+
75+ if ( SettingsStore . offlineMode ) {
76+ HNServiceRest . itemRef ( nextProps . params . id ) . then ( function ( res ) {
77+ return res . json ( )
78+ } ) . then ( function ( snapshot ) {
79+ this . replaceState ( { item : snapshot } )
80+ } . bind ( this ) )
81+ }
82+ else {
83+ this . bindAsObject ( HNService . itemRef ( nextProps . params . id ) , 'item' )
84+ this . setState ( { item : item || { } } )
85+ }
6386 }
6487 } ,
6588
0 commit comments