Skip to content

Commit

Permalink
Merge pull request #82 from cryingtoilet/main
Browse files Browse the repository at this point in the history
Changed coupon's expirationDate to score and changed it from a percentage to a score
  • Loading branch information
Abdallah-Alwarawreh authored Jan 8, 2025
2 parents 02aebb5 + fa375fb commit a03207e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
22 changes: 11 additions & 11 deletions Extension-React/src/components/CouponCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ export interface Coupon {
title: string;
description: string;
copied?: boolean;
expirationDate: number;
score: number;
}

const colorRanges = [
{ min: 70, color: "text-green-500" },
{ min: 55, color: "text-lime-500" },
{ min: 40, color: "text-yellow-500" },
{ min: 25, color: "text-orange-500" },
{ min: 0.7, color: "text-green-500" },
{ min: 0.55, color: "text-lime-500" },
{ min: 0.4, color: "text-yellow-500" },
{ min: 0.25, color: "text-orange-500" },
{ min: 0, color: "text-red-500" }
] as const;

const getPercentageColor = (percentage: number): string => {
return colorRanges.find(range => percentage >= range.min)?.color || "text-red-500";
const getColor = (score: number): string => {
return colorRanges.find(range => score >= range.min)?.color || "text-red-500";
};

function round(value: number, precision: number) {
Expand All @@ -33,16 +33,16 @@ const CouponCard: React.FC<{
copied: boolean;
}> = ({ coupon, onCopy, copied }) => {
const { t } = useTranslation();
const percentage = Math.round(coupon.expirationDate * 100);
let score = Math.round(coupon.score);

return (
<Card className="p-4 pt-2 pb-2 flex justify-between items-center bg-card text-card-foreground">
<div>
<p className="text-sm font-bold text-primary">{coupon.code}</p>
<p className="text-sm text-muted-foreground">{coupon.title}</p>
{coupon.expirationDate && (
<p className={`text-sm ${getPercentageColor(percentage)}`}>
{t(round(percentage, 1) + "% chance to work")}
{coupon.score && (
<p className={`text-sm ${getColor(score)}`}>
{'Score: ' + (round(score, 2))}
</p>
)}
</div>
Expand Down
2 changes: 1 addition & 1 deletion Extension-React/src/components/CouponsEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface Coupon {
title: string;
description: string;
copied?: boolean;
expirationDate: number;
score: number;
}

const CouponsEntry: React.FC<CouponData> = ({pageIcon, pageDomain, couponsDomain, handleCopy, isSubDomain}) => {
Expand Down
2 changes: 1 addition & 1 deletion Extension-React/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const fetchCoupons = async (
code: coupon.code,
title: coupon.title,
description: coupon.description,
expirationDate: coupon.score
score: coupon.score
})
);

Expand Down

0 comments on commit a03207e

Please sign in to comment.