Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Commit

Permalink
fix delete 2 repos in a row (#236)
Browse files Browse the repository at this point in the history
* fix delete 2 repos in a row

* major refactor of modal handling

* standard

* format
  • Loading branch information
juliangruber authored and yoshuawuyts committed Feb 16, 2017
1 parent fcbfe7c commit 9c5da6a
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 191 deletions.
8 changes: 2 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,11 @@ persist(opts, (p) => {

app.router([
['/', params({
default: require('./pages/main'),
crash: require('./pages/main-crash'),
error: require('./pages/main-error'),
share: require('./pages/main-share'),
delete: require('./pages/main-delete')
default: require('./pages/main')
})]
])

mount('body', app.start())
mount('body div', app.start())
})

function onError (action) {
Expand Down
6 changes: 4 additions & 2 deletions elements/confirm-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ module.exports = createWidget
function createWidget () {
return Modal({
render: render,
onexit: onexit
onexit: onexit,
class: 'modal'
})

function onexit () {
window.history.back()
const el = document.querySelector('.modal')
if (el) el.parentNode.removeChild(el)
}

function render (cb) {
Expand Down
10 changes: 8 additions & 2 deletions elements/link-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,18 @@ function createModal () {
let link = ''
let el = ''

const modal = Modal({ onunload, onexit, render })
const modal = Modal({
onunload: onunload,
onexit: onexit,
render: render,
class: 'modal'
})

return modal

function onexit () {
window.history.back()
const el = document.querySelector('.modal')
if (el) el.parentNode.removeChild(el)
}

function onunload () {
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
</head>
<body>
<div></div>
<script>require('./bundle')</script>
</body>
</html>
26 changes: 9 additions & 17 deletions models/error.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const version = require('../package.json').version
const ipc = require('electron').ipcRenderer
const xhr = require('xhr')
const CrashModal = require('../elements/crash-modal')
const ErrorModal = require('../elements/error-modal')

module.exports = model

Expand All @@ -16,27 +18,13 @@ function model () {
effects: {
display: display,
quit: quit
},
reducers: {
clear: clear,
set: set
}
}
}

function set (state, error) {
return { message: error }
}

function clear () {
return { message: null }
}

function display (state, error, send, done) {
send('error:set', error, function (err) {
if (err) return done(err)
send('location:set', '?error=true', done)
})
const modal = ErrorModal()(error.message)
document.body.appendChild(modal)
}

function onUncaughtException (send, done) {
Expand All @@ -59,7 +47,11 @@ function onUncaughtException (send, done) {
xhr(opts, function (err) {
if (err) console.error(err)
})
send('location:set', '?crash=true', done)

const modal = CrashModal()(() => {
send('error:quit', done)
})
document.body.appendChild(modal)

err._thrown = true
throw err
Expand Down
33 changes: 9 additions & 24 deletions models/repos.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const assert = require('assert')
const mkdirp = require('mkdirp')
const open = require('open')
const path = require('path')
const ConfirmModal = require('../elements/confirm-modal')
const LinkModal = require('../elements/link-modal')

module.exports = createModel

Expand All @@ -35,7 +37,6 @@ function createModel () {
onIpc: handleIpc
},
reducers: {
setRemovalKey: setRemovalKey,
ready: multidatReady,
update: updateDats
},
Expand Down Expand Up @@ -86,10 +87,6 @@ function createModel () {
waterfall(tasks, done)
}

function setRemovalKey (state, key) {
return { removalKey: key }
}

// share state with external model
function shareState (state, data, send, done) {
done(null, state)
Expand Down Expand Up @@ -135,31 +132,19 @@ function createModel () {
}

function removeDat (state, data, send, done) {
if (!data.confirmed) {
assert.ok(data.key, 'repos-model.deleteDat: data.key should exist')
const encodedKey = encoding.encode(data.key)
const uri = window.location.href + '?delete=' + encodedKey
const key = encoding.toStr(data.key)
send('repos:setRemovalKey', key, function (err) {
if (err) return done(err)
send('location:set', uri, done)
})
} else {
// removalKey is a temporary hack because the callback in the modal is
// referencing the wrong onclick event
var key = state.removalKey
send('repos:setRemovalKey', null, function (err) {
if (err) return done(err)
manager.close(key, done)
})
}
const key = data.key
const modal = ConfirmModal()(function () {
manager.close(key, done)
})
document.body.appendChild(modal)
}

// copy a dat share link to clipboard and open a modal
function shareDat (state, data, send, done) {
assert.ok(data.key, 'repos-model.shareDat: data.key should exist')
const encodedKey = encoding.encode(data.key)
send('location:set', `?share=${encodedKey}`, done)
const modal = LinkModal()(encodedKey)
document.body.appendChild(modal)
}

function cloneDat (state, data, send, done) {
Expand Down
30 changes: 0 additions & 30 deletions pages/main-crash.js

This file was deleted.

37 changes: 0 additions & 37 deletions pages/main-delete.js

This file was deleted.

36 changes: 0 additions & 36 deletions pages/main-error.js

This file was deleted.

31 changes: 0 additions & 31 deletions pages/main-share.js

This file was deleted.

12 changes: 6 additions & 6 deletions pages/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,31 +86,31 @@ function mainView (state, prev, send) {
if (showWelcomeScreen) {
document.title = 'Dat Desktop | Welcome'
return html`
<body>
<div>
${sprite()}
${WelcomeScreen({
onexit: () => send('mainView:toggleWelcomeScreen', { toggle: false })
})}
</body>
</div>
`
}

if (!dats.length) {
return html`
<body>
<div>
${sprite()}
${header}
${EmptyState()}
</body>
</div>
`
}

return html`
<body>
<div>
${sprite()}
${header}
${Table(dats, send)}
</body>
</div>
`
}

Expand Down

0 comments on commit 9c5da6a

Please sign in to comment.