feat: add post button to relayInfo component

This commit is contained in:
codytseng
2025-08-29 22:59:00 +08:00
parent 8c9416a6c8
commit 8b1f11d2ab
19 changed files with 57 additions and 49 deletions

View File

@@ -27,11 +27,13 @@ import Uploader from './Uploader'
export default function PostContent({
defaultContent = '',
parentEvent,
close
close,
openFrom
}: {
defaultContent?: string
parentEvent?: Event
close: () => void
openFrom?: string[]
}) {
const { t } = useTranslation()
const { pubkey, publish, checkLogin } = useNostr()
@@ -233,6 +235,7 @@ export default function PostContent({
parentEvent={parentEvent}
specifiedRelayUrls={specifiedRelayUrls}
setSpecifiedRelayUrls={setSpecifiedRelayUrls}
openFrom={openFrom}
/>
)}
<div className="flex items-center justify-between">

View File

@@ -13,17 +13,24 @@ import { useTranslation } from 'react-i18next'
export default function SendOnlyToSwitch({
parentEvent,
specifiedRelayUrls,
setSpecifiedRelayUrls
setSpecifiedRelayUrls,
openFrom
}: {
parentEvent?: Event
specifiedRelayUrls?: string[]
setSpecifiedRelayUrls: Dispatch<SetStateAction<string[] | undefined>>
openFrom?: string[]
}) {
const { t } = useTranslation()
const { currentRelayUrls } = useCurrentRelays()
const [urls, setUrls] = useState<string[]>([])
useEffect(() => {
if (openFrom?.length) {
setUrls(openFrom)
setSpecifiedRelayUrls(openFrom)
return
}
if (!parentEvent) {
setUrls(currentRelayUrls)
return
@@ -36,7 +43,7 @@ export default function SendOnlyToSwitch({
} else {
setUrls(currentRelayUrls)
}
}, [parentEvent, currentRelayUrls])
}, [parentEvent, currentRelayUrls, openFrom])
if (!urls.length) return null

View File

@@ -24,12 +24,14 @@ export default function PostEditor({
defaultContent = '',
parentEvent,
open,
setOpen
setOpen,
openFrom
}: {
defaultContent?: string
parentEvent?: Event
open: boolean
setOpen: Dispatch<boolean>
openFrom?: string[]
}) {
const { isSmallScreen } = useScreenSize()
@@ -39,6 +41,7 @@ export default function PostEditor({
defaultContent={defaultContent}
parentEvent={parentEvent}
close={() => setOpen(false)}
openFrom={openFrom}
/>
)
}, [])

View File

@@ -1,8 +1,11 @@
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import { useFetchRelayInfo } from '@/hooks'
import { normalizeHttpUrl } from '@/lib/url'
import { GitBranch, Mail, SquareCode } from 'lucide-react'
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import PostEditor from '../PostEditor'
import RelayBadges from '../RelayBadges'
import RelayIcon from '../RelayIcon'
import UserAvatar from '../UserAvatar'
@@ -11,6 +14,8 @@ import Username from '../Username'
export default function RelayInfo({ url }: { url: string }) {
const { t } = useTranslation()
const { relayInfo, isFetching } = useFetchRelayInfo(url)
const [open, setOpen] = useState(false)
if (isFetching || !relayInfo) {
return null
}
@@ -38,29 +43,7 @@ export default function RelayInfo({ url }: { url: string }) {
</div>
)}
</div>
{!!relayInfo.supported_nips?.length && (
<div className="space-y-2">
<div className="text-sm font-semibold text-muted-foreground">{t('Supported NIPs')}</div>
<div className="flex flex-wrap gap-2">
{relayInfo.supported_nips
.sort((a, b) => a - b)
.map((nip) => (
<Badge
key={nip}
variant="secondary"
className="clickable"
onClick={() =>
window.open(
`https://github.com/nostr-protocol/nips/blob/master/${formatNip(nip)}.md`
)
}
>
{formatNip(nip)}
</Badge>
))}
</div>
</div>
)}
{relayInfo.payments_url && (
<div className="space-y-2">
<div className="text-sm font-semibold text-muted-foreground">{t('Payment page')}:</div>
@@ -111,6 +94,10 @@ export default function RelayInfo({ url }: { url: string }) {
</div>
)}
</div>
<Button variant="secondary" className="w-full" onClick={() => setOpen(true)}>
{t('Share something on this Relay')}
</Button>
<PostEditor open={open} setOpen={setOpen} openFrom={[relayInfo.url]} />
</div>
)
}
@@ -119,10 +106,3 @@ function formatSoftware(software: string) {
const parts = software.split('/')
return parts[parts.length - 1]
}
function formatNip(nip: number) {
if (nip < 10) {
return `0${nip}`
}
return `${nip}`
}