lbry-desktop/ui/js/actions/availability.js
2017-06-06 17:19:12 -04:00

27 lines
695 B
JavaScript

import * as types from "constants/action_types";
import lbry from "lbry";
import { selectFetchingAvailability } from "selectors/availability";
export function doFetchAvailability(uri) {
return function(dispatch, getState) {
const state = getState();
const alreadyFetching = !!selectFetchingAvailability(state)[uri];
if (!alreadyFetching) {
dispatch({
type: types.FETCH_AVAILABILITY_STARTED,
data: { uri },
});
lbry.get_availability({ uri }).then(availability => {
dispatch({
type: types.FETCH_AVAILABILITY_COMPLETED,
data: {
availability,
uri,
},
});
});
}
};
}