Skip to content
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

Implement Dynamic Labels & Repository Languages in the Contribute Page #1126

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
157 changes: 77 additions & 80 deletions frontend/src/components/Card.tsx
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used to have these labels before, so thanks for adding those back.

One of the features they had is that they were clickable with the label/topic being added to a search field and fetching filtered records.
Do you think you could add that too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Hey @kasya, that's a great idea! Thanks for suggesting it. Since implementing this would require some modifications to the backend, I think it would be best to address it in a new issue. I'm currently working on the backend and will make sure to include this feature in future updates

Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ import { desktopViewMinWidth } from 'utils/constants'
import { Icons } from 'utils/data'
import { TooltipRecipe } from 'utils/theme'
import { getSocialIcon } from 'utils/urlIconMappings'
import { cn } from 'utils/utility'
import FontAwesomeIconWrapper from 'wrappers/FontAwesomeIconWrapper'
import ActionButton from 'components/ActionButton'
import ContributorAvatar from 'components/ContributorAvatar'
import DisplayIcon from 'components/DisplayIcon'
import Markdown from 'components/MarkdownWrapper'
import { Tooltip } from 'components/ui/tooltip'

// Initial check for mobile screen size
const isMobileInitial = typeof window !== 'undefined' && window.innerWidth < desktopViewMinWidth

const Card = ({
Expand All @@ -29,24 +27,25 @@ const Card = ({
projectLink,
social,
tooltipLabel,
labels,
repository_languages,
}: CardProps) => {
const [isMobile, setIsMobile] = useState(isMobileInitial)

// Resize listener to adjust display based on screen width
useEffect(() => {
const checkMobile = () => {
const mobile = window.innerWidth < desktopViewMinWidth
setIsMobile(mobile)
}
const checkMobile = () => setIsMobile(window.innerWidth < desktopViewMinWidth)
window.addEventListener('resize', checkMobile)
return () => window.removeEventListener('resize', checkMobile)
}, [])

return (
<div className="mx-auto mb-2 mt-4 flex w-full max-w-[95%] flex-col items-start rounded-md border border-border bg-white px-4 pb-4 pl-4 dark:bg-[#212529] md:max-w-6xl">
<div
className={`mx-auto mb-2 mt-4 flex w-full max-w-[95%] flex-col items-start rounded-md border border-border bg-white dark:bg-[#212529] md:max-w-6xl ${
isMobile ? 'px-2 pb-2' : 'px-4 pb-4'
}`}
>
<div className="mt-2 flex w-full flex-col items-start gap-4 pt-2 sm:flex-col sm:gap-4 md:pt-0">
<div className="flex items-center gap-3">
{/* Display project level badge (if available) */}
<div className="flex w-full flex-wrap items-center gap-3">
{level && (
<Tooltip
closeDelay={100}
Expand All @@ -58,9 +57,7 @@ const Card = ({
showArrow
>
<span
className={cn(
'flex h-8 w-8 items-center justify-center rounded-full text-xs shadow'
)}
className="flex h-8 w-8 items-center justify-center rounded-full text-xs shadow"
style={{ backgroundColor: level.color }}
>
<FontAwesomeIconWrapper icon={level.icon} className="text-white" />
Expand All @@ -71,16 +68,14 @@ const Card = ({
<Link href={url} target="_blank" rel="noopener noreferrer" className="flex-1">
<h1
className="max-w-full break-words text-base font-semibold text-blue-400 sm:break-normal sm:text-lg lg:text-2xl"
style={{
transition: 'color 0.3s ease',
}}
style={{ transition: 'color 0.3s ease' }}
>
{title}
</h1>
</Link>
</div>
{/* Icons associated with the project */}
{icons && Object.keys(Icons).some((key) => icons[key]) ? (

{icons && Object.keys(Icons).some((key) => icons[key]) && (
<div className="-ml-1.5 flex flex-grow">
{Object.keys(Icons).map((key, index) =>
icons[key] ? (
Expand All @@ -92,24 +87,52 @@ const Card = ({
) : null
)}
</div>
) : null}
)}
</div>
{/* Link to project name if provided */}

{projectName && (
<Link href={projectLink} rel="noopener noreferrer" className="mt-2 font-medium">
<Link
href={projectLink}
rel="noopener noreferrer"
className="mt-2 font-medium text-sky-600 dark:text-sky-400"
>
{projectName}
</Link>
)}
{/* Render project summary using Markdown */}

<Markdown content={summary} className="py-2 pr-4 text-gray-600 dark:text-gray-300" />
<div
className={
social && social.length > 0
? 'flex w-full flex-col gap-2 pr-4'
: 'flex w-full items-center justify-between'
}
>
{/* Render top contributors as avatars */}

{repository_languages && repository_languages.length > 0 && (
<div className="mt-1 flex flex-wrap gap-1 pr-4">
{repository_languages.map((lang, index) => (
<span
key={`lang-${index}`}
className="rounded-md bg-gray-100 px-3 py-1 text-sm font-medium text-gray-700 dark:bg-gray-700 dark:text-gray-300"
>
{lang}
</span>
))}
</div>
)}

{labels?.length > 0 && (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Labels background changes on smaller screens πŸ€”
Dark theme:
Screenshot 2025-03-30 at 7 22 11β€―PM
Screenshot 2025-03-30 at 7 22 20β€―PM
Light theme:
Screenshot 2025-03-30 at 7 23 13β€―PM
Screenshot 2025-03-30 at 7 23 20β€―PM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kasya sorry for the delay will fix this issue soon!!

<div className="mt-2 flex flex-wrap gap-2 pr-4">
{labels.map((label, index) => (
<span
key={`label-${index}`}
className={`rounded-md px-3 py-1 text-sm font-medium ${
isMobile
? 'bg-sky-200 text-sky-900'
: 'bg-sky-100 text-sky-800 dark:bg-sky-900 dark:text-sky-300'
}`}
>
{label}
</span>
))}
</div>
)}

<div className="flex w-full flex-wrap items-center justify-between gap-6">
<div className="mt-3 flex w-full flex-wrap items-center gap-2">
{topContributors?.map((contributor, index) => (
<ContributorAvatar
Expand All @@ -119,56 +142,30 @@ const Card = ({
/>
))}
</div>
{!social || social.length === 0 ? (
<div
className={cn(
'mt-3 flex items-center pr-4',
isMobile && 'mt-4 w-full justify-end pr-4'
)}
>
<ActionButton tooltipLabel={tooltipLabel} url={button.url} onClick={button.onclick}>
{button.icon}
{button.label}
</ActionButton>
</div>
) : (
<div
className={cn(
'flex w-full flex-wrap items-center justify-between gap-6',
isMobile && 'items-start'
)}
>
<div
className={cn('flex w-full items-center justify-between', isMobile && 'flex-wrap')}
>
{/* Render social links if available */}
{social && social.length > 0 && (
<HStack id="social" mt={2}>
{social.map((item) => (
<Link
key={`${item.title}-${item.url}`}
href={item.url}
target="_blank"
rel="noopener noreferrer"
display="flex"
alignItems="center"
gap={2}
>
<FontAwesomeIcon icon={getSocialIcon(item.url)} className="h-5 w-5" />
</Link>
))}
</HStack>
)}
{/* Action Button */}
<div className="flex items-center">
<ActionButton tooltipLabel={tooltipLabel} url={button.url} onClick={button.onclick}>
{button.icon}
{button.label}
</ActionButton>
</div>
</div>
</div>
)}

<div className="flex w-full items-center justify-between">
{social && social.length > 0 && (
<HStack id="social" mt={2}>
{social.map((item) => (
<Link
key={`${item.title}-${item.url}`}
href={item.url}
target="_blank"
rel="noopener noreferrer"
display="flex"
alignItems="center"
gap={2}
>
<FontAwesomeIcon icon={getSocialIcon(item.url)} className="h-5 w-5" />
</Link>
))}
</HStack>
)}
<ActionButton tooltipLabel={tooltipLabel} url={button.url} onClick={button.onclick}>
{button.icon}
{button.label}
</ActionButton>
</div>
</div>
</div>
)
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/pages/Contribute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ const ContributePage = () => {
url={issue.url}
projectName={issue.project_name}
projectLink={issue.project_url}
labels={issue.labels}
repository_languages={issue.repository_languages}
summary={issue.summary}
icons={filteredIcons}
button={SubmitButton}
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/types/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export interface CardProps {
button: ButtonType
icons?: IconType
isActive?: boolean
labels?: string[]
repository_languages?: string[]
level?: Level
projectLink?: string
projectName?: string
Expand Down