feat: improve style of others relay list
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
import { useSecondaryPage } from '@/PageManager'
|
import { useSecondaryPage } from '@/PageManager'
|
||||||
import { Badge } from '@/components/ui/badge'
|
import { Badge } from '@/components/ui/badge'
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { useFetchRelayList } from '@/hooks'
|
import { useFetchRelayInfo, useFetchRelayList } from '@/hooks'
|
||||||
import { toRelay } from '@/lib/link'
|
import { toRelay } from '@/lib/link'
|
||||||
import { userIdToPubkey } from '@/lib/pubkey'
|
import { userIdToPubkey } from '@/lib/pubkey'
|
||||||
import { simplifyUrl } from '@/lib/url'
|
import { simplifyUrl } from '@/lib/url'
|
||||||
import { TMailboxRelay } from '@/types'
|
import { TMailboxRelay } from '@/types'
|
||||||
import { ListPlus, Telescope } from 'lucide-react'
|
import { ListPlus } from 'lucide-react'
|
||||||
import { useMemo } from 'react'
|
import { useMemo } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import RelayIcon from '../RelayIcon'
|
import RelayIcon from '../RelayIcon'
|
||||||
@@ -22,7 +22,7 @@ export default function OthersRelayList({ userId }: { userId: string }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-2">
|
<div className="space-y-4">
|
||||||
{relayList.originalRelays.map((relay, index) => (
|
{relayList.originalRelays.map((relay, index) => (
|
||||||
<RelayItem key={`read-${relay.url}-${index}`} relay={relay} />
|
<RelayItem key={`read-${relay.url}-${index}`} relay={relay} />
|
||||||
))}
|
))}
|
||||||
@@ -33,26 +33,30 @@ export default function OthersRelayList({ userId }: { userId: string }) {
|
|||||||
function RelayItem({ relay }: { relay: TMailboxRelay }) {
|
function RelayItem({ relay }: { relay: TMailboxRelay }) {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { push } = useSecondaryPage()
|
const { push } = useSecondaryPage()
|
||||||
|
const { relayInfo } = useFetchRelayInfo(relay.url)
|
||||||
const { url, scope } = relay
|
const { url, scope } = relay
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center gap-2 justify-between">
|
<div
|
||||||
<div
|
className="flex items-center gap-2 justify-between p-4 rounded-lg border clickable"
|
||||||
className="flex items-center gap-2 cursor-pointer flex-1 w-0"
|
onClick={() => push(toRelay(url))}
|
||||||
onClick={() => push(toRelay(url))}
|
>
|
||||||
>
|
<div className="flex-1 w-0 space-y-2">
|
||||||
<RelayIcon url={url} />
|
<div className="flex items-center gap-2 w-full">
|
||||||
<div className="truncate">{simplifyUrl(url)}</div>
|
<RelayIcon url={url} />
|
||||||
|
<div className="truncate font-semibold text-lg">{simplifyUrl(url)}</div>
|
||||||
|
</div>
|
||||||
|
{!!relayInfo?.description && <div className="line-clamp-2">{relayInfo.description}</div>}
|
||||||
|
<div className="flex gap-2">
|
||||||
|
{['both', 'read'].includes(scope) && (
|
||||||
|
<Badge className="bg-blue-400 hover:bg-blue-400/80">{t('Read')}</Badge>
|
||||||
|
)}
|
||||||
|
{['both', 'write'].includes(scope) && (
|
||||||
|
<Badge className="bg-green-400 hover:bg-green-400/80">{t('Write')}</Badge>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-1 shrink-0">
|
<div className="flex items-center gap-1 shrink-0" onClick={(e) => e.stopPropagation()}>
|
||||||
{scope === 'read' ? (
|
|
||||||
<Badge className="bg-blue-400 hover:bg-blue-400/80">{t('Read')}</Badge>
|
|
||||||
) : scope === 'write' ? (
|
|
||||||
<Badge className="bg-green-400 hover:bg-green-400/80">{t('Write')}</Badge>
|
|
||||||
) : null}
|
|
||||||
<Button variant="ghost" size="icon" onClick={() => push(toRelay(url))}>
|
|
||||||
<Telescope />
|
|
||||||
</Button>
|
|
||||||
<SaveRelayDropdownMenu urls={[url]}>
|
<SaveRelayDropdownMenu urls={[url]}>
|
||||||
<Button variant="ghost" size="icon">
|
<Button variant="ghost" size="icon">
|
||||||
<ListPlus />
|
<ListPlus />
|
||||||
|
|||||||
@@ -39,14 +39,14 @@ export default function RelayInfo({ url }: { url: string }) {
|
|||||||
<div className="text-sm font-semibold text-muted-foreground">Operator</div>
|
<div className="text-sm font-semibold text-muted-foreground">Operator</div>
|
||||||
<div className="flex gap-2 items-center">
|
<div className="flex gap-2 items-center">
|
||||||
<UserAvatar userId={relayInfo.pubkey} size="small" />
|
<UserAvatar userId={relayInfo.pubkey} size="small" />
|
||||||
<Username userId={relayInfo.pubkey} className="font-semibold whitespace-nowrap" />
|
<Username userId={relayInfo.pubkey} className="font-semibold" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{relayInfo.contact && (
|
{relayInfo.contact && (
|
||||||
<div className="space-y-2 flex-1">
|
<div className="space-y-2 flex-1">
|
||||||
<div className="text-sm font-semibold text-muted-foreground">Contact</div>
|
<div className="text-sm font-semibold text-muted-foreground">Contact</div>
|
||||||
<div className="flex gap-2 items-center font-semibold whitespace-nowrap">
|
<div className="flex gap-2 items-center font-semibold">
|
||||||
<Mail />
|
<Mail />
|
||||||
{relayInfo.contact}
|
{relayInfo.contact}
|
||||||
</div>
|
</div>
|
||||||
@@ -55,7 +55,7 @@ export default function RelayInfo({ url }: { url: string }) {
|
|||||||
{relayInfo.software && (
|
{relayInfo.software && (
|
||||||
<div className="space-y-2 flex-1">
|
<div className="space-y-2 flex-1">
|
||||||
<div className="text-sm font-semibold text-muted-foreground">Software</div>
|
<div className="text-sm font-semibold text-muted-foreground">Software</div>
|
||||||
<div className="flex gap-2 items-center font-semibold whitespace-nowrap">
|
<div className="flex gap-2 items-center font-semibold">
|
||||||
<SquareCode />
|
<SquareCode />
|
||||||
{formatSoftware(relayInfo.software)}
|
{formatSoftware(relayInfo.software)}
|
||||||
</div>
|
</div>
|
||||||
@@ -64,7 +64,7 @@ export default function RelayInfo({ url }: { url: string }) {
|
|||||||
{relayInfo.version && (
|
{relayInfo.version && (
|
||||||
<div className="space-y-2 flex-1">
|
<div className="space-y-2 flex-1">
|
||||||
<div className="text-sm font-semibold text-muted-foreground">Version</div>
|
<div className="text-sm font-semibold text-muted-foreground">Version</div>
|
||||||
<div className="flex gap-2 items-center font-semibold whitespace-nowrap">
|
<div className="flex gap-2 items-center font-semibold">
|
||||||
<GitBranch />
|
<GitBranch />
|
||||||
{relayInfo.version}
|
{relayInfo.version}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,7 +3,11 @@ import { TRelayList } from '@/types'
|
|||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
|
|
||||||
export function useFetchRelayList(pubkey?: string | null) {
|
export function useFetchRelayList(pubkey?: string | null) {
|
||||||
const [relayList, setRelayList] = useState<TRelayList>({ write: [], read: [] })
|
const [relayList, setRelayList] = useState<TRelayList>({
|
||||||
|
write: [],
|
||||||
|
read: [],
|
||||||
|
originalRelays: []
|
||||||
|
})
|
||||||
const [isFetching, setIsFetching] = useState(true)
|
const [isFetching, setIsFetching] = useState(true)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -51,10 +51,6 @@ export default function ProfilePage({ id, index }: { id?: string; index?: number
|
|||||||
() => (profile?.pubkey ? generateImageByPubkey(profile?.pubkey) : ''),
|
() => (profile?.pubkey ? generateImageByPubkey(profile?.pubkey) : ''),
|
||||||
[profile]
|
[profile]
|
||||||
)
|
)
|
||||||
const relayCount = useMemo(
|
|
||||||
() => new Set(relayList.write.concat(relayList.read)).size,
|
|
||||||
[relayList]
|
|
||||||
)
|
|
||||||
const isSelf = accountPubkey === profile?.pubkey
|
const isSelf = accountPubkey === profile?.pubkey
|
||||||
|
|
||||||
if (!profile && isFetching) {
|
if (!profile && isFetching) {
|
||||||
@@ -128,7 +124,7 @@ export default function ProfilePage({ id, index }: { id?: string; index?: number
|
|||||||
to={isSelf ? toRelaySettings('mailbox') : toOthersRelaySettings(pubkey)}
|
to={isSelf ? toRelaySettings('mailbox') : toOthersRelaySettings(pubkey)}
|
||||||
className="flex gap-1 hover:underline w-fit"
|
className="flex gap-1 hover:underline w-fit"
|
||||||
>
|
>
|
||||||
{relayCount}
|
{relayList.originalRelays.length}
|
||||||
<div className="text-muted-foreground">{t('Relays')}</div>
|
<div className="text-muted-foreground">{t('Relays')}</div>
|
||||||
</SecondaryPageLink>
|
</SecondaryPageLink>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import SaveRelayDropdownMenu from '@/components/SaveRelayDropdownMenu'
|
|||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import SecondaryPageLayout from '@/layouts/SecondaryPageLayout'
|
import SecondaryPageLayout from '@/layouts/SecondaryPageLayout'
|
||||||
import { normalizeUrl, simplifyUrl } from '@/lib/url'
|
import { normalizeUrl, simplifyUrl } from '@/lib/url'
|
||||||
import { ListPlus } from 'lucide-react'
|
import { Check, Copy, ListPlus } from 'lucide-react'
|
||||||
import { useMemo } from 'react'
|
import { useMemo, useState } from 'react'
|
||||||
import NotFoundPage from '../NotFoundPage'
|
import NotFoundPage from '../NotFoundPage'
|
||||||
|
|
||||||
export default function RelayPage({ url, index }: { url?: string; index?: number }) {
|
export default function RelayPage({ url, index }: { url?: string; index?: number }) {
|
||||||
@@ -20,13 +20,7 @@ export default function RelayPage({ url, index }: { url?: string; index?: number
|
|||||||
<SecondaryPageLayout
|
<SecondaryPageLayout
|
||||||
index={index}
|
index={index}
|
||||||
title={title}
|
title={title}
|
||||||
controls={
|
controls={<RelayPageControls url={normalizedUrl} />}
|
||||||
<SaveRelayDropdownMenu urls={[normalizedUrl]} asChild>
|
|
||||||
<Button variant="ghost" size="titlebar-icon">
|
|
||||||
<ListPlus />
|
|
||||||
</Button>
|
|
||||||
</SaveRelayDropdownMenu>
|
|
||||||
}
|
|
||||||
displayScrollToTopButton
|
displayScrollToTopButton
|
||||||
>
|
>
|
||||||
<RelayInfo url={normalizedUrl} />
|
<RelayInfo url={normalizedUrl} />
|
||||||
@@ -34,3 +28,25 @@ export default function RelayPage({ url, index }: { url?: string; index?: number
|
|||||||
</SecondaryPageLayout>
|
</SecondaryPageLayout>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function RelayPageControls({ url }: { url: string }) {
|
||||||
|
const [copied, setCopied] = useState(false)
|
||||||
|
const handleCopy = () => {
|
||||||
|
navigator.clipboard.writeText(url)
|
||||||
|
setCopied(true)
|
||||||
|
setTimeout(() => setCopied(false), 2000)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Button variant="ghost" size="titlebar-icon" onClick={handleCopy}>
|
||||||
|
{copied ? <Check /> : <Copy />}
|
||||||
|
</Button>
|
||||||
|
<SaveRelayDropdownMenu urls={[url]} asChild>
|
||||||
|
<Button variant="ghost" size="titlebar-icon">
|
||||||
|
<ListPlus />
|
||||||
|
</Button>
|
||||||
|
</SaveRelayDropdownMenu>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user