Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Commit

Permalink
[WIP] Show last modified time on archive page #521 (#587)
Browse files Browse the repository at this point in the history
* add placeholder for last modified time on archive page #521

* Add modified time
  • Loading branch information
Kriesse authored and Karissa committed Jun 19, 2017
1 parent 09320be commit 8c4b6bb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
6 changes: 5 additions & 1 deletion client/js/components/health.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const html = require('choo/html')
const relative = require('relative-date')
const prettyBytes = require('pretty-bytes')
const circle = require('./circle')
const css = require('sheetify')
Expand Down Expand Up @@ -43,7 +44,10 @@ module.exports = function hyperhealth (state, emit) {
`
: ''}
</div>
<div class="dat-detail">${progressPeers} ${plural(progressPeers)} downloading</div>
<div class="dat-detail">${progressPeers} downloading</div>
${state.archive.updatedAt ? html`<div class="dat-detail">
updated ${relative(state.archive.updatedAt)}
</div>` : ''}
</div>
<div>
${data.peers.map((peer, i) => {
Expand Down
18 changes: 1 addition & 17 deletions client/js/components/hyperdrive/client.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
var path = require('path')
var yofs = require('yo-fs')

module.exports = function ui (root, entries, onclick) {
var lookup = {}
for (var i in entries) {
var entry = entries[i]
if (entry.name[0] === '/') entry.name = entry.name.substring(1, entry.name.length)
lookup[entry.name] = entry
var dir = path.dirname(entry.name)
if (!lookup[dir]) {
lookup[dir] = {
type: 'directory',
name: dir,
length: 0
}
}
}
var vals = Object.keys(lookup).map(key => lookup[key])
var tree = yofs(root, vals, onclick)
var tree = yofs(root, entries, onclick)
return tree.widget
}
25 changes: 24 additions & 1 deletion client/js/components/hyperdrive/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
const hyperdriveRenderer = require('./client.js')
const path = require('path')
const noop = function () {}

module.exports = function (state, emit) {
var lookup = {}
var updated = null // last modified date
for (var i in state.archive.entries) {
var entry = state.archive.entries[i]
if (!updated) updated = new Date(entry.mtime)
else {
var compare = new Date(entry.mtime)
if (updated.getTime() < compare.getTime()) updated = compare
}
if (entry.name[0] === '/') entry.name = entry.name.substring(1, entry.name.length)
lookup[entry.name] = entry
var dir = path.dirname(entry.name)
if (!lookup[dir]) {
lookup[dir] = {
type: 'directory',
name: dir,
length: 0
}
}
}
emit('archive:update', {updatedAt: updated})
var vals = Object.keys(lookup).map(key => lookup[key])
var onclick = (ev, entry) => {
if (entry.type === 'directory') {
emit('archive:directory', entry.name)
Expand All @@ -13,5 +36,5 @@ module.exports = function (state, emit) {
}
}

return hyperdriveRenderer(state.archive.root, state.archive.entries, onclick)
return hyperdriveRenderer(state.archive.root, vals, onclick)
}
1 change: 1 addition & 0 deletions client/js/models/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = {
archive: {
health: null,
id: null,
updatedAt: false,
key: null,
retries: 0,
peers: 0,
Expand Down

0 comments on commit 8c4b6bb

Please sign in to comment.