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 {
|
2017-05-15 05:50:59 +02:00
|
|
|
selectFetchingAvailability
|
|
|
|
} from 'selectors/availability'
|
2017-04-29 11:50:29 +02:00
|
|
|
|
2017-05-15 05:50:59 +02:00
|
|
|
export function doFetchAvailability(uri) {
|
2017-04-29 11:50:29 +02:00
|
|
|
return function(dispatch, getState) {
|
2017-05-15 05:50:59 +02:00
|
|
|
const state = getState()
|
|
|
|
const alreadyFetching = !!selectFetchingAvailability(state)[uri]
|
2017-04-29 11:50:29 +02:00
|
|
|
|
2017-05-15 05:50:59 +02:00
|
|
|
if (!alreadyFetching) {
|
2017-04-29 11:50:29 +02:00
|
|
|
dispatch({
|
2017-05-15 05:50:59 +02:00
|
|
|
type: types.FETCH_AVAILABILITY_STARTED,
|
|
|
|
data: {uri}
|
2017-04-29 11:50:29 +02:00
|
|
|
})
|
2017-04-29 19:02:25 +02:00
|
|
|
|
2017-05-15 05:50:59 +02:00
|
|
|
lbry.get_availability({uri}).then((availability) => {
|
|
|
|
dispatch({
|
|
|
|
type: types.FETCH_AVAILABILITY_COMPLETED,
|
|
|
|
data: {
|
|
|
|
availability,
|
|
|
|
uri,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
2017-04-29 19:02:25 +02:00
|
|
|
}
|
2017-04-29 11:50:29 +02:00
|
|
|
}
|
2017-05-15 05:50:59 +02:00
|
|
|
}
|