Skip to content

Commit

Permalink
rewards label supported
Browse files Browse the repository at this point in the history
  • Loading branch information
ipapandinas committed Oct 14, 2024
1 parent e4cd69e commit 3b1bed3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
35 changes: 19 additions & 16 deletions app/projects/[slug]/_components/ProjectInfos.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Tooltip } from "@nextui-org/tooltip";
import { Chip } from "@nextui-org/chip";
import { KudosCertifiedIcon } from "@/assets/icons";
import Emoji from "@/components/emoji";
import { KUDOS_ISSUE_KEY } from "@/data/filters";
import { ProjectInfosLabel } from "@/types/project";
import { Chip } from "@nextui-org/chip";

interface IProjectInfosProps {
infos: { title: string; items: string[] }[];
Expand All @@ -13,21 +14,23 @@ const ProjectInfos = ({ infos, labels }: IProjectInfosProps) => (
<div className="bg-gradient-to-r md:bg-gradient-to-l from-background to-background-200 to-80% py-5 px-6 border-[1px] rounded-md flex flex-col gap-4 h-full">
{labels.length > 0 && (
<div className="flex flex-col sm:flex-row gap-3 border-b-small pb-4">
{labels.map(({ color, emoji, label, type }, idx) => (
<Chip key={idx} color={color} className="rounded-md">
<div className="flex items-center font-semibold gap-2 !leading-none py-0.5 text-base">
{emoji && (
<>
<Emoji emoji={emoji} className="text-xl" />
&nbsp;
</>
)}
{type === KUDOS_ISSUE_KEY ? (
<KudosCertifiedIcon className="w-5 h-5" size={16} />
) : null}
{label}
</div>
</Chip>
{labels.map(({ color, emoji, label, tooltip, type }, idx) => (
<Tooltip key={idx} content={tooltip}>
<Chip color={color} className="rounded-md">
<div className="flex items-center font-semibold gap-2 !leading-none py-0.5 text-base">
{emoji && (
<>
<Emoji emoji={emoji} className="text-xl" />
&nbsp;
</>
)}
{type === KUDOS_ISSUE_KEY ? (
<KudosCertifiedIcon className="w-5 h-5" size={16} />
) : null}
{label}
</div>
</Chip>
</Tooltip>
))}
</div>
)}
Expand Down
15 changes: 12 additions & 3 deletions app/projects/[slug]/_helpers/infos.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
import { REWARDS_KEY, KUDOS_ISSUE_KEY } from "@/data/filters";
import { ProjectInfosLabel, ProjectMetrics } from "@/types/project";
import {
ProjectInfos,
ProjectInfosLabel,
ProjectMetrics,
} from "@/types/project";

export function constructLabels(metrics: ProjectMetrics): ProjectInfosLabel[] {
export function constructLabels(
infos: ProjectInfos,
metrics: ProjectMetrics,
): ProjectInfosLabel[] {
const { certifiedTotal, rewardsTotal } = metrics;

return [
rewardsTotal > 0 && {
infos.attributes.rewards && {
color: "success",
emoji: "💰",
label: "Rewards",
type: REWARDS_KEY,
tooltip: "This project is willing to distributed rewards (e.g. tipping)",
},
certifiedTotal > 0 && {
color: "default",
label: "Kudos Pick",
type: KUDOS_ISSUE_KEY,
tooltip: "This project participates to the Kudos Carnival",
},
].filter((label): label is ProjectInfosLabel => Boolean(label)); // Type-safe filtering
}
2 changes: 1 addition & 1 deletion app/projects/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default async function SingleProjectPage({ params }: IProps) {
const issues = await fetchProjectIssues(slug, query);
const metrics = await constructProjectMetrics(infos, issues);

const labels = constructLabels(metrics);
const labels = constructLabels(infos, metrics);
const repositoryIds = getUniqueRepositoryIds(issues);
const checkboxFilters = buildCheckboxFilters(metrics);

Expand Down
2 changes: 2 additions & 0 deletions types/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type ProjectInfos = {
stackLevels: ProjectStackLevel[];
technologies: ProjectTechnologies[];
types: ProjectType[];
rewards: boolean;
};
};

Expand All @@ -51,6 +52,7 @@ export type ProjectInfosLabel = {
color: "default" | "success" | "danger";
emoji?: string;
label: string;
tooltip: string;
type: string;
};

Expand Down

0 comments on commit 3b1bed3

Please sign in to comment.