Skip to content

Commit

Permalink
feat: add link to jc badge
Browse files Browse the repository at this point in the history
  • Loading branch information
tomquirk committed Nov 19, 2023
1 parent bc10070 commit 1977e70
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
27 changes: 26 additions & 1 deletion src/components/DomainBadge.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import { readNetwork } from 'constants/networks'
import { NetworkName } from 'models/networkName'
import Image from 'next/image'
import Link from 'next/link'
import { useMemo } from 'react'
import { twMerge } from 'tailwind-merge'
import { Badge } from './Badge'

export type DomainBadgeProps = {
className?: string
domain: string | undefined
projectId?: number
}

function getJuicecrowdUrl(projectId: number) {
const prefix = readNetwork.name === NetworkName.goerli ? 'goerli.' : ''
return `https://${prefix}juicecrowd.gg/p/${projectId}`
}

export const DomainBadge: React.FC<DomainBadgeProps> = ({
className,
domain,
projectId,
}) => {
const domainString = useMemo(() => {
if (!domain) return undefined
Expand All @@ -21,9 +32,14 @@ export const DomainBadge: React.FC<DomainBadgeProps> = ({
if (domain === 'juicecrowd') return '/assets/images/juicecrowd-logo.webp'
}, [domain])

const linkUrl = useMemo(() => {
if (!domain || !projectId) return undefined
if (domain === 'juicecrowd') return getJuicecrowdUrl(projectId)
}, [projectId, domain])

if (!customDomainImageSrc) return null

return (
const badge = (
<Badge className={twMerge('pl-1.5', className)} variant="info">
<Image
height={16}
Expand All @@ -34,4 +50,13 @@ export const DomainBadge: React.FC<DomainBadgeProps> = ({
{domainString}
</Badge>
)

if (linkUrl)
return (
<Link href={linkUrl} target="_blank" rel="noopener noreferrer">
{badge}
</Link>
)

return badge
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const ProjectHeader = ({ className }: { className?: string }) => {

return (
<div className={twMerge('relative flex w-full flex-col', className)}>
<ProjectHeaderLogo className="absolute left-3.5 -top-[146px] rounded-[0.85rem] border-6 border-white dark:border-slate-900 md:left-0" />
<ProjectHeaderLogo className="absolute -top-[146px] left-3.5 rounded-[0.85rem] border-6 border-white dark:border-slate-900 md:left-0" />

<div className="flex items-center justify-end gap-4">
{projectId ? (
Expand Down Expand Up @@ -70,7 +70,7 @@ export const ProjectHeader = ({ className }: { className?: string }) => {
<h1 className="mb-0 font-heading text-3xl font-medium leading-none dark:text-slate-50 md:text-4xl">
{title}
</h1>
<DomainBadge domain={domain} />
<DomainBadge domain={domain} projectId={projectId} />
</div>

<div className="flex flex-col justify-between gap-8 md:flex-row md:gap-12">
Expand Down

2 comments on commit 1977e70

@vercel
Copy link

@vercel vercel bot commented on 1977e70 Nov 19, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 1977e70 Nov 19, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.