Skip to content

Commit

Permalink
Fix confetti not displaying on milestone completion (#1995)
Browse files Browse the repository at this point in the history
* add confetti state

* fix confetti bug
  • Loading branch information
djnunez-aot authored Mar 18, 2024
1 parent 58b1155 commit 759aa0d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
12 changes: 9 additions & 3 deletions epictrack-web/src/components/confetti/Confetti.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Confetti = ({ displayType = "confetti" }: ConfettiProps) => {
const animationEnd = Date.now() + duration;
const defaults = {
startVelocity: 30,
spread: displayType === "fireworks" ? 120 : 360, // narrower spread for fireworks
spread: displayType === "fireworks" ? 180 : 360, // wider spread
ticks: 60,
zIndex: 0,
};
Expand All @@ -27,10 +27,17 @@ const Confetti = ({ displayType = "confetti" }: ConfettiProps) => {
}

const particleCount = 50 * (timeLeft / duration);
// First point of explosion
confetti({
...defaults,
particleCount,
origin: { x: 0.5, y: 0.5 }, // center of the screen
origin: { x: 0.3, y: 0.5 }, // left of the screen
});
// Second point of explosion
confetti({
...defaults,
particleCount,
origin: { x: 0.7, y: 0.5 }, // right of the screen
});

timeout = setTimeout(animateConfetti, 250);
Expand All @@ -47,5 +54,4 @@ const Confetti = ({ displayType = "confetti" }: ConfettiProps) => {

return null;
};

export default Confetti;
21 changes: 10 additions & 11 deletions epictrack-web/src/components/workPlan/event/EventList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import {
} from "../../../constants/application-constant";
import { Restricted } from "components/shared/restricted";
import { IButton } from "components/shared";
import Confetti from "components/confetti/Confetti";
import { showConfetti } from "styles/uiStateSlice";

const ImportFileIcon: React.FC<IconProps> = Icons["ImportFileIcon"];
Expand Down Expand Up @@ -78,7 +77,7 @@ const EventList = () => {
() => ctx.team.some((member) => member.staff.email === email),
[ctx.team, email]
);

const isConfettiShown = useAppSelector((state) => state.uiState.showConfetti);
const { handleHighlightRows } = useContext(EventContext);
const [rowSelection, setRowSelection] = React.useState<MRT_RowSelectionState>(
{}
Expand Down Expand Up @@ -116,6 +115,11 @@ const EventList = () => {
}, [milestoneEvent]);

React.useEffect(() => setEvents([]), [ctx.selectedWorkPhase?.work_phase.id]);
React.useEffect(() => {
setTimeout(() => {
dispatch(showConfetti(false));
}, 5000);
}, [isConfettiShown]);
React.useEffect(() => {
getCombinedEvents();
}, [ctx.work?.id, ctx.selectedWorkPhase?.work_phase.id]);
Expand Down Expand Up @@ -319,24 +323,19 @@ const EventList = () => {
setShowMilestoneForm(false);
getCombinedEvents();
getWorkPhases();
setTaskEvent(undefined);
setMilestoneEvent(undefined);
getTemplateUploadStatus()
.then(() => {
return getWorkById();
})
.then(() => {
if (
milestoneEvent &&
milestoneEvent.event_configuration.event_position ===
EventPosition.END &&
milestoneEvent.actual_date
milestoneEvent?.event_configuration.event_position ===
EventPosition.END
) {
dispatch(showConfetti(true));
setTimeout(() => {
dispatch(showConfetti(false));
}, 5000);
}
setTaskEvent(undefined);
setMilestoneEvent(undefined);
});
};

Expand Down

0 comments on commit 759aa0d

Please sign in to comment.