Skip to content

Commit 599cdb2

Browse files
authored
Merge pull request #172 from Stanley-Owoh/add-animated-progress-bar-on-pledge-78
Add animated progress bar on pledge 78
2 parents 212c04e + a6015ec commit 599cdb2

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

frontend/src/components/CampaignCard.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useState, useEffect, useRef } from "react";
12
import { Campaign } from "../types/campaign";
23
import { CopyButton } from "./CopyButton";
34
import { AddressAvatar } from "./AddressAvatar";
@@ -13,6 +14,16 @@ export function CampaignCard({
1314
selectedCampaignId,
1415
onSelect,
1516
}: CampaignCardProps) {
17+
const prevPercentRef = useRef<number | null>(null);
18+
const [animate, setAnimate] = useState(false);
19+
20+
useEffect(() => {
21+
if (prevPercentRef.current !== null && prevPercentRef.current !== campaign.progress.percentFunded) {
22+
setAnimate(true);
23+
}
24+
prevPercentRef.current = campaign.progress.percentFunded;
25+
}, [campaign.progress.percentFunded]);
26+
1627
const formatTimestamp = (unixSeconds: number) =>
1728
new Date(unixSeconds * 1000).toLocaleString();
1829

@@ -47,6 +58,7 @@ export function CampaignCard({
4758
</div>
4859
<div className="progress-bar" aria-hidden>
4960
<div
61+
className={animate ? "progress-bar-fill" : undefined}
5062
style={{
5163
width: `${Math.min(campaign.progress.percentFunded, 100)}%`,
5264
}}

frontend/src/index.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,10 @@ tbody tr:hover td {
12341234
background: linear-gradient(90deg, var(--primary), #22c55e);
12351235
}
12361236

1237+
.progress-bar-fill {
1238+
transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
1239+
}
1240+
12371241
.badge,
12381242
.chip,
12391243
.chip-emphasis {

pr-body.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## Summary
2+
3+
- Smoothly animates the campaign progress bar when funding percentage changes after a pledge
4+
- Uses 0.4s cubic-bezier transition for responsive feel
5+
- Animation only triggers on update, not on initial page load
6+
7+
## Changes
8+
9+
- **CampaignCard.tsx**: Added useRef to track previous percent and useState to conditionally apply animation class after initial render
10+
- **index.css**: Added `.progress-bar-fill` class with CSS transition on width
11+
12+
## Acceptance criteria
13+
14+
- Progress bar animates on funding percentage change
15+
- Animation duration is short enough to feel responsive
16+
- Animation does not trigger on initial page load

0 commit comments

Comments
 (0)