feat: community mode (#738)

Co-authored-by: CXPLAY <62034099+cxplay@users.noreply.github.com>
This commit is contained in:
Cody Tseng 2026-01-24 00:09:10 +08:00 committed by GitHub
parent 686b1f9998
commit ed8a22d5bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 303 additions and 101 deletions

View file

@ -2,6 +2,7 @@ import FeedSwitcher from '@/components/FeedSwitcher'
import RelayIcon from '@/components/RelayIcon'
import { Drawer, DrawerContent } from '@/components/ui/drawer'
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
import { IS_COMMUNITY_MODE, COMMUNITY_RELAY_SETS, COMMUNITY_RELAYS } from '@/constants'
import { simplifyUrl } from '@/lib/url'
import { cn } from '@/lib/utils'
import { useFavoriteRelays } from '@/providers/FavoriteRelaysProvider'
@ -15,6 +16,10 @@ export default function FeedButton({ className }: { className?: string }) {
const { isSmallScreen } = useScreenSize()
const [open, setOpen] = useState(false)
if (IS_COMMUNITY_MODE && COMMUNITY_RELAY_SETS.length + COMMUNITY_RELAYS.length <= 1) {
return <FeedSwitcherTrigger className={className} />
}
if (isSmallScreen) {
return (
<>
@ -61,7 +66,8 @@ const FeedSwitcherTrigger = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivEle
const { relaySets } = useFavoriteRelays()
const activeRelaySet = useMemo(() => {
return feedInfo?.feedType === 'relays' && feedInfo.id
? relaySets.find((set) => set.id === feedInfo.id)
? (relaySets.find((set) => set.id === feedInfo.id) ??
COMMUNITY_RELAY_SETS.find((set) => set.id === feedInfo.id))
: undefined
}, [feedInfo, relaySets])
const title = useMemo(() => {
@ -78,7 +84,7 @@ const FeedSwitcherTrigger = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivEle
return simplifyUrl(feedInfo?.id ?? '')
}
if (feedInfo?.feedType === 'relays') {
return activeRelaySet?.name ?? activeRelaySet?.id
return feedInfo.name ?? activeRelaySet?.name ?? activeRelaySet?.id
}
}, [feedInfo, activeRelaySet])
@ -92,15 +98,22 @@ const FeedSwitcherTrigger = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivEle
return <Server />
}, [feedInfo])
const clickable =
!IS_COMMUNITY_MODE || COMMUNITY_RELAY_SETS.length + COMMUNITY_RELAYS.length > 1
return (
<div
className={cn('clickable flex h-full items-center gap-2 rounded-xl px-3', className)}
className={cn(
'flex h-full items-center gap-2 rounded-xl px-3',
clickable && 'clickable',
className
)}
ref={ref}
{...props}
>
{icon}
<div className="truncate text-lg font-semibold">{title}</div>
<ChevronDown />
{clickable && <ChevronDown />}
</div>
)
}