2017-04-29 11:50:29 +02:00
|
|
|
import * as types from 'constants/action_types'
|
|
|
|
import lbry from 'lbry'
|
2017-04-29 19:02:25 +02:00
|
|
|
import {
|
|
|
|
selectCurrentUri,
|
|
|
|
} from 'selectors/app'
|
2017-04-29 11:50:29 +02:00
|
|
|
|
|
|
|
export function doFetchUriAvailability(uri) {
|
|
|
|
return function(dispatch, getState) {
|
|
|
|
dispatch({
|
|
|
|
type: types.FETCH_AVAILABILITY_STARTED,
|
|
|
|
data: { uri }
|
|
|
|
})
|
|
|
|
|
2017-04-29 19:02:25 +02:00
|
|
|
const successCallback = (availability) => {
|
2017-04-29 11:50:29 +02:00
|
|
|
dispatch({
|
2017-04-29 19:02:25 +02:00
|
|
|
type: types.FETCH_AVAILABILITY_COMPLETED,
|
2017-04-29 11:50:29 +02:00
|
|
|
data: {
|
|
|
|
availability,
|
|
|
|
uri,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2017-04-29 19:02:25 +02:00
|
|
|
|
|
|
|
const errorCallback = () => {
|
|
|
|
console.debug('error')
|
|
|
|
}
|
|
|
|
|
|
|
|
lbry.get_availability({ uri }, successCallback, errorCallback)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function doFetchCurrentUriAvailability() {
|
|
|
|
return function(dispatch, getState) {
|
|
|
|
const state = getState()
|
|
|
|
const uri = selectCurrentUri(state)
|
|
|
|
|
|
|
|
dispatch(doFetchUriAvailability(uri))
|
2017-04-29 11:50:29 +02:00
|
|
|
}
|
|
|
|
}
|