Skip to content

Commit

Permalink
Merge pull request #3 from allroundexperts/feature-expensiconx-confetti
Browse files Browse the repository at this point in the history
feat: added confetti
  • Loading branch information
allroundexperts authored Mar 14, 2023
2 parents da430aa + 7b87d6d commit 2107f70
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 0 deletions.
Binary file added assets/sounds/confetti_pop.mp3
Binary file not shown.
33 changes: 33 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"pusher-js": "^7.0.6",
"react": "18.1.0",
"react-collapse": "^5.1.0",
"react-confetti": "^6.1.0",
"react-content-loader": "^6.1.0",
"react-dom": "18.1.0",
"react-native": "npm:@expensify/react-native@0.70.4-alpha.2",
Expand Down
42 changes: 42 additions & 0 deletions src/components/Confetti/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react';
import PropTypes from 'prop-types';
import ReactConfetti from 'react-confetti';
import {Howl} from 'howler';
import confettiSound from '../../../assets/sounds/confetti_pop.mp3';

const propTypes = {
/** Triggers confetti */
trigger: PropTypes.bool,
};

const defaultProps = {
trigger: false,
};

const Confetti = (props) => {
const [toggle, setToggle] = React.useState(false);

React.useEffect(() => {
setToggle((prevToggle) => {
if (prevToggle) {
return true;
}
return props.trigger;
});
}, [props.trigger]);

React.useEffect(() => {
if (!toggle) {
return;
}
new Howl({src: confettiSound}).play();
}, [toggle]);

return toggle ? <ReactConfetti gravity={0.05} recycle={false} onConfettiComplete={() => setToggle(false)} /> : null;
};

Confetti.propTypes = propTypes;
Confetti.defaultProps = defaultProps;
Confetti.displayName = 'Confetti';

export default Confetti;
6 changes: 6 additions & 0 deletions src/components/Confetti/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

const Confetti = () => null;

Confetti.displayName = 'Confetti';

export default Confetti;
7 changes: 7 additions & 0 deletions src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import lodashGet from 'lodash/get';
import _ from 'underscore';
import {Freeze} from 'react-freeze';
import {PortalHost} from '@gorhom/portal';
import Confetti from '../../components/Confetti';
import styles from '../../styles/styles';
import ScreenWrapper from '../../components/ScreenWrapper';
import HeaderView from './HeaderView';
Expand Down Expand Up @@ -204,6 +205,11 @@ class ReportScreen extends React.Component {
// (which is shown, until all the actual views of the ReportScreen have been rendered)
const animatePlaceholder = !freeze;

const lastMessage = _.find(this.props.reportActions, action => action.sequenceNumber === lodashGet(this.props.report, 'maxSequenceNumber'));
const triggerConfetti = lodashGet(this.props.report, 'lastReadTime') < lodashGet(lastMessage, 'created')
&& lodashGet(this.props.report, 'lastMessageText').match(/^congrat(s|ulations?[.!]+)$/i)
&& lodashGet(this.props.report, 'lastActorEmail') !== this.props.session.email;

return (
<ScreenWrapper
style={screenWrapperStyle}
Expand Down Expand Up @@ -269,6 +275,7 @@ class ReportScreen extends React.Component {
>
{(this.isReportReadyForDisplay() && !isLoadingInitialReportActions) && (
<>
<Confetti trigger={triggerConfetti} />
<ReportActionsView
reportActions={this.props.reportActions}
report={this.props.report}
Expand Down

0 comments on commit 2107f70

Please sign in to comment.