lbry-desktop/ui/js/actions/availability.js

29 lines
683 B
JavaScript
Raw Normal View History

import * as types from 'constants/action_types'
import lbry from 'lbry'
import {
2017-05-15 05:50:59 +02:00
selectFetchingAvailability
} from 'selectors/availability'
2017-05-15 05:50:59 +02:00
export function doFetchAvailability(uri) {
return function(dispatch, getState) {
2017-05-15 05:50:59 +02:00
const state = getState()
const alreadyFetching = !!selectFetchingAvailability(state)[uri]
2017-05-15 05:50:59 +02:00
if (!alreadyFetching) {
dispatch({
2017-05-15 05:50:59 +02:00
type: types.FETCH_AVAILABILITY_STARTED,
data: {uri}
})
2017-05-15 05:50:59 +02:00
lbry.get_availability({uri}).then((availability) => {
dispatch({
type: types.FETCH_AVAILABILITY_COMPLETED,
data: {
availability,
uri,
}
})
})
}
}
2017-05-15 05:50:59 +02:00
}