2018-09-10 09:55:26 -07:00
|
|
|
import { AppState } from 'store/reducers';
|
2018-10-04 21:27:02 -07:00
|
|
|
import { ProposalWithCrowdFund, ProposalComments, ProposalUpdates } from 'types';
|
2018-09-10 09:55:26 -07:00
|
|
|
|
|
|
|
export function getProposals(state: AppState) {
|
|
|
|
return state.proposal.proposals;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getProposal(
|
|
|
|
state: AppState,
|
|
|
|
proposalId: ProposalWithCrowdFund['proposalId'],
|
|
|
|
): ProposalWithCrowdFund | null {
|
|
|
|
return (
|
|
|
|
state.proposal.proposals.find(
|
|
|
|
(p: ProposalWithCrowdFund) => p.proposalId === proposalId,
|
|
|
|
) || null
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-11-07 09:33:19 -08:00
|
|
|
export function getProposalByAddress(
|
|
|
|
state: AppState,
|
|
|
|
proposalAddress: ProposalWithCrowdFund['proposalAddress'],
|
|
|
|
): ProposalWithCrowdFund | null {
|
|
|
|
return (
|
|
|
|
state.proposal.proposals.find(
|
|
|
|
(p: ProposalWithCrowdFund) => p.proposalAddress === proposalAddress,
|
|
|
|
) || null
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-09-10 09:55:26 -07:00
|
|
|
export function getProposalComments(
|
|
|
|
state: AppState,
|
|
|
|
proposalId: ProposalWithCrowdFund['proposalId'],
|
|
|
|
): ProposalComments['comments'] | null {
|
|
|
|
const pc = state.proposal.proposalComments[proposalId];
|
|
|
|
return pc ? pc.comments : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getProposalCommentCount(
|
|
|
|
state: AppState,
|
|
|
|
proposalId: ProposalWithCrowdFund['proposalId'],
|
|
|
|
): ProposalComments['totalComments'] | null {
|
|
|
|
const pc = state.proposal.proposalComments[proposalId];
|
|
|
|
return pc ? pc.totalComments : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getIsFetchingComments(state: AppState) {
|
|
|
|
return state.proposal.isFetchingComments;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getCommentsError(state: AppState) {
|
|
|
|
return state.proposal.commentsError;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getProposalUpdates(
|
|
|
|
state: AppState,
|
|
|
|
proposalId: ProposalWithCrowdFund['proposalId'],
|
|
|
|
): ProposalUpdates['updates'] | null {
|
|
|
|
const pu = state.proposal.proposalUpdates[proposalId];
|
|
|
|
return pu ? pu.updates : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getProposalUpdateCount(
|
|
|
|
state: AppState,
|
|
|
|
proposalId: ProposalWithCrowdFund['proposalId'],
|
2018-11-02 09:24:28 -07:00
|
|
|
): number | null {
|
2018-09-10 09:55:26 -07:00
|
|
|
const pu = state.proposal.proposalUpdates[proposalId];
|
2018-11-02 09:24:28 -07:00
|
|
|
return pu ? pu.updates.length : null;
|
2018-09-10 09:55:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getIsFetchingUpdates(state: AppState) {
|
|
|
|
return state.proposal.isFetchingUpdates;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getUpdatesError(state: AppState) {
|
|
|
|
return state.proposal.updatesError;
|
|
|
|
}
|