2017-04-29 11:50:29 +02:00
|
|
|
import {
|
|
|
|
createSelector,
|
|
|
|
} from 'reselect'
|
2017-04-29 19:02:25 +02:00
|
|
|
import {
|
|
|
|
selectDaemonReady,
|
|
|
|
selectCurrentPage,
|
|
|
|
selectCurrentUri,
|
|
|
|
} from 'selectors/app'
|
2017-04-29 11:50:29 +02:00
|
|
|
|
|
|
|
const _selectState = state => state.availability
|
|
|
|
|
|
|
|
export const selectAvailabilityByUri = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => state.byUri || {}
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectFetchingAvailability = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => state.fetching || {}
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectFetchingAvailabilityByUri = createSelector(
|
|
|
|
selectFetchingAvailability,
|
|
|
|
(fetching) => fetching.byUri || {}
|
|
|
|
)
|
|
|
|
|
|
|
|
const selectAvailabilityForUri = (state, props) => {
|
|
|
|
return selectAvailabilityByUri(state)[props.uri]
|
|
|
|
}
|
|
|
|
|
|
|
|
export const makeSelectAvailabilityForUri = () => {
|
|
|
|
return createSelector(
|
|
|
|
selectAvailabilityForUri,
|
|
|
|
(availability) => availability
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const selectFetchingAvailabilityForUri = (state, props) => {
|
|
|
|
return selectFetchingAvailabilityByUri(state)[props.uri]
|
|
|
|
}
|
|
|
|
|
|
|
|
export const makeSelectFetchingAvailabilityForUri = () => {
|
|
|
|
return createSelector(
|
|
|
|
selectFetchingAvailabilityForUri,
|
|
|
|
(fetching) => fetching
|
|
|
|
)
|
|
|
|
}
|
2017-04-29 19:02:25 +02:00
|
|
|
|
|
|
|
export const selectFetchingAvailabilityForCurrentUri = createSelector(
|
|
|
|
selectCurrentUri,
|
|
|
|
selectFetchingAvailabilityByUri,
|
|
|
|
(uri, byUri) => byUri[uri]
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectAvailabilityForCurrentUri = createSelector(
|
|
|
|
selectCurrentUri,
|
|
|
|
selectAvailabilityByUri,
|
|
|
|
(uri, byUri) => byUri[uri]
|
|
|
|
)
|
|
|
|
|
|
|
|
export const shouldFetchCurrentUriAvailability = createSelector(
|
|
|
|
selectDaemonReady,
|
|
|
|
selectCurrentPage,
|
|
|
|
selectFetchingAvailabilityForCurrentUri,
|
|
|
|
selectAvailabilityForCurrentUri,
|
|
|
|
(daemonReady, page, fetching, availability) => {
|
|
|
|
if (!daemonReady) return false
|
|
|
|
if (page != 'show') return false
|
|
|
|
if (fetching) return false
|
|
|
|
if (availability) return false
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
)
|