Commit 3dcb028f authored by Efe's avatar Efe Committed by Jonathan Porta
Browse files

create separate reducer file

parent 95fdc0c7
......@@ -391,14 +391,14 @@ module.exports = {
state => {
const user = state.user.get('current');
const currentUser = user && user.get('username');
const proposals = state.global.get('proposals', List());
const proposals = state.proposal.get('proposals', List());
const last = proposals.size - 1;
const last_id =
(proposals.size && proposals.get(last).get('id')) || null;
const newProposals =
proposals.size >= 10 ? proposals.delete(last) : proposals;
const voterProposals = state.global.get('voterProposals', List());
const votesInProgress = state.global.get(
const voterProposals = state.proposal.get('voterProposals', List());
const votesInProgress = state.proposal.get(
`transaction_proposal_vote_active_${currentUser}`,
List()
);
......
......@@ -32,10 +32,6 @@ const SHOW_DIALOG = 'global/SHOW_DIALOG';
const HIDE_DIALOG = 'global/HIDE_DIALOG';
const ADD_ACTIVE_WITNESS_VOTE = 'global/ADD_ACTIVE_WITNESS_VOTE';
const REMOVE_ACTIVE_WITNESS_VOTE = 'global/REMOVE_ACTIVE_WITNESS_VOTE';
const ADD_ACTIVE_PROPOSAL_VOTE = 'global/ADD_ACTIVE_PROPOSAL_VOTE';
const REMOVE_ACTIVE_PROPOSAL_VOTE = 'global/REMOVE_ACTIVE_PROPOSAL_VOTE';
const RECEIVE_LIST_PROPOSALS = 'global/RECEIVE_LIST_PROPOSALS';
const RECEIVE_LIST_VOTER_PROPOSALS = 'global/RECEIVE_LIST_VOTER_PROPOSALS';
// Saga-related:
export const GET_STATE = 'global/GET_STATE';
......@@ -326,32 +322,6 @@ export default function reducer(state = defaultState, action = {}) {
);
}
case ADD_ACTIVE_PROPOSAL_VOTE: {
return state.update(
`transaction_proposal_vote_active_${payload.voter}`,
List(),
l => l.push(payload.proposal_ids[0])
);
}
case REMOVE_ACTIVE_PROPOSAL_VOTE: {
return state.update(
`transaction_proposal_vote_active_${payload.voter}`,
List(),
l => l.delete(l.indexOf(payload.proposal_ids[0]))
);
}
case RECEIVE_LIST_PROPOSALS: {
const new_state = fromJS(payload);
return state.merge(new_state);
}
case RECEIVE_LIST_VOTER_PROPOSALS: {
const new_state = fromJS(payload);
return state.merge(new_state);
}
default:
return state;
}
......@@ -470,26 +440,6 @@ export const removeActiveWitnessVote = payload => ({
payload,
});
export const addActiveProposalVote = payload => ({
type: ADD_ACTIVE_PROPOSAL_VOTE,
payload,
});
export const removeActiveProposalVote = payload => ({
type: REMOVE_ACTIVE_PROPOSAL_VOTE,
payload,
});
export const receiveListProposals = payload => ({
type: RECEIVE_LIST_PROPOSALS,
payload,
});
export const receiveListVoterProposals = payload => ({
type: RECEIVE_LIST_VOTER_PROPOSALS,
payload,
});
export const getState = payload => ({
type: GET_STATE,
payload,
......
import { Map, Set, List, fromJS } from 'immutable';
const ADD_ACTIVE_PROPOSAL_VOTE = 'global/ADD_ACTIVE_PROPOSAL_VOTE';
const REMOVE_ACTIVE_PROPOSAL_VOTE = 'global/REMOVE_ACTIVE_PROPOSAL_VOTE';
const RECEIVE_LIST_PROPOSALS = 'global/RECEIVE_LIST_PROPOSALS';
const RECEIVE_LIST_VOTER_PROPOSALS = 'global/RECEIVE_LIST_VOTER_PROPOSALS';
export const defaultState = Map();
export default function reducer(state = defaultState, action = {}) {
const payload = action.payload;
switch (action.type) {
case ADD_ACTIVE_PROPOSAL_VOTE: {
return state.update(
`transaction_proposal_vote_active_${payload.voter}`,
List(),
l => l.push(payload.proposal_ids[0])
);
}
case REMOVE_ACTIVE_PROPOSAL_VOTE: {
return state.update(
`transaction_proposal_vote_active_${payload.voter}`,
List(),
l => l.delete(l.indexOf(payload.proposal_ids[0]))
);
}
case RECEIVE_LIST_PROPOSALS: {
const new_state = fromJS(payload);
return state.merge(new_state);
}
case RECEIVE_LIST_VOTER_PROPOSALS: {
const new_state = fromJS(payload);
return state.merge(new_state);
}
default:
return state;
}
}
export const addActiveProposalVote = payload => ({
type: ADD_ACTIVE_PROPOSAL_VOTE,
payload,
});
export const removeActiveProposalVote = payload => ({
type: REMOVE_ACTIVE_PROPOSAL_VOTE,
payload,
});
export const receiveListProposals = payload => ({
type: RECEIVE_LIST_PROPOSALS,
payload,
});
export const receiveListVoterProposals = payload => ({
type: RECEIVE_LIST_VOTER_PROPOSALS,
payload,
});
import { api } from '@blocktradesdev/steem-js';
import { call, put, takeEvery } from 'redux-saga/effects';
import * as globalActions from './GlobalReducer';
import * as proposalActions from './ProposalReducer';
const LIST_PROPOSALS = 'fetchDataSaga/LIST_PROPOSALS';
const LIST_VOTER_PROPOSALS = 'fetchDataSaga/LIST_VOTER_PROPOSALS';
......@@ -55,7 +55,7 @@ export function* listProposals({
}
}
yield put(globalActions.receiveListProposals({ proposals }));
yield put(proposalActions.receiveListProposals({ proposals }));
if (resolve && proposals) {
resolve(proposals);
} else if (reject && !proposals) {
......@@ -108,7 +108,7 @@ export function* listVoterProposals({
}
}
yield put(globalActions.receiveListVoterProposals({ voterProposals }));
yield put(proposalActions.receiveListVoterProposals({ voterProposals }));
if (resolve && voterProposals[start].length > 0) {
resolve(voterProposals);
} else if (reject && !voterProposals) {
......
......@@ -9,6 +9,7 @@ import marketReducer from './MarketReducer';
import userReducer from './UserReducer';
import transactionReducer from './TransactionReducer';
import offchainReducer from './OffchainReducer';
import proposalReducer from './ProposalReducer';
function initReducer(reducer, type) {
return (state, action) => {
......@@ -54,4 +55,5 @@ export default combineReducers({
routing: initReducer(routerReducer),
app: initReducer(appReducer),
form: formReducer,
proposal: initReducer(proposalReducer, 'proposal'),
});
......@@ -13,6 +13,7 @@ import * as appActions from 'app/redux/AppReducer';
import * as globalActions from 'app/redux/GlobalReducer';
import * as transactionActions from 'app/redux/TransactionReducer';
import * as userActions from 'app/redux/UserReducer';
import * as proposalActions from 'app/redux/ProposalReducer';
import { DEBT_TICKER } from 'app/client_config';
import { serverApiRecordEvent } from 'app/utils/ServerApiClient';
......@@ -88,7 +89,7 @@ function* preBroadcast_update_proposal_votes({ operation, username }) {
if (!operation.voter) operation.voter = username;
const { voter, proposal_ids } = operation;
yield put(
globalActions.addActiveProposalVote({
proposalActions.addActiveProposalVote({
voter,
proposal_ids,
})
......@@ -375,7 +376,7 @@ function* accepted_update_proposal_votes({
});
yield put(
globalActions.removeActiveProposalVote({
proposalActions.removeActiveProposalVote({
voter,
proposal_ids,
})
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment