Skip to content

Commit

Permalink
Confetti (dexlab-io#78)
Browse files Browse the repository at this point in the history
A confetti animation shows whenever a tip is received.
  • Loading branch information
Emilio Silva Schlenker committed Mar 11, 2019
1 parent d893123 commit ac3a08b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"react": "^16.7.0",
"react-apollo": "^2.4.1",
"react-clipboard.js": "^2.0.2",
"react-confetti": "^2.6.0",
"react-dom": "^16.7.0",
"react-helmet": "^5.2.0",
"react-i18next": "^9.0.10",
Expand Down
24 changes: 23 additions & 1 deletion src/pages/Dashboard/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { Component } from 'react';
import React, { Component, Fragment } from 'react';
import { withRouter, matchPath } from 'react-router-dom';
import Confetti from 'react-confetti';

import { checkWindowSize } from '../../utils/helpers';
import { store } from '../../store';
Expand All @@ -22,6 +23,8 @@ class Dashboard extends Component {
setupModalOpen: false,
pos: { address: null },
tipHashes: [],
confettiRun: false,
confettiRec: false,
};
}

Expand Down Expand Up @@ -64,10 +67,21 @@ class Dashboard extends Component {
}, 5000);
};

confetti = () => {
this.setState({
confettiRun: true,
confettiRec: true,
});
window.setTimeout(() => {
this.setState({ confettiRec: false });
}, 5000);
}

onTipReceived = (txHash) => {
const { tipHashes } = this.state;
tipHashes.push(txHash);
this.setState({ tipHashes });
this.confetti();
}

handleNavItemChange = activeTab => {
Expand All @@ -91,6 +105,7 @@ class Dashboard extends Component {
const { isMobile, totalAmount, paymentModalOpen, activeTab } = this.state;

return (
<Fragment>
<Layout
header={{ onNavItemClick: this.handleNavItemChange }}
activeNavItem={activeTab}
Expand All @@ -108,6 +123,13 @@ class Dashboard extends Component {
/>
) : null}
</Layout>
<Confetti
style={ { zIndex: -1 } }
run={this.state.confettiRun}
recycle={this.state.confettiRec}
numberOfPieces={600}
/>
</Fragment>
);
}
}
Expand Down

0 comments on commit ac3a08b

Please sign in to comment.