Skip to content

Commit

Permalink
Saving config and checking modified date.
Browse files Browse the repository at this point in the history
  • Loading branch information
d14na committed Aug 25, 2018
1 parent 3737a12 commit f49339e
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 67 deletions.
207 changes: 146 additions & 61 deletions android/app/src/main/assets/index.android.bundle

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions android/app/src/main/assets/index.android.bundle.meta
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
�z
";�k��c���D��Oh��
�!5�lU�k��c�>�FLp��
6 changes: 6 additions & 0 deletions src/frames/Stage.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ export default class Stage extends React.Component {
<Text style={ styles.ziteDetailsText }>
{ stores.Stage.ziteLastUpdate }
</Text>
<Text style={ styles.ziteDetailsText }>
LIVE: { stores.Stage.ziteModified }
</Text>
<Text style={ styles.ziteDetailsText }>
CACHED: { stores.Stage.ziteCachedConfig.modified }
</Text>
</View>
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/frames/Webview.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,11 @@ const styles = StyleSheet.create({
},
navBar: {
flexDirection: 'row',
width: '100%',
height: 40
// width: '100%',
height: 40,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'rgba(30, 30, 180, 0.2)'
},
navBarButton: {
flex: 1
Expand Down
5 changes: 3 additions & 2 deletions src/lib/host0.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ class Host0 {
const self = this

const filePath = self.fs.DocumentDirectoryPath + '/' + _address + '/' + _path
console.log('FILEPATH', filePath)

return new Promise(async function (resolve, reject) {
const exists = await self.fs.exists(filePath)
.catch(reject)
// console.log('getPath EXISTS', exists)
console.log('getPath EXISTS', exists)

if (exists) {
let contents = null

if (_path.slice(-3) === 'png') {
if (_path.slice(-3) === 'png' || _path.slice(-3) === 'jpg') {
contents = await self.fs.readFile(filePath, 'base64')
.catch(err => { throw err })

Expand Down
12 changes: 12 additions & 0 deletions src/stores/Stage.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class Store {
@observable ziteTitle = ''
@observable ziteDescription = ''
@observable ziteLastUpdate = ''
@observable ziteModified = 0
@observable ziteCachedConfig = {}
@observable ziteFiles = []
/* FIXME Will only display blockchain ads on Android devices to avoid
Expand Down Expand Up @@ -64,6 +66,16 @@ class Store {
this.ziteLastUpdate = _lastUpdate
}

/* Set the zite modified. */
@action setZiteModified(_modified) {
this.ziteModified = _modified
}

/* Set the zite modified. */
@action setZiteCachedConfig(_cachedConfig) {
this.ziteCachedConfig = _cachedConfig
}

/* Set the zite files list. */
@action setZiteFiles(_files) {
this.ziteFiles = _files
Expand Down
28 changes: 28 additions & 0 deletions src/stores/controllers/Zite.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@ const Zite = {
/* Initailize Peer0. */
this.peer0 = new Peer0(net)

try {
/* Check the config (if available) cached on disk. */
let cachedConfig = await this.host0.getFile(this.address, 'content.json')
.catch(err => { throw err })

/* Decode the cache. */
cachedConfig = JSON.parse(cachedConfig)
console.log('CACHED CONFIG', cachedConfig)

/* Set cached config (if available). */
if (cachedConfig) {
/* Set the cached config.json. */
Stage.setZiteCachedConfig(cachedConfig)
}
} catch (e) {
/* Something has gone wrong if we cannot parse the content.json. */
// FIXME Handle this better in the UI
throw e
}

/* Initialize caching flag. */
const noCache = false

Expand All @@ -45,6 +65,7 @@ const Zite = {
Stage.setZiteTitle(this.config['title'])
Stage.setZiteAddress(this.config['address'])
Stage.setZiteDescription(this.config['description'])
Stage.setZiteModified(this.config['modified'])

const lastUpdate = moment.unix(this.config['modified']).fromNow() +
' [ ' + moment.unix(this.config['modified']).format('ll') + ' ]'
Expand Down Expand Up @@ -88,6 +109,13 @@ const Zite = {
},

open: async function(_address, _path) {
/* Retrieve and decode content.json. */
const config = JSON.stringify(this.config)

/* Save the latest content.json. */
await this.host0.saveFile(_address, 'content.json', config)
.catch(err => { throw err })

/* Initialize files holder. */
const files = this.config['files']

Expand Down

0 comments on commit f49339e

Please sign in to comment.