Skip to content
This repository has been archived by the owner on Jul 7, 2024. It is now read-only.
/ Orion Public archive

fix import from hash dialog #145

Merged
merged 6 commits into from
Jul 4, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
30 changes: 3 additions & 27 deletions app/windows/Import/Components/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,13 @@ import React from 'react'
import { Toolbar, Actionbar, Button } from 'react-photonkit'
import { observer } from 'mobx-react'

import { getObjectStat, getPeersWithObjectbyHash, importObjectByHash } from '../../../api'
import { importObjectByHash } from '../../../api'

@observer
class Footer extends React.Component {
_handleCheckButton () {
const storage = this.props.statsStore

// Prepare the promise to check the Peers
const pPeers = getPeersWithObjectbyHash(storage.hash)
.then(peers => {
storage.peersAmount = peers.length
storage.isLoading = false
this.forceUpdate()
})

// Prepare the promise to check the stats
const pStats = getObjectStat(storage.hash)
.then(stats => {
storage.stats = stats
storage.isLoading = false
this.forceUpdate()
})

storage.isLoading = true
storage.wasLoadingStats = true
// Now race! The first one shows stuff!
Promise.race([pPeers, pStats])
.catch(err => {
storage.isLoading = false
remote.dialog.showErrorBox('Gurl, an error occurred', `${err}`)
})
this.props.statsStore.check()
.then(() => { this.forceUpdate() })
}

_handleImportButton () {
Expand Down
3 changes: 2 additions & 1 deletion app/windows/Import/Components/Form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class Form extends React.Component {
if (isValid) {
this.props.statsStore.hash = hash
this.props.statsStore.isValid = isValid
this.forceUpdate()
this.props.statsStore.check()
.then(() => { this.forceUpdate() })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a catch here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The catch is in the stats store, shows an error dialog

}
}

Expand Down
30 changes: 30 additions & 0 deletions app/windows/Import/Stores/Stats.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { observable } from 'mobx'
import { remote } from 'electron'

import { getObjectStat, getPeersWithObjectbyHash } from '../../../api'

/**
* StatStorage will contain the status and few information about the Object.
Expand Down Expand Up @@ -31,6 +34,33 @@ export class StatStorage {
this.isLoading = false
this.wasLoading = false
this.importing = false
this.wasLoadingStats = false
}

check () {
// Prepare the promise to check the Peers
const pPeers = getPeersWithObjectbyHash(this.hash)
.then(peers => {
console.log('got peers', peers)
this.peersAmount = peers.length
this.isLoading = false
})

// Prepare the promise to check the stats
const pStats = getObjectStat(this.hash)
.then(stats => {
console.log('got stats')
this.stats = stats
this.isLoading = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about concurrency?
Should we have a isLoading both here and on line 46, or should we have a .then right after the Promise.all? What are the pro/cons of this?

Copy link
Contributor Author

@kernelwhisperer kernelwhisperer Jul 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, better to handle them in Promise.all

})

this.isLoading = true
this.wasLoadingStats = true
return Promise.all([pPeers, pStats])
.catch(err => {
this.isLoading = false
remote.dialog.showErrorBox('Gurl, an error occurred', `${err}`)
})
}
}

Expand Down