Skip to content

Commit b7f1b0e

Browse files
committed
feat: automatically sort sponsors based on tier priority
1 parent 6f9f9a2 commit b7f1b0e

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/components/SupportUsButton.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from "react";
22
import type { supportUsButtonProps } from "../types/index";
33
import type { Theme } from "../types/index";
44
import type { ButtonVariant } from "../types/index";
5+
import type { Tier } from "../types/index";
56

67
// Function to get the appropriate classes based on the selected theme, used for styling different sections of the component according to the chosen theme
78
function classAccordingToTheme(Theme: Theme): string {
@@ -70,6 +71,18 @@ function SupportUsButton({
7071
},
7172
buttonVariant = "AOSSIE",
7273
}: supportUsButtonProps): React.JSX.Element {
74+
const sortedSponsors = sponsors ? [...sponsors].sort((a, b) => {
75+
const tierPriority: Record<Tier, number> = {
76+
Platinum: 1,
77+
Gold: 2,
78+
Silver: 3,
79+
Bronze: 4,
80+
};
81+
const aTier = a.sponsorshipTier || 'Bronze';
82+
const bTier = b.sponsorshipTier || 'Bronze';
83+
return tierPriority[aTier] - tierPriority[bTier];
84+
}) : [];
85+
7386
return (
7487
// Container for the support us button, with dynamic classes based on the selected theme and custom class names
7588
<div
@@ -240,7 +253,7 @@ function SupportUsButton({
240253
${Theme === "minimal" && "bg-gray-800/50"}
241254
${Theme === "corporate" && "bg-blue-600/50"}`}
242255
>
243-
{sponsors && sponsors.length > 0 && (
256+
{sortedSponsors && sortedSponsors.length > 0 && (
244257
// List of sponsors with their logos and links, styled according to the selected theme and custom class names
245258
<div
246259
className={`${classNames.sponsors} ${classAccordingToTheme(Theme)}
@@ -275,7 +288,7 @@ function SupportUsButton({
275288

276289
{/* Sponsor logos */}
277290
<div className="flex flex-row flex-wrap justify-center items-center gap-10 z-10">
278-
{sponsors.map((sponsor, index) => (
291+
{sortedSponsors.map((sponsor, index) => (
279292
<a
280293
href={sponsor.link}
281294
key={index}

0 commit comments

Comments
 (0)