Hello Hive Community Members ๐,
The Distriator app is getting a ReactJS glow-up โจ โ and if things go right, we might finally say goodbye to that bloated Flutter build ๐ชฆ.
As always, everything is open source (because sharing is caring โค๏ธ), so if you missed the earlier drama, hereโs your binge-worthy recap ๐บ๐.
๐ Epic Learning Journey Recap
Missed a day? Hereโs the trail of my glorious ReactJS misadventures:
- ๐ Day 1 โ Fresh React app + AIOHA integration!
- ๐งญ Day 2 โ Routing drama & rebellious NavBar
- ๐ ๏ธ Day 3 โ Fixed layouts, Routing & AIOHA
- ๐ง Day 4 โ useState, useEffect & .env headaches ๐
- ๐งน Day 5 โ Path aliases to clean up path spaghetti ๐
- ๐ก Day 6 โ Create Context Provider & call API
- ๐ Day 7 โ Show a toast message
- ๐ Day 8 โ Login magic with LocalStorage
- ๐ Day 9 โ Toasts, laughs & custom tricks
- ๐ Day 10 โ Handle user account switch + fresh JWT Token
- ๐ Day 11 โ Integrating API for cashback details
๐ต Day 12: Designing the Cashback ClaimBox
This time, weโre showing users a beautiful, irresistible โClaim Cashbackโ card ๐ whenever their cashback is ready to be grabbed.
๐ญ Thought Process
Originally: โLetโs just put a box in the center with a button.โ
Brain: โ โNope, donโt reinvent the wheel.โ
Solution: Scroll through DaisyUI like itโs Pinterest, and pick something gorgeous.
๐ The Card That Stole My Heart
After scrolling... BAM ๐ โ this card component caught my eye.
JSX? Barely 10 lines ๐คฏ. Copy. Paste. Letโs roll.
๐ฆ ClaimBox Component
- Created
ClaimBox.tsx
- Grabbed API attributes:
- Transaction timestamp ๐
- Business name ๐ช
- Claimable cashback amount ๐ต
- Transaction amount ๐ณ
โณ Timer Logic
Cashback = claimable for 2 hours after transaction.
We:
- Grab timestamp
- Add 2 hrs
- Show countdown (HH:MM:SS)
- Update every 1 sec โฑ๏ธ
function formatSecondsToHHMMSS(totalSeconds: number): string {
if (totalSeconds < 0) return '';
const hours = Math.floor(totalSeconds / 3600);
const minutes = Math.floor((totalSeconds % 3600) / 60);
const seconds = parseInt((totalSeconds % 60).toFixed(0));
const pad = (num: number) => String(num).padStart(2, "0");
return `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`;
}
๐ช Getting Business Info
Using the Business Provider to get:
- Profile Image ๐ท
- Display Name ๐ท๏ธ
In this post, we discussed about implementing business provider. From that provider, we'll access businesses. From list of businesses, we'll get business display name & business profile image.
Step 1. Import business provider
import { useBusinesses } from "@/context/BusinessesContext";
Step 2. Declare business provider variable
const { businesses } = useBusinesses();
Step 3. Get Business Profile Display Image
const getBusinessImage = (username: string) => {
const filteredItems = businesses.filter(
(b) => b.distriator?.owner === username
);
if (filteredItems.length > 0) {
return (
filteredItems[0].profile?.displayImage ||
"https://img.daisyui.com/images/stock/photo-1606107557195-0e29a4b5b4aa.webp"
);
} else {
return "https://img.daisyui.com/images/stock/photo-1606107557195-0e29a4b5b4aa.webp";
}
};
Step 4. Get Business Profile Display Name
const getBusinessName = (username: string) => {
const filteredItems = businesses.filter(
(b) => b.distriator?.owner === username
);
if (filteredItems.length > 0) {
return filteredItems[0].profile?.displayName || "Business Name";
} else {
return "Business Name";
}
};
๐จ Final ClaimBox UI
return (
<div className="card bg-base-100 w-96 shadow-sm">
<figure>
<img
src={getBusinessImage(claim.business)}
alt={`${getBusinessName(claim.business)}`} />
</figure>
<div className="card-body">
<h2 className="card-title">{claim.claimValue} Cashback</h2>
<p>
Your recent spent of {claim.amount}, at {getBusinessName(claim.business)}, is eligible for claiming a cashback
</p>
<div className="card-actions justify-end items-center">
<span className="text-lg font-bold text-red-600 animate-blink">
Time Left {timeText}
</span>
<button className="btn btn-primary">Claim Now!</button>
</div>
</div>
</div>
);
๐ Centering the Magic
Show loader if loading, โNo claim availableโ if empty, else ClaimBox ๐.
๐ฅ Drumroll... Tada!
npm run dev
โ Profit.
Looks wonderful, right? ๐
๐ Open Source Goodness
- Github Repository Link: https://github.com/sag333ar/react-distriator
- Review Last commit changes: https://github.com/sag333ar/react-distriator/commit/33d842e2f0cb697d8b4d61c44c7c8a1d98be9a2e
- Snapshot: https://github.com/sag333ar/react-distriator/tree/33d842e2f0cb697d8b4d61c44c7c8a1d98be9a2e
๐ค Why Flutter? Why Me?
After this, I questioned my life choicesโฆ Flutter? Native apps? When ReactJS makes it this simple? ๐
But hey, lesson learned โ and we now have ClaimBox integrated ๐ฏ.
๐ Power to Hive
- ๐ Hive to the moon (and beyond!)
- โค๏ธ Power to Hive community
- ๐ช Power to Hive blockchain
Thanks for reading! Drop your feedback & see you in the next one โ๏ธ.
๐ Final Note
- I asked ChatGPT/AI to help optimize this post to make it more readable and viewer-friendly.
- Here is the link where you can find both original content & improvements made by AI
- https://chatgpt.com/share/689a853f-e634-8000-8a8a-7a1929030940
๐ My Contributions to โฆ๏ธ Hive Ecosystem
Contribution | To | Hive | Ecosystem |
---|---|---|---|
Hive Witness Node | Hive API Node (in progress) | 3Speak Video Encoder Node Operator (highest number of nodes) | 3Speak Mobile App Developer |
3Speak Podcast App Developer | 3Speak Shorts App Developer | 3Speak Support & Maintenance Team | Distriator Developer |
CheckinWithXYZ | Hive Inbox | HiFind | Hive Donate App |
Contributed to HiveAuth Mobile App | Ecency โ 3Speak Integration | Ecency โ InLeo Integration | Ecency โ Actifit Integration |
Hive Stats App | Vote for Witness App | HiveFlutterKit | New 3Speak App |
๐ Support Back
โค๏ธ Appreciate my work? Consider supporting @threespeak & @sagarkothari88! โค๏ธ
Vote | For | Witness |
---|---|---|
sagarkothari88 | @sagarkothari88 | |
threespeak | @threespeak |
This post has been manually curated by @steemflow from Indiaunited community. Join us on our Discord Server.
Do you know that you can earn a passive income by delegating to @indiaunited. We share more than 100 % of the curation rewards with the delegators in the form of IUC tokens. HP delegators and IUC token holders also get upto 20% additional vote weight.
Here are some handy links for delegations: 100HP, 250HP, 500HP, 1000HP.
100% of the rewards from this comment goes to the curator for their manual curation efforts. Please encourage the curator @steemflow by upvoting this comment and support the community by voting the posts made by @indiaunited..
This post received an extra 7.51% vote for delegating HP / holding IUC tokens.