2017-04-23 11:56:50 +02:00
|
|
|
import { createSelector } from 'reselect'
|
|
|
|
import {
|
|
|
|
selectDaemonReady,
|
|
|
|
selectCurrentPage,
|
2017-04-24 09:25:27 +02:00
|
|
|
selectCurrentUri,
|
2017-04-23 11:56:50 +02:00
|
|
|
} from 'selectors/app'
|
|
|
|
|
|
|
|
export const _selectState = state => state.content || {}
|
|
|
|
|
2017-05-04 05:44:08 +02:00
|
|
|
export const selectFeaturedUris = createSelector(
|
2017-04-23 11:56:50 +02:00
|
|
|
_selectState,
|
2017-05-04 05:44:08 +02:00
|
|
|
(state) => state.featuredUris || {}
|
2017-04-23 11:56:50 +02:00
|
|
|
)
|
|
|
|
|
2017-05-04 05:44:08 +02:00
|
|
|
export const selectFetchingFeaturedUris = createSelector(
|
2017-04-23 11:56:50 +02:00
|
|
|
_selectState,
|
|
|
|
(state) => !!state.fetchingFeaturedContent
|
|
|
|
)
|
|
|
|
|
2017-05-04 05:44:08 +02:00
|
|
|
export const shouldFetchFeaturedUris = createSelector(
|
2017-04-23 11:56:50 +02:00
|
|
|
selectDaemonReady,
|
|
|
|
selectCurrentPage,
|
2017-05-04 05:44:08 +02:00
|
|
|
selectFetchingFeaturedUris,
|
|
|
|
selectFeaturedUris,
|
2017-04-23 11:56:50 +02:00
|
|
|
(daemonReady, page, fetching, byCategory) => {
|
|
|
|
if (!daemonReady) return false
|
|
|
|
if (page != 'discover') return false
|
|
|
|
if (fetching) return false
|
|
|
|
if (Object.keys(byCategory).length != 0) return false
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
)
|
2017-04-23 16:01:00 +02:00
|
|
|
|
2017-04-24 09:25:27 +02:00
|
|
|
export const selectFetchingFileInfos = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => state.fetchingFileInfos || {}
|
|
|
|
)
|
|
|
|
|
2017-04-23 18:10:45 +02:00
|
|
|
export const selectFetchingDownloadedContent = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => !!state.fetchingDownloadedContent
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectDownloadedContent = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => state.downloadedContent || {}
|
|
|
|
)
|
|
|
|
|
2017-04-25 07:47:21 +02:00
|
|
|
export const selectDownloadedContentFileInfos = createSelector(
|
|
|
|
selectDownloadedContent,
|
|
|
|
(downloadedContent) => downloadedContent.fileInfos || []
|
|
|
|
)
|
|
|
|
|
2017-04-23 18:10:45 +02:00
|
|
|
export const shouldFetchDownloadedContent = createSelector(
|
|
|
|
selectDaemonReady,
|
|
|
|
selectCurrentPage,
|
|
|
|
selectFetchingDownloadedContent,
|
|
|
|
selectDownloadedContent,
|
|
|
|
(daemonReady, page, fetching, content) => {
|
|
|
|
if (!daemonReady) return false
|
|
|
|
if (page != 'downloaded') return false
|
|
|
|
if (fetching) return false
|
|
|
|
if (Object.keys(content).length != 0) return false
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectFetchingPublishedContent = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => !!state.fetchingPublishedContent
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectPublishedContent = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => state.publishedContent || {}
|
|
|
|
)
|
|
|
|
|
|
|
|
export const shouldFetchPublishedContent = createSelector(
|
|
|
|
selectDaemonReady,
|
|
|
|
selectCurrentPage,
|
|
|
|
selectFetchingPublishedContent,
|
|
|
|
selectPublishedContent,
|
|
|
|
(daemonReady, page, fetching, content) => {
|
|
|
|
if (!daemonReady) return false
|
|
|
|
if (page != 'published') return false
|
|
|
|
if (fetching) return false
|
|
|
|
if (Object.keys(content).length != 0) return false
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
)
|
2017-05-02 06:48:16 +02:00
|
|
|
|
|
|
|
export const selectResolvingUris = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => state.resolvingUris || []
|
|
|
|
)
|
|
|
|
|
|
|
|
const selectResolvingUri = (state, props) => {
|
|
|
|
return selectResolvingUris(state).indexOf(props.uri) != -1
|
|
|
|
}
|
|
|
|
|
|
|
|
export const makeSelectResolvingUri = () => {
|
|
|
|
return createSelector(
|
|
|
|
selectResolvingUri,
|
|
|
|
(resolving) => resolving
|
|
|
|
)
|
|
|
|
}
|