Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bin/version-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ var pageContents = fs.readFileSync(page, 'utf8')
fs.renameSync(page, 'server/page-debug.js')

var prod = pageContents
.replace(/public\/css\/app.css/gmi, 'public/css/app.min.css')
.replace(/public\/js\/app.js/gmi, 'public/js/app.min.js')
.replace(/public\/css\/app.css/gmi, 'public/css/app.min.css')
.replace(/public\/js\/app.js/gmi, 'public/js/app.min.js')
fs.writeFileSync(page, prod, 'utf8')

// version `app.min.js` and `main.min.js` by appending md5 hash to filename
Expand Down
3 changes: 1 addition & 2 deletions client/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ var api = require('dat-registry')

module.exports = function () {
if (!module.parent) {
return api({server: window.location.origin, apiPath: '/api/v1'})
return api({ server: window.location.origin, apiPath: '/api/v1' })
}
return
}
5 changes: 2 additions & 3 deletions client/js/app.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
const choo = require('choo')
const persist = require('choo-persist')
const logger = require('choo-log')
const css = require('sheetify')
const defaults = require('./models/defaults')
const app = choo()

// define models:
var key = module.parent ? '' : window.location.origin
app.use(persist({name: 'choo-hypertracker' + key}))
app.use(persist({ name: 'choo-hypertracker' + key }))
if (process.env.NODE_ENV !== 'production') {
app.use(logger())
app.use(require('choo-devtools')())
}
app.use(require('./defaults')(defaults))
app.use(require('./models/archive'))
Expand Down
1 change: 0 additions & 1 deletion client/js/components/auth/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const login = (state, emit) => {
}
`


return html`<div class="${styles} login">
<div class="mw5 pv6 center">
<h1 class="f4">Log In</h1>
Expand Down
4 changes: 2 additions & 2 deletions client/js/components/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ module.exports = function (state, emit) {
<a class="${logoCss} v-mid dib link dim mr2 w2 h2" href="/" title="DatBase">
<img src="/public/img/dat-hexagon.svg" alt="Dat Logo">
</a>
<a class="mr3 v-mid link dim color-neutral hover-color-neutral b f5 f3-ns dib-ns dn" href="/" title="datBase">dat<span class="color-neutral-60">Base</span></a>
<a class="mr3 v-mid link dim color-neutral hover-color-neutral b f5 f3-ns dib-ns dn" href="/" title="datBase">dat<span class="color-neutral-60">Directory</span></a>
${importButton(emit)}
<a href="http://docs.datproject.org" class="ml3 link dim color-neutral ttu tracked f6 f5-ns dib">Docs</a>
<a href="http://chat.datproject.org" class="ml3 link dim color-neutral ttu tracked f6 f5-ns dib-l dn">Chat</a>
<a href="http://datproject.org" class="ml3 link dim color-neutral ttu tracked f6 f5-ns dib-l dn">Home</a>
</div>
<div class="dtc v-mid w-25 tr">
${state.township.email ? html`<a href="/publish" class="dib-ns dn btn btn--green">Publish</a>` : ''}
Expand Down
6 changes: 3 additions & 3 deletions client/js/components/health.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ module.exports = function hyperhealth (state, emit) {
</div>
<div>
${data.peers.map((peer, i) => {
const prog = (peer.have * 100) / peer.length
if (!prog) return circle(prog)
})}
const prog = (peer.have * 100) / peer.length
if (!prog) return circle(prog)
})}
</div>
</div>
`
Expand Down
10 changes: 5 additions & 5 deletions client/js/components/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ module.exports = (state, emit) => {
const intro = () => emit('help:show')
return html`
${button({
icon: '/public/img/question.svg',
text: 'Help',
klass: 'btn btn--green btn__reveal-text dat-button--help',
click: intro
})}
icon: '/public/img/question.svg',
text: 'Help',
klass: 'btn btn--green btn__reveal-text dat-button--help',
click: intro
})}
`
}
4 changes: 2 additions & 2 deletions client/js/components/hyperdrive/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ module.exports = function (state, emit) {
}
}
}
emit('archive:update', {updatedAt: updated})
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)
return true
} else {
entry.archiveKey = state.archive.key
emit('preview:file', {entry: entry}, noop)
emit('preview:file', { entry: entry }, noop)
return false
}
}
Expand Down
4 changes: 2 additions & 2 deletions client/js/components/import-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ module.exports = (state, emit) => {
return html`<table id="import-queue">
${writing ? renderLi(writing, writingProgressPct) : null}
${next.map(function (file) {
return renderLi(file, null)
})}
return renderLi(file, null)
})}
</table>`
} else {
return html`<table id="import-queue"></table>`
Expand Down
19 changes: 11 additions & 8 deletions client/js/components/login-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,25 @@ var avatarStyles = css`
`

module.exports = function (state, emit) {
if (state) return html`` // always true
// Hide login button
//
if (module.parent || !state.township.whoami) return html``
if (state.township.email) {
return html`
${button({
text: gravatar({email: state.township.email}, {}, avatarStyles),
click: () => emit('township:sidePanel'),
klass: 'btn bn pr0'
})}
text: gravatar({ email: state.township.email }, {}, avatarStyles),
click: () => emit('township:sidePanel'),
klass: 'btn bn pr0'
})}
`
} else {
return html`
${button({
text: 'Log In',
click: function () { window.location.href = '/login' },
klass: 'btn btn--full btn--green'
})}
text: 'Log In',
click: function () { window.location.href = '/login' },
klass: 'btn btn--full btn--green'
})}
`
}
}
4 changes: 2 additions & 2 deletions client/js/elements/404/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ module.exports = function (props) {
}
var icon
if (props.icon) {
icon = datIcon(props.icon, {class: 'w3'})
icon = datIcon(props.icon, { class: 'w3' })
} if (props.icon === 'loader') {
icon = loaderIcon()
} else {
icon = datIcon('sad-dat', {class: 'w3 color-green'})
icon = datIcon('sad-dat', { class: 'w3 color-green' })
}

return html`
Expand Down
12 changes: 1 addition & 11 deletions client/js/elements/footer/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
const html = require('choo/html')
const css = require('sheetify')

module.exports = function () {
return html`
<footer class="pv2 bg-neutral white w-100">
<section class="ph2 ph4-m mw8-ns center-ns">
<div class="pt3">
<div class="mb2 lh-copy">
<a class="f4 b white dib dim link hover-color-white mr3 mt1" href="/" title="Dat Project">
<img src="/public/img/dat-hexagon.svg" class="dib w2 h2 mr2 v-mid mb1" alt="Dat Project">
datBase
</a>
<a class="f4 link white hover-color-neutral-40 b dib mr3 mb3" href="http://blog.datproject.org" title="Blog - Dat Project">
Blog
</a>
</div>
<div class="mt3">
<a class="white hover-color-white ba b--green no-underline grow b inline-flex items-center mr3 mb3 pv2 ph3" href="https://datproject.org" title="Dat Project Home">
<div class="color-green dib mr2"><svg class="w2 h2"><use xlink:href="#daticon-happy-dat"/></svg></div>
Expand All @@ -36,7 +26,7 @@ module.exports = function () {
</p>
</div>
<p class="bt b--dat-neutral-80 color-neutral-50 tc f7 pv2">
<strong>Dat</strong> 2017 • Page source on <a class="color-neutral-50 hover-color-pink" href="https://github.com/datproject/datbase.org">github</a>
<strong>Dat</strong> 2019 • Page source on <a class="color-neutral-50 hover-color-pink" href="https://github.com/datproject/datbase.org">github</a>
</p>
</section>
</footer>
Expand Down
2 changes: 1 addition & 1 deletion client/js/elements/gravatar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = function (user, opts, cls) {
if (!user || !user.email) return html``
if (!opts) opts = {}
if (!cls) cls = ''
var _opts = xtend({s: '200', r: 'pg', d: 'retro'}, opts)
var _opts = xtend({ s: '200', r: 'pg', d: 'retro' }, opts)
var url = gravatar.url(user.email, _opts)
return html`
<img class="${cls}" src="${url}" width=${_opts.s} height=${_opts.s} />
Expand Down
4 changes: 2 additions & 2 deletions client/js/elements/home-section/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ module.exports = function (props) {
</header>
<div class="pt3 cf">
${props.sections.map((section) => {
return textSection(section)
})}
return textSection(section)
})}
</div>
${cta()}
</div>
Expand Down
4 changes: 2 additions & 2 deletions client/js/elements/icon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ module.exports = iconElement
function iconElement (iconName, opts) {
opts = opts || {}

assert.equal(typeof iconName, 'string', 'elements/icon: iconName should be type string')
assert.equal(typeof opts, 'object', 'elements/icon: opts should be type object')
assert.strictEqual(typeof iconName, 'string', 'elements/icon: iconName should be type string')
assert.strictEqual(typeof opts, 'object', 'elements/icon: opts should be type object')

var classNames = 'icon-' + iconName + ' ' + prefix
if (opts.class) classNames += (' ' + opts.class)
Expand Down
14 changes: 7 additions & 7 deletions client/js/models/archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@ module.exports = function (state, emitter) {
emitter.on('archive:directory', function (root) {
var path = root === '.' ? '' : `/contents/${root}`
emitter.emit('pushState', `/dat://${state.archive.key}${path}`)
emitter.emit('archive:update', {root: root})
emitter.emit('archive:update', { root: root })
})

emitter.on('archive:health', function (data) {
http({url: `/health/${state.archive.key}`, method: 'GET', json: true}, function (err, resp, json) {
http({ url: `/health/${state.archive.key}`, method: 'GET', json: true }, function (err, resp, json) {
if (err) console.error(err)
emitter.emit('archive:update', {health: json})
emitter.emit('archive:update', { health: json })
})
})

emitter.on('archive:getMetadata', function (data) {
if (!state.archive.key || state.archive.fetching) return
state.archive.fetching = true
http({url: `/metadata/${state.archive.key}?timeout=${data.timeout}`, method: 'GET', json: true}, function (err, resp, json) {
http({ url: `/metadata/${state.archive.key}?timeout=${data.timeout}`, method: 'GET', json: true }, function (err, resp, json) {
json.fetching = false
json.retries = state.archive.retries + 1
if (err) return emitter.emit('archive:update', xtend({error: {message: err.message}}, json))
if (err) return emitter.emit('archive:update', xtend({ error: { message: err.message } }, json))
if (json.error) return emitter.emit('archive:update', json)
if (json.entries) json.error = null
emitter.emit('archive:update', json)
})
})
emitter.on('archive:delete', function (data) {
api.dats.delete({id: data.id}, function (err, resp, json) {
if (err) return emitter.emit('archive:update', {error: {message: err.message}})
api.dats.delete({ id: data.id }, function (err, resp, json) {
if (err) return emitter.emit('archive:update', { error: { message: err.message } })
emitter.emit('pushState', '/profile')
})
})
Expand Down
10 changes: 5 additions & 5 deletions client/js/models/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module.exports = function (state, emitter) {
emitter.emit('message:clear')
})
emitter.on('message:update', function (data) {
state.message = {message: data.message, type: data.type}
state.message = { message: data.message, type: data.type }
emitter.emit('render')
})
emitter.on('message:clear', function (data) {
state.message = {message: '', type: ''}
state.message = { message: '', type: '' }
emitter.emit('render')
})

Expand All @@ -19,12 +19,12 @@ module.exports = function (state, emitter) {
})

emitter.on('message:success', function (message) {
emitter.emit('message:new', {message: message, type: 'success'})
emitter.emit('message:new', { message: message, type: 'success' })
})
emitter.on('message:error', function (message) {
emitter.emit('message:new', {message: message, type: 'error'})
emitter.emit('message:new', { message: message, type: 'error' })
})
emitter.on('message:warning', function (message) {
emitter.emit('message:new', {message: message, type: 'warning'})
emitter.emit('message:new', { message: message, type: 'warning' })
})
}
2 changes: 1 addition & 1 deletion client/js/models/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = function (state, emitter) {
})

emitter.on('preview:openPanel', function (data) {
emitter.emit('preview:update', {isPanelOpen: true, error: null})
emitter.emit('preview:update', { isPanelOpen: true, error: null })
})

emitter.on('preview:file', function (data) {
Expand Down
10 changes: 5 additions & 5 deletions client/js/models/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ module.exports = function (state, emitter) {

emitter.on('profile:delete', function (data) {
api.users.delete(data, function (err, resp, json) {
if (err) return emitter.emit('township:update', {error: err.message})
emitter.emit('profile:update', {profile: defaults.profile})
if (err) return emitter.emit('township:update', { error: err.message })
emitter.emit('profile:update', { profile: defaults.profile })
emitter.emit('township:logout')
window.location.href = '/'
})
})

emitter.on('profile:edit', function (data) {
api.users.update(data, function (err, resp, json) {
if (err) return emitter.emit('township:update', {error: err.message})
emitter.emit('township:update', {profile: data})
if (err) return emitter.emit('township:update', { error: err.message })
emitter.emit('township:update', { profile: data })
emitter.emit('message:success', 'Profile edited successfully!')
})
})
Expand All @@ -30,7 +30,7 @@ module.exports = function (state, emitter) {
if (err) return emitter.emit('message:error', err.message)
if (!json.length) return emitter.emit('message:error', 'User not found.')
var user = json[0]
api.dats.get({user_id: user.id}, function (err, resp, results) {
api.dats.get({ user_id: user.id }, function (err, resp, results) {
if (err) return emitter.emit('message:error', err.message)
user.dats = results
emitter.emit('profile:update', user)
Expand Down
16 changes: 8 additions & 8 deletions client/js/models/township.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ module.exports = function (state, emitter) {
emitter.on('township:whoami', function (data) {
const user = api.whoami()
if (user.username) {
api.users.get({username: user.username}, function (err, resp, results) {
api.users.get({ username: user.username }, function (err, resp, results) {
if (err && err.message === 'jwt expired') {
emitter.emit('township:logout', data)
return done()
}
if (!results.length) return done()
var newState = user
newState.profile = results[0]
api.dats.get({user_id: user.id}, function (err, resp, results) {
api.dats.get({ user_id: user.id }, function (err, resp, results) {
if (err && err.message === 'jwt expired') {
emitter.emit('township:logout', data)
return done()
Expand All @@ -48,15 +48,15 @@ module.exports = function (state, emitter) {

emitter.on('township:logout', function (data) {
api.logout(data, function (err, resp, data) {
if (err) return emitter.emit('township:update', {error: err.message})
if (err) return emitter.emit('township:update', { error: err.message })
emitter.emit('township:update', defaults.township)
emitter.emit('message:success', 'Successfully Logged Out')
})
})

emitter.on('township:login', function (data) {
api.login(data, function (err, resp, data) {
if (err) return emitter.emit('township:update', {error: err.message})
if (err) return emitter.emit('township:update', { error: err.message })
data.login = 'hidden'
emitter.emit('township:update', data)
window.location.href = '/' + data.username
Expand All @@ -65,7 +65,7 @@ module.exports = function (state, emitter) {

emitter.on('township:register', function (data) {
api.register(data, function (err, resp, data) {
if (err) return emitter.emit('township:error', {error: err.message})
if (err) return emitter.emit('township:error', { error: err.message })
data.register = 'hidden'
emitter.emit('township:update', data)
window.location.href = '/profile/edit'
Expand All @@ -74,16 +74,16 @@ module.exports = function (state, emitter) {

emitter.on('township:resetPassword', function (data) {
var email = data || state.township.account.auth.basic.email
api.users.resetPassword({email}, function (err, res, body) {
api.users.resetPassword({ email }, function (err, res, body) {
if (err) return emitter.emit('township:error', err.message)
emitter.emit('township:update', {passwordResetResponse: body.message})
emitter.emit('township:update', { passwordResetResponse: body.message })
})
})

emitter.on('township:resetPasswordConfirmation', function (data) {
api.users.resetPasswordConfirmation(data, function (err, res, body) {
if (err) return emitter.emit('township:error', err.message)
emitter.emit('township:update', {passwordResetConfirmResponse: body.message, passwordResetResponse: null})
emitter.emit('township:update', { passwordResetConfirmResponse: body.message, passwordResetResponse: null })
})
})

Expand Down
Loading