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}`
}

View File

@@ -365,6 +365,7 @@ export default {
'Clear All': 'مسح الكل',
'Remember my choice': 'تذكر اختياري',
Apply: 'تطبيق',
Reset: 'إعادة تعيين'
Reset: 'إعادة تعيين',
'Share something on this Relay': 'شارك شيئاً على هذا الريلاي'
}
}

View File

@@ -372,6 +372,7 @@ export default {
'Clear All': 'Alle löschen',
'Remember my choice': 'Meine Auswahl merken',
Apply: 'Anwenden',
Reset: 'Zurücksetzen'
Reset: 'Zurücksetzen',
'Share something on this Relay': 'Teile etwas auf diesem Relay'
}
}

View File

@@ -366,6 +366,7 @@ export default {
'Clear All': 'Clear All',
'Remember my choice': 'Remember my choice',
Apply: 'Apply',
Reset: 'Reset'
Reset: 'Reset',
'Share something on this Relay': 'Share something on this Relay'
}
}

View File

@@ -371,6 +371,7 @@ export default {
'Clear All': 'Limpiar todo',
'Remember my choice': 'Recordar mi elección',
Apply: 'Aplicar',
Reset: 'Restablecer'
Reset: 'Restablecer',
'Share something on this Relay': 'Comparte algo en este relé'
}
}

View File

@@ -366,6 +366,7 @@ export default {
'Clear All': 'پاک کردن همه',
'Remember my choice': 'انتخاب من را به خاطر بسپار',
Apply: 'اعمال',
Reset: 'بازنشانی'
Reset: 'بازنشانی',
'Share something on this Relay': 'در این رله چیزی به اشتراک بگذارید'
}
}

View File

@@ -371,6 +371,7 @@ export default {
'Clear All': 'Tout effacer',
'Remember my choice': 'Se souvenir de mon choix',
Apply: 'Appliquer',
Reset: 'Réinitialiser'
Reset: 'Réinitialiser',
'Share something on this Relay': 'Partager quelque chose sur ce relais'
}
}

View File

@@ -370,6 +370,7 @@ export default {
'Clear All': 'Cancella tutto',
'Remember my choice': 'Ricorda la mia scelta',
Apply: 'Applica',
Reset: 'Reimposta'
Reset: 'Reimposta',
'Share something on this Relay': 'Condividi qualcosa su questo Relay'
}
}

View File

@@ -368,6 +368,7 @@ export default {
'Clear All': 'すべてクリア',
'Remember my choice': '選択を記憶',
Apply: '適用',
Reset: 'リセット'
Reset: 'リセット',
'Share something on this Relay': 'このリレーで何かを共有する'
}
}

View File

@@ -367,6 +367,7 @@ export default {
'Clear All': '모두 지우기',
'Remember my choice': '내 선택 기억하기',
Apply: '적용',
Reset: '초기화'
Reset: '초기화',
'Share something on this Relay': '이 릴레이에서 무언가를 공유하세요'
}
}

View File

@@ -370,6 +370,7 @@ export default {
'Clear All': 'Wyczyść wszystko',
'Remember my choice': 'Zapamiętaj mój wybór',
Apply: 'Zastosuj',
Reset: 'Resetuj'
Reset: 'Resetuj',
'Share something on this Relay': 'Udostępnij coś na tym przekaźniku'
}
}

View File

@@ -369,6 +369,7 @@ export default {
'Clear All': 'Limpar tudo',
'Remember my choice': 'Lembrar minha escolha',
Apply: 'Aplicar',
Reset: 'Redefinir'
Reset: 'Redefinir',
'Share something on this Relay': 'Compartilhe algo neste Relay'
}
}

View File

@@ -370,6 +370,7 @@ export default {
'Clear All': 'Limpar tudo',
'Remember my choice': 'Lembrar a minha escolha',
Apply: 'Aplicar',
Reset: 'Repor'
Reset: 'Repor',
'Share something on this Relay': 'Partilhe algo neste Relay'
}
}

View File

@@ -370,6 +370,7 @@ export default {
'Clear All': 'Очистить все',
'Remember my choice': 'Запомнить мой выбор',
Apply: 'Применить',
Reset: 'Сбросить'
Reset: 'Сбросить',
'Share something on this Relay': 'Поделиться чем-то на этом релее'
}
}

View File

@@ -364,6 +364,7 @@ export default {
'Clear All': 'ล้างทั้งหมด',
'Remember my choice': 'จำการเลือกของฉัน',
Apply: 'ใช้',
Reset: 'รีเซ็ต'
Reset: 'รีเซ็ต',
'Share something on this Relay': 'แชร์บางอย่างบนรีเลย์นี้'
}
}

View File

@@ -362,6 +362,7 @@ export default {
'Clear All': '清空',
'Remember my choice': '记住我的选择',
Apply: '应用',
Reset: '重置'
Reset: '重置',
'Share something on this Relay': '在此服务器上分享点什么'
}
}