Refactor Patron code
This commit is contained in:
parent
751261a173
commit
0dc085411c
3 changed files with 20 additions and 21 deletions
|
@ -1,10 +1,12 @@
|
|||
import api from '../api';
|
||||
|
||||
export const PATRON_FUNDING_IMPORT = 'PATRON_FUNDING_IMPORT';
|
||||
export const PATRON_FUNDING_FETCH_FAIL = 'PATRON_FUNDING_FETCH_FAIL';
|
||||
export const PATRON_INSTANCE_FETCH_REQUEST = 'PATRON_INSTANCE_FETCH_REQUEST';
|
||||
export const PATRON_INSTANCE_FETCH_SUCCESS = 'PATRON_INSTANCE_FETCH_SUCCESS';
|
||||
export const PATRON_INSTANCE_FETCH_FAIL = 'PATRON_INSTANCE_FETCH_FAIL';
|
||||
|
||||
export function fetchFunding() {
|
||||
export function fetchPatronInstance() {
|
||||
return (dispatch, getState) => {
|
||||
dispatch({ type: PATRON_INSTANCE_FETCH_REQUEST });
|
||||
api(getState).get('/api/patron/v1/instance').then(response => {
|
||||
dispatch(importFetchedFunding(response.data));
|
||||
}).catch(error => {
|
||||
|
@ -13,16 +15,16 @@ export function fetchFunding() {
|
|||
};
|
||||
};
|
||||
|
||||
export function importFetchedFunding(funding) {
|
||||
export function importFetchedFunding(instance) {
|
||||
return {
|
||||
type: PATRON_FUNDING_IMPORT,
|
||||
funding,
|
||||
type: PATRON_INSTANCE_FETCH_SUCCESS,
|
||||
instance,
|
||||
};
|
||||
}
|
||||
|
||||
export function fetchFundingFail(error) {
|
||||
return {
|
||||
type: PATRON_FUNDING_FETCH_FAIL,
|
||||
type: PATRON_INSTANCE_FETCH_FAIL,
|
||||
error,
|
||||
skipAlert: true,
|
||||
};
|
||||
|
|
|
@ -3,7 +3,7 @@ import { connect } from 'react-redux';
|
|||
import { injectIntl } from 'react-intl';
|
||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||
import ProgressBar from '../../../components/progress_bar';
|
||||
import { fetchFunding } from 'soapbox/actions/patron';
|
||||
import { fetchPatronInstance } from 'soapbox/actions/patron';
|
||||
|
||||
const moneyFormat = amount => (
|
||||
new Intl
|
||||
|
@ -18,19 +18,16 @@ const moneyFormat = amount => (
|
|||
class FundingPanel extends ImmutablePureComponent {
|
||||
|
||||
componentDidMount() {
|
||||
this.props.dispatch(fetchFunding());
|
||||
this.props.dispatch(fetchPatronInstance());
|
||||
}
|
||||
|
||||
render() {
|
||||
const { funding, patronUrl } = this.props;
|
||||
const { patron, patronUrl } = this.props;
|
||||
if (patron.isEmpty()) return null;
|
||||
|
||||
if (!funding) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const amount = funding.getIn(['funding', 'amount']);
|
||||
const goal = funding.getIn(['goals', '0', 'amount']);
|
||||
const goal_text = funding.getIn(['goals', '0', 'text']);
|
||||
const amount = patron.getIn(['funding', 'amount']);
|
||||
const goal = patron.getIn(['goals', '0', 'amount']);
|
||||
const goal_text = patron.getIn(['goals', '0', 'text']);
|
||||
const goal_reached = amount >= goal;
|
||||
let ratio_text;
|
||||
|
||||
|
@ -66,7 +63,7 @@ class FundingPanel extends ImmutablePureComponent {
|
|||
|
||||
const mapStateToProps = state => {
|
||||
return {
|
||||
funding: state.getIn(['patron', 'funding']),
|
||||
patron: state.get('patron'),
|
||||
patronUrl: state.getIn(['soapbox', 'extensions', 'patron', 'baseUrl']),
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import { PATRON_FUNDING_IMPORT } from '../actions/patron';
|
||||
import { PATRON_INSTANCE_FETCH_SUCCESS } from '../actions/patron';
|
||||
import { Map as ImmutableMap, fromJS } from 'immutable';
|
||||
|
||||
const initialState = ImmutableMap();
|
||||
|
||||
export default function patron(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case PATRON_FUNDING_IMPORT:
|
||||
return state.set('funding', fromJS(action.funding));
|
||||
case PATRON_INSTANCE_FETCH_SUCCESS:
|
||||
return fromJS(action.instance);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue