|
| 1 | +import { GetContributionsResponse } from "@dzcode.io/api/dist/contribution/types"; |
| 2 | +import React from "react"; |
| 3 | +import { Link } from "src/components/link"; |
| 4 | +import { useLocale } from "src/components/locale"; |
| 5 | +import { Markdown } from "src/components/markdown"; |
| 6 | +import { getElapsedTime } from "src/utils/elapsed-time"; |
| 7 | + |
| 8 | +export function ContributionCard({ |
| 9 | + contribution, |
| 10 | + compact = false, |
| 11 | +}: { |
| 12 | + contribution: GetContributionsResponse["contributions"][number]; |
| 13 | + compact?: boolean; |
| 14 | +}) { |
| 15 | + const { localize } = useLocale(); |
| 16 | + |
| 17 | + return ( |
| 18 | + <div dir="ltr" className="card card-compact bg-base-300 flex-auto w-full max-w-xs sm:max-w-sm"> |
| 19 | + <div className="card-body markdown"> |
| 20 | + <div className="card-body"> |
| 21 | + <h2 className="card-title"> |
| 22 | + <Markdown content={contribution.title} /> |
| 23 | + </h2> |
| 24 | + <span className="flex-1" /> |
| 25 | + {!compact && ( |
| 26 | + <> |
| 27 | + <span className="card-normal">{contribution.repository.project.name}</span> |
| 28 | + <span className="card-normal"> |
| 29 | + {contribution.repository.owner}/{contribution.repository.name} |
| 30 | + </span> |
| 31 | + </> |
| 32 | + )} |
| 33 | + <div className="card-actions justify-end mt-4 gap-4"> |
| 34 | + {!compact && ( |
| 35 | + <img className="w-6 h-6 rounded-full" src={contribution.contributor.avatarUrl} /> |
| 36 | + )} |
| 37 | + <div className="flex-1" /> |
| 38 | + {contribution.activityCount > 0 && ( |
| 39 | + <div className="flex flex-row"> |
| 40 | + <svg |
| 41 | + xmlns="http://www.w3.org/2000/svg" |
| 42 | + fill="none" |
| 43 | + viewBox="0 0 24 24" |
| 44 | + strokeWidth={1.5} |
| 45 | + stroke="currentColor" |
| 46 | + className="size-6" |
| 47 | + > |
| 48 | + <path |
| 49 | + strokeLinecap="round" |
| 50 | + strokeLinejoin="round" |
| 51 | + d="M20.25 8.511c.884.284 1.5 1.128 1.5 2.097v4.286c0 1.136-.847 2.1-1.98 2.193-.34.027-.68.052-1.02.072v3.091l-3-3c-1.354 0-2.694-.055-4.02-.163a2.115 2.115 0 0 1-.825-.242m9.345-8.334a2.126 2.126 0 0 0-.476-.095 48.64 48.64 0 0 0-8.048 0c-1.131.094-1.976 1.057-1.976 2.192v4.286c0 .837.46 1.58 1.155 1.951m9.345-8.334V6.637c0-1.621-1.152-3.026-2.76-3.235A48.455 48.455 0 0 0 11.25 3c-2.115 0-4.198.137-6.24.402-1.608.209-2.76 1.614-2.76 3.235v6.226c0 1.621 1.152 3.026 2.76 3.235.577.075 1.157.14 1.74.194V21l4.155-4.155" |
| 52 | + /> |
| 53 | + </svg> |
| 54 | + <span className="">{contribution.activityCount}</span> |
| 55 | + </div> |
| 56 | + )} |
| 57 | + {!compact && ( |
| 58 | + <div className="flex flex-row"> |
| 59 | + {getElapsedTime(contribution.updatedAt, localize("elapsed-time-suffixes"))} |
| 60 | + </div> |
| 61 | + )} |
| 62 | + <Link href={contribution.url} className="link"> |
| 63 | + {contribution.type === "ISSUE" |
| 64 | + ? localize("contribute-read-issue") |
| 65 | + : localize("contribute-review-changes")} |
| 66 | + </Link> |
| 67 | + </div> |
| 68 | + </div> |
| 69 | + </div> |
| 70 | + </div> |
| 71 | + ); |
| 72 | +} |
0 commit comments