Patron updates
This commit is contained in:
parent
4b44959fc2
commit
73b275b8da
8 changed files with 34 additions and 23 deletions
|
@ -1,4 +1,3 @@
|
||||||
NODE_ENV=development
|
NODE_ENV=development
|
||||||
# BACKEND_URL="https://example.com"
|
# BACKEND_URL="https://example.com"
|
||||||
# PATRON_URL="https://patron.example.com"
|
|
||||||
# PROXY_HTTPS_INSECURE=false
|
# PROXY_HTTPS_INSECURE=false
|
||||||
|
|
|
@ -124,7 +124,7 @@ For https, be sure to also set `PROXY_HTTPS_INSECURE=true`.
|
||||||
|
|
||||||
Allows using an HTTPS backend if set to `true`.
|
Allows using an HTTPS backend if set to `true`.
|
||||||
|
|
||||||
This is needed if `BACKEND_URL` or `PATRON_URL` are set to an `https://` value.
|
This is needed if `BACKEND_URL` is set to an `https://` value.
|
||||||
[More info](https://stackoverflow.com/a/48624590/8811886).
|
[More info](https://stackoverflow.com/a/48624590/8811886).
|
||||||
|
|
||||||
**Default:** `false`
|
**Default:** `false`
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import api from '../api';
|
import axios from 'axios';
|
||||||
|
|
||||||
export const PATRON_FUNDING_IMPORT = 'PATRON_FUNDING_IMPORT';
|
export const PATRON_FUNDING_IMPORT = 'PATRON_FUNDING_IMPORT';
|
||||||
export const PATRON_FUNDING_FETCH_FAIL = 'PATRON_FUNDING_FETCH_FAIL';
|
export const PATRON_FUNDING_FETCH_FAIL = 'PATRON_FUNDING_FETCH_FAIL';
|
||||||
|
|
||||||
export function fetchFunding() {
|
export function fetchFunding() {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
api(getState).get('/patron/v1/funding').then(response => {
|
const baseUrl = getState().getIn(['soapbox', 'extensions', 'patron', 'baseUrl']);
|
||||||
|
axios.get(`${baseUrl}/api/patron/v1/instance`).then(response => {
|
||||||
dispatch(importFetchedFunding(response.data));
|
dispatch(importFetchedFunding(response.data));
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch(fetchFundingFail(error));
|
dispatch(fetchFundingFail(error));
|
||||||
|
|
|
@ -15,6 +15,7 @@ import { shortNumberFormat } from '../utils/numbers';
|
||||||
import { isStaff } from '../utils/accounts';
|
import { isStaff } from '../utils/accounts';
|
||||||
import { makeGetAccount } from '../selectors';
|
import { makeGetAccount } from '../selectors';
|
||||||
import { logOut } from 'soapbox/actions/auth';
|
import { logOut } from 'soapbox/actions/auth';
|
||||||
|
import { Map as ImmutableMap } from 'immutable';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
followers: { id: 'account.followers', defaultMessage: 'Followers' },
|
followers: { id: 'account.followers', defaultMessage: 'Followers' },
|
||||||
|
@ -39,11 +40,12 @@ const messages = defineMessages({
|
||||||
const mapStateToProps = state => {
|
const mapStateToProps = state => {
|
||||||
const me = state.get('me');
|
const me = state.get('me');
|
||||||
const getAccount = makeGetAccount();
|
const getAccount = makeGetAccount();
|
||||||
|
const patron = state.getIn(['soapbox', 'extensions', 'patron'], ImmutableMap());
|
||||||
|
|
||||||
return {
|
return {
|
||||||
account: getAccount(state, me),
|
account: getAccount(state, me),
|
||||||
sidebarOpen: state.get('sidebar').sidebarOpen,
|
sidebarOpen: state.get('sidebar').sidebarOpen,
|
||||||
hasPatron: state.getIn(['soapbox', 'extensions', 'patron']),
|
patronUrl: patron.get('enabled') && patron.get('baseUrl'),
|
||||||
isStaff: isStaff(state.getIn(['accounts', me])),
|
isStaff: isStaff(state.getIn(['accounts', me])),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -75,7 +77,7 @@ class SidebarMenu extends ImmutablePureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { sidebarOpen, onClose, intl, account, onClickLogOut, hasPatron, isStaff } = this.props;
|
const { sidebarOpen, onClose, intl, account, onClickLogOut, patronUrl, isStaff } = this.props;
|
||||||
if (!account) return null;
|
if (!account) return null;
|
||||||
const acct = account.get('acct');
|
const acct = account.get('acct');
|
||||||
|
|
||||||
|
@ -127,11 +129,11 @@ class SidebarMenu extends ImmutablePureComponent {
|
||||||
<Icon id='envelope' />
|
<Icon id='envelope' />
|
||||||
<span className='sidebar-menu-item__title'>{intl.formatMessage(messages.messages)}</span>
|
<span className='sidebar-menu-item__title'>{intl.formatMessage(messages.messages)}</span>
|
||||||
</NavLink>
|
</NavLink>
|
||||||
{hasPatron ?
|
{patronUrl ?
|
||||||
<NavLink className='sidebar-menu-item' to='/donate' onClick={onClose}>
|
<a className='sidebar-menu-item' href={patronUrl} onClick={onClose}>
|
||||||
<Icon id='dollar' />
|
<Icon id='dollar' />
|
||||||
<span className='sidebar-menu-item__title'>{intl.formatMessage(messages.donate)}</span>
|
<span className='sidebar-menu-item__title'>{intl.formatMessage(messages.donate)}</span>
|
||||||
</NavLink>
|
</a>
|
||||||
: ''}
|
: ''}
|
||||||
<NavLink className='sidebar-menu-item' to='/lists' onClick={onClose}>
|
<NavLink className='sidebar-menu-item' to='/lists' onClick={onClose}>
|
||||||
<Icon id='list' />
|
<Icon id='list' />
|
||||||
|
|
|
@ -5,6 +5,16 @@ import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||||
import ProgressBar from '../../../components/progress_bar';
|
import ProgressBar from '../../../components/progress_bar';
|
||||||
import { fetchFunding } from 'soapbox/actions/patron';
|
import { fetchFunding } from 'soapbox/actions/patron';
|
||||||
|
|
||||||
|
const moneyFormat = amount => (
|
||||||
|
new Intl
|
||||||
|
.NumberFormat('en-US', {
|
||||||
|
style: 'currency',
|
||||||
|
currency: 'usd',
|
||||||
|
notation: 'compact',
|
||||||
|
})
|
||||||
|
.format(amount/100)
|
||||||
|
);
|
||||||
|
|
||||||
class FundingPanel extends ImmutablePureComponent {
|
class FundingPanel extends ImmutablePureComponent {
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
@ -12,21 +22,22 @@ class FundingPanel extends ImmutablePureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { funding } = this.props;
|
const { funding, patronUrl } = this.props;
|
||||||
|
|
||||||
if (!funding) {
|
if (!funding) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const amount = funding.getIn(['funding', 'amount']);
|
||||||
const goal = funding.getIn(['goals', '0', 'amount']);
|
const goal = funding.getIn(['goals', '0', 'amount']);
|
||||||
const goal_text = funding.getIn(['goals', '0', 'text']);
|
const goal_text = funding.getIn(['goals', '0', 'text']);
|
||||||
const goal_reached = funding.get('amount') >= goal;
|
const goal_reached = amount >= goal;
|
||||||
let ratio_text;
|
let ratio_text;
|
||||||
|
|
||||||
if (goal_reached) {
|
if (goal_reached) {
|
||||||
ratio_text = <><strong>${Math.floor(goal/100)}</strong> per month<span className='funding-panel__reached'>— reached!</span></>;
|
ratio_text = <><strong>{moneyFormat(goal)}</strong> per month<span className='funding-panel__reached'>— reached!</span></>;
|
||||||
} else {
|
} else {
|
||||||
ratio_text = <><strong>${Math.floor(funding.get('amount')/100)} out of ${Math.floor(goal/100)}</strong> per month</>;
|
ratio_text = <><strong>{moneyFormat(amount)} out of {moneyFormat(goal)}</strong> per month</>;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -41,11 +52,11 @@ class FundingPanel extends ImmutablePureComponent {
|
||||||
<div className='funding-panel__ratio'>
|
<div className='funding-panel__ratio'>
|
||||||
{ratio_text}
|
{ratio_text}
|
||||||
</div>
|
</div>
|
||||||
<ProgressBar progress={funding.get('amount')/goal} />
|
<ProgressBar progress={amount/goal} />
|
||||||
<div className='funding-panel__description'>
|
<div className='funding-panel__description'>
|
||||||
{goal_text}
|
{goal_text}
|
||||||
</div>
|
</div>
|
||||||
<a className='button' href='/donate'>Donate</a>
|
{patronUrl && <a className='button' href={patronUrl}>Donate</a>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -56,6 +67,7 @@ class FundingPanel extends ImmutablePureComponent {
|
||||||
const mapStateToProps = state => {
|
const mapStateToProps = state => {
|
||||||
return {
|
return {
|
||||||
funding: state.getIn(['patron', 'funding']),
|
funding: state.getIn(['patron', 'funding']),
|
||||||
|
patronUrl: state.getIn(['soapbox', 'extensions', 'patron', 'baseUrl']),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ const mapStateToProps = state => {
|
||||||
const me = state.get('me');
|
const me = state.get('me');
|
||||||
return {
|
return {
|
||||||
account: state.getIn(['accounts', me]),
|
account: state.getIn(['accounts', me]),
|
||||||
hasPatron: state.getIn(['soapbox', 'extensions', 'patron']),
|
hasPatron: state.getIn(['soapbox', 'extensions', 'patron', 'enabled']),
|
||||||
features: getFeatures(state.get('instance')),
|
features: getFeatures(state.get('instance')),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,7 +13,10 @@
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
"extensions": {
|
"extensions": {
|
||||||
"patron": false
|
"patron": {
|
||||||
|
"enabled": false,
|
||||||
|
"baseUrl": "https://patron.example.com"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"defaultSettings": {
|
"defaultSettings": {
|
||||||
"autoPlayGif": false,
|
"autoPlayGif": false,
|
||||||
|
|
|
@ -9,7 +9,6 @@ const { settings, output } = require('./configuration');
|
||||||
const watchOptions = {};
|
const watchOptions = {};
|
||||||
|
|
||||||
const backendUrl = process.env.BACKEND_URL || 'http://localhost:4000';
|
const backendUrl = process.env.BACKEND_URL || 'http://localhost:4000';
|
||||||
const patronUrl = process.env.PATRON_URL || 'http://localhost:5000';
|
|
||||||
const secureProxy = !(process.env.PROXY_HTTPS_INSECURE === 'true');
|
const secureProxy = !(process.env.PROXY_HTTPS_INSECURE === 'true');
|
||||||
|
|
||||||
const backendEndpoints = [
|
const backendEndpoints = [
|
||||||
|
@ -22,7 +21,6 @@ const backendEndpoints = [
|
||||||
'/.well-known/webfinger',
|
'/.well-known/webfinger',
|
||||||
'/static',
|
'/static',
|
||||||
'/emoji',
|
'/emoji',
|
||||||
'/patron',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const makeProxyConfig = () => {
|
const makeProxyConfig = () => {
|
||||||
|
@ -33,10 +31,6 @@ const makeProxyConfig = () => {
|
||||||
secure: secureProxy,
|
secure: secureProxy,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
proxyConfig['/patron'] = {
|
|
||||||
target: patronUrl,
|
|
||||||
secure: secureProxy,
|
|
||||||
};
|
|
||||||
return proxyConfig;
|
return proxyConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue