-
Notifications
You must be signed in to change notification settings - Fork 9
feat: automatically sort sponsors based on tier priority #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ import React from "react"; | |||||||||||||||||
| import type { supportUsButtonProps } from "../types/index"; | ||||||||||||||||||
| import type { Theme } from "../types/index"; | ||||||||||||||||||
| import type { ButtonVariant } from "../types/index"; | ||||||||||||||||||
| import type { Tier } from "../types/index"; | ||||||||||||||||||
|
|
||||||||||||||||||
| // Function to get the appropriate classes based on the selected theme, used for styling different sections of the component according to the chosen theme | ||||||||||||||||||
| function classAccordingToTheme(Theme: Theme): string { | ||||||||||||||||||
|
|
@@ -70,6 +71,18 @@ function SupportUsButton({ | |||||||||||||||||
| }, | ||||||||||||||||||
| buttonVariant = "AOSSIE", | ||||||||||||||||||
| }: supportUsButtonProps): React.JSX.Element { | ||||||||||||||||||
| const sortedSponsors = sponsors ? [...sponsors].sort((a, b) => { | ||||||||||||||||||
| const tierPriority: Record<Tier, number> = { | ||||||||||||||||||
| Platinum: 1, | ||||||||||||||||||
| Gold: 2, | ||||||||||||||||||
| Silver: 3, | ||||||||||||||||||
| Bronze: 4, | ||||||||||||||||||
| }; | ||||||||||||||||||
| const aTier = a.sponsorshipTier || 'Bronze'; | ||||||||||||||||||
| const bTier = b.sponsorshipTier || 'Bronze'; | ||||||||||||||||||
| return tierPriority[aTier] - tierPriority[bTier]; | ||||||||||||||||||
| }) : []; | ||||||||||||||||||
|
|
||||||||||||||||||
| return ( | ||||||||||||||||||
| // Container for the support us button, with dynamic classes based on the selected theme and custom class names | ||||||||||||||||||
| <div | ||||||||||||||||||
|
|
@@ -240,7 +253,7 @@ function SupportUsButton({ | |||||||||||||||||
| ${Theme === "minimal" && "bg-gray-800/50"} | ||||||||||||||||||
| ${Theme === "corporate" && "bg-blue-600/50"}`} | ||||||||||||||||||
| > | ||||||||||||||||||
| {sponsors && sponsors.length > 0 && ( | ||||||||||||||||||
| {sortedSponsors && sortedSponsors.length > 0 && ( | ||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Simplify redundant truthy check. Since ♻️ Proposed simplification- {sortedSponsors && sortedSponsors.length > 0 && (
+ {sortedSponsors.length > 0 && (📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| // List of sponsors with their logos and links, styled according to the selected theme and custom class names | ||||||||||||||||||
| <div | ||||||||||||||||||
| className={`${classNames.sponsors} ${classAccordingToTheme(Theme)} | ||||||||||||||||||
|
|
@@ -275,7 +288,7 @@ function SupportUsButton({ | |||||||||||||||||
|
|
||||||||||||||||||
| {/* Sponsor logos */} | ||||||||||||||||||
| <div className="flex flex-row flex-wrap justify-center items-center gap-10 z-10"> | ||||||||||||||||||
| {sponsors.map((sponsor, index) => ( | ||||||||||||||||||
| {sortedSponsors.map((sponsor, index) => ( | ||||||||||||||||||
| <a | ||||||||||||||||||
| href={sponsor.link} | ||||||||||||||||||
| key={index} | ||||||||||||||||||
|
Comment on lines
+291
to
294
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Consider using a stable unique key instead of array index. Using ♻️ Proposed fix using sponsor name as key- {sortedSponsors.map((sponsor, index) => (
+ {sortedSponsors.map((sponsor) => (
<a
href={sponsor.link}
- key={index}
+ key={`${sponsor.name}-${sponsor.link ?? ''}`}
target="_blank"📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
|
|
||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.