Skip to content

Commit

Permalink
A full service slack counter integration
Browse files Browse the repository at this point in the history
  • Loading branch information
cereallarceny committed May 15, 2018
1 parent d455c29 commit 76bf46f
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 23 deletions.
7 changes: 2 additions & 5 deletions src/containers/app/routes/static/homepage/footer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ const CallsToAction = ({ movement }) => (
{movement.ctas.map((cta, key) => (
<div className="button-container" key={key}>
<ImageButton {...cta} color="white" />
{cta.count !== 0 && (
<span className="count">
{!cta.precise && '> '}
{cta.count.toLocaleString()} people
</span>
{cta.count && (
<span className="count">{cta.count.toLocaleString()} people</span>
)}
</div>
))}
Expand Down
3 changes: 2 additions & 1 deletion src/containers/app/routes/static/homepage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { withWrapper } from 'create-react-server/wrapper';
import { addNotification } from '../../../../../modules/notifications';
import { getGithubData } from '../../../../../modules/homepage';
import { getGithubData, getSlackData } from '../../../../../modules/homepage';
import { Page } from 'openmined-ui';

import FooterLinks from '../../../components/footer-links';
Expand All @@ -18,6 +18,7 @@ import Footer from './footer/';
class Homepage extends Component {
static async getInitialProps(props) {
await props.store.dispatch(getGithubData());
await props.store.dispatch(getSlackData());
}

render() {
Expand Down
14 changes: 4 additions & 10 deletions src/content/homepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,23 +317,17 @@ export default {
ctas: [
{
...buttons.contribute,
count: 0,
precise: true
count: 0
},
{
...buttons.chat,
count: 2500,
precise: false
count: 0
},
{
...buttons.donate,
count: 0,
precise: true
...buttons.donate
},
{
...buttons.newsletter,
count: 0,
precise: true
...buttons.newsletter
}
]
},
Expand Down
63 changes: 58 additions & 5 deletions src/modules/homepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { STATS_API_URL, handleRemoteError } from './index';
import HOMEPAGE_CONTENT from '../content/homepage';

export const GET_GITHUB_CONTENT = 'homepage/GET_GITHUB_CONTENT';
export const GET_SLACK_CONTENT = 'homepage/GET_SLACK_CONTENT';

const initialState = {
githubContentLoaded: false,
slackContentLoaded: false,
github: {
repositories: [],
members: []
Expand Down Expand Up @@ -40,20 +42,42 @@ export default (state = initialState, action) => {
}
};

case GET_SLACK_CONTENT:
return {
...state,
slackContentLoaded: true,
content: {
...state.content,
movement: {
...state.content.movement,
ctas: state.content.movement.ctas.map(cta => {
if (cta.type === 'Slack') {
return {
...cta,
count: action.slack.count
};
}

return cta;
})
}
}
};

default:
return state;
}
};

const fetchGithub = () => dispatch =>
new Promise((resolve, reject) => {
fetch(STATS_API_URL)
fetch(STATS_API_URL + '/github')
.then(response => response.json())
.then(({ error, repositories, members }) => {
if (error) {
dispatch(handleRemoteError(error));
.then(({ errorMessage, repositories, members }) => {
if (errorMessage) {
dispatch(handleRemoteError(errorMessage));

reject(new Error(error));
reject(new Error(errorMessage));
} else {
const shuffle = a => {
for (let i = a.length - 1; i > 0; i--) {
Expand Down Expand Up @@ -85,3 +109,32 @@ export const getGithubData = () => {
await dispatch(fetchGithub());
};
};

const fetchSlack = () => dispatch =>
new Promise((resolve, reject) => {
fetch(STATS_API_URL + '/slack')
.then(response => response.json())
.then(({ errorMessage, metadata }) => {
if (errorMessage) {
dispatch(handleRemoteError(errorMessage));

reject(new Error(errorMessage));
} else {
dispatch({
type: GET_SLACK_CONTENT,
slack: metadata
});

resolve({
slack: metadata
});
}
})
.catch(error => dispatch(handleRemoteError(error)));
});

export const getSlackData = () => {
return async dispatch => {
await dispatch(fetchSlack());
};
};
4 changes: 2 additions & 2 deletions src/modules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export const WORDPRESS_API_URL = WORDPRESS_URL + '/wp-json';

export const STATS_API_URL =
process.env.NODE_ENV === 'development'
? 'http://localhost:3002/github'
: 'https://stats.openmined.org/github';
? 'http://localhost:3002'
: 'https://stats.openmined.org';

export const handleRemoteError = error =>
addNotification({
Expand Down

0 comments on commit 76bf46f

Please sign in to comment.