2021-12-31 18:52:26 +01:00
|
|
|
// @flow
|
2021-10-08 05:47:39 +02:00
|
|
|
import { createSelector } from 'reselect';
|
2021-12-31 18:52:26 +01:00
|
|
|
import { selectClaimIdForUri } from 'redux/selectors/claims';
|
2021-10-08 05:47:39 +02:00
|
|
|
|
2021-12-31 18:52:26 +01:00
|
|
|
type State = { claims: any };
|
2021-10-08 05:47:39 +02:00
|
|
|
const selectState = state => state.stats || {};
|
|
|
|
export const selectViewCount = createSelector(selectState, state => state.viewCountById);
|
|
|
|
export const selectSubCount = createSelector(selectState, state => state.subCountById);
|
|
|
|
|
2021-12-31 18:52:26 +01:00
|
|
|
export const selectViewCountForUri = (state: State, uri: string) => {
|
|
|
|
const claimId = selectClaimIdForUri(state, uri);
|
|
|
|
const viewCountById = selectViewCount(state);
|
|
|
|
return claimId ? viewCountById[claimId] || 0 : 0;
|
|
|
|
};
|
2021-10-08 05:47:39 +02:00
|
|
|
|
2021-12-31 18:52:26 +01:00
|
|
|
export const selectSubCountForUri = (state: State, uri: string) => {
|
|
|
|
const claimId = selectClaimIdForUri(state, uri);
|
|
|
|
const subCountById = selectSubCount(state);
|
|
|
|
return claimId ? subCountById[claimId] || 0 : 0;
|
|
|
|
};
|