diff --git a/src/PageManager.tsx b/src/PageManager.tsx index fd538b6..5f04d14 100644 --- a/src/PageManager.tsx +++ b/src/PageManager.tsx @@ -131,6 +131,27 @@ export function useSmartNoteNavigation() { return { navigateToNote } } +// Custom hook for intelligent relay navigation +export function useSmartRelayNavigation() { + const { hideRecommendedRelaysPanel } = useUserPreferences() + const { push: pushSecondary } = useSecondaryPage() + const { navigate: navigatePrimary } = usePrimaryPage() + + const navigateToRelay = (url: string) => { + if (hideRecommendedRelaysPanel) { + // When right panel is hidden, navigate to relay page in primary area + // Extract relay URL from the path (e.g., "/relays/wss%3A%2F%2F..." -> "wss://...") + const relayUrl = url.startsWith('/relays/') ? decodeURIComponent(url.replace('/relays/', '')) : url + navigatePrimary('relay', { url: relayUrl }) + } else { + // Normal behavior - use secondary navigation + pushSecondary(url) + } + } + + return { navigateToRelay } +} + function ConditionalHomePage() { const { hideRecommendedRelaysPanel } = useUserPreferences() diff --git a/src/components/Explore/index.tsx b/src/components/Explore/index.tsx index 11fc31e..c4ae82f 100644 --- a/src/components/Explore/index.tsx +++ b/src/components/Explore/index.tsx @@ -1,7 +1,7 @@ import { Skeleton } from '@/components/ui/skeleton' import { useFetchRelayInfo } from '@/hooks' import { toRelay } from '@/lib/link' -import { useSecondaryPage } from '@/PageManager' +import { useSmartRelayNavigation } from '@/PageManager' import relayInfoService from '@/services/relay-info.service' import { TAwesomeRelayCollection } from '@/types' import { useEffect, useState } from 'react' @@ -60,7 +60,7 @@ function RelayCollection({ collection }: { collection: TAwesomeRelayCollection } } function RelayItem({ url }: { url: string }) { - const { push } = useSecondaryPage() + const { navigateToRelay } = useSmartRelayNavigation() const { relayInfo, isFetching } = useFetchRelayInfo(url) if (isFetching) { @@ -78,7 +78,7 @@ function RelayItem({ url }: { url: string }) { relayInfo={relayInfo} onClick={(e) => { e.stopPropagation() - push(toRelay(relayInfo.url)) + navigateToRelay(toRelay(relayInfo.url)) }} /> ) diff --git a/src/components/FollowingFavoriteRelayList/index.tsx b/src/components/FollowingFavoriteRelayList/index.tsx index 8838267..c9e6b82 100644 --- a/src/components/FollowingFavoriteRelayList/index.tsx +++ b/src/components/FollowingFavoriteRelayList/index.tsx @@ -1,6 +1,6 @@ import { useFetchRelayInfo } from '@/hooks' import { toRelay } from '@/lib/link' -import { useSecondaryPage } from '@/PageManager' +import { useSmartRelayNavigation } from '@/PageManager' import { useNostr } from '@/providers/NostrProvider' import client from '@/services/client.service' import { useEffect, useRef, useState } from 'react' @@ -73,7 +73,7 @@ export default function FollowingFavoriteRelayList() { } function RelayItem({ url, users }: { url: string; users: string[] }) { - const { push } = useSecondaryPage() + const { navigateToRelay } = useSmartRelayNavigation() const { relayInfo } = useFetchRelayInfo(url) return ( @@ -84,7 +84,7 @@ function RelayItem({ url, users }: { url: string; users: string[] }) { className="clickable p-4 border-b" onClick={(e) => { e.stopPropagation() - push(toRelay(url)) + navigateToRelay(toRelay(url)) }} /> ) diff --git a/src/components/Note/Zap.tsx b/src/components/Note/Zap.tsx index d252304..8cfde88 100644 --- a/src/components/Note/Zap.tsx +++ b/src/components/Note/Zap.tsx @@ -7,12 +7,13 @@ import { Zap as ZapIcon } from 'lucide-react' import { Event } from 'nostr-tools' import { useMemo } from 'react' import { useTranslation } from 'react-i18next' -import { useSecondaryPage } from '@/PageManager' +import { useSmartNoteNavigation, useSecondaryPage } from '@/PageManager' import Username from '../Username' import UserAvatar from '../UserAvatar' export default function Zap({ event, className }: { event: Event; className?: string }) { const { t } = useTranslation() + const { navigateToNote } = useSmartNoteNavigation() const { push } = useSecondaryPage() const zapInfo = useMemo(() => getZapInfoFromEvent(event), [event]) const { event: targetEvent } = useFetchEvent(zapInfo?.eventId) @@ -52,9 +53,9 @@ export default function Zap({ event, className }: { event: Event; className?: st if (isEventZap) { // Event zap - navigate to the zapped event if (targetEvent) { - push(toNote(targetEvent.id)) + navigateToNote(toNote(targetEvent.id)) } else if (zapInfo.eventId) { - push(toNote(zapInfo.eventId)) + navigateToNote(toNote(zapInfo.eventId)) } } else if (isProfileZap && actualRecipientPubkey) { // Profile zap - navigate to the zapped profile diff --git a/src/components/Note/index.tsx b/src/components/Note/index.tsx index 672706f..ed0abb5 100644 --- a/src/components/Note/index.tsx +++ b/src/components/Note/index.tsx @@ -1,4 +1,4 @@ -import { useSecondaryPage } from '@/PageManager' +import { useSmartNoteNavigation } from '@/PageManager' import { ExtendedKind, SUPPORTED_KINDS } from '@/constants' import { getParentBech32Id, isNsfwEvent } from '@/lib/event' import { toNote } from '@/lib/link' @@ -51,7 +51,7 @@ export default function Note({ hideParentNotePreview?: boolean showFull?: boolean }) { - const { push } = useSecondaryPage() + const { navigateToNote } = useSmartNoteNavigation() const { isSmallScreen } = useScreenSize() const parentEventId = useMemo( () => (hideParentNotePreview ? undefined : getParentBech32Id(event)), @@ -169,7 +169,7 @@ export default function Note({ className="p-1 hover:bg-muted rounded transition-colors" onClick={(e) => { e.stopPropagation() - push(toNote(event)) + navigateToNote(toNote(event)) }} title="View in Discussions" > @@ -188,7 +188,7 @@ export default function Note({ className="mt-2" onClick={(e) => { e.stopPropagation() - push(toNote(parentEventId)) + navigateToNote(toNote(parentEventId)) }} /> )} diff --git a/src/components/NotificationList/NotificationItem/MentionNotification.tsx b/src/components/NotificationList/NotificationItem/MentionNotification.tsx index 43e7d36..9aa1a28 100644 --- a/src/components/NotificationList/NotificationItem/MentionNotification.tsx +++ b/src/components/NotificationList/NotificationItem/MentionNotification.tsx @@ -2,7 +2,7 @@ import ParentNotePreview from '@/components/ParentNotePreview' import { NOTIFICATION_LIST_STYLE } from '@/constants' import { getEmbeddedPubkeys, getParentBech32Id } from '@/lib/event' import { toNote } from '@/lib/link' -import { useSecondaryPage } from '@/PageManager' +import { useSmartNoteNavigation } from '@/PageManager' import { useNostr } from '@/providers/NostrProvider' import { useUserPreferences } from '@/providers/UserPreferencesProvider' import { AtSign, MessageCircle, Quote } from 'lucide-react' @@ -19,7 +19,7 @@ export function MentionNotification({ isNew?: boolean }) { const { t } = useTranslation() - const { push } = useSecondaryPage() + const { navigateToNote } = useSmartNoteNavigation() const { pubkey } = useNostr() const { notificationListStyle } = useUserPreferences() const isMention = useMemo(() => { diff --git a/src/components/NotificationList/NotificationItem/Notification.tsx b/src/components/NotificationList/NotificationItem/Notification.tsx index d20d10f..5cdfe12 100644 --- a/src/components/NotificationList/NotificationItem/Notification.tsx +++ b/src/components/NotificationList/NotificationItem/Notification.tsx @@ -7,7 +7,7 @@ import Username from '@/components/Username' import { NOTIFICATION_LIST_STYLE } from '@/constants' import { toNote, toProfile } from '@/lib/link' import { cn } from '@/lib/utils' -import { useSecondaryPage } from '@/PageManager' +import { useSmartNoteNavigation, useSecondaryPage } from '@/PageManager' import { useNostr } from '@/providers/NostrProvider' import { useNotification } from '@/providers/NotificationProvider' import { useUserPreferences } from '@/providers/UserPreferencesProvider' @@ -37,6 +37,7 @@ export default function Notification({ showStats?: boolean }) { const { t } = useTranslation() + const { navigateToNote } = useSmartNoteNavigation() const { push } = useSecondaryPage() const { pubkey } = useNostr() const { isNotificationRead, markNotificationAsRead } = useNotification() @@ -49,7 +50,7 @@ export default function Notification({ const handleClick = () => { markNotificationAsRead(notificationId) if (targetEvent) { - push(toNote(targetEvent.id)) + navigateToNote(toNote(targetEvent.id)) } else if (pubkey) { push(toProfile(pubkey)) } diff --git a/src/components/RelayInfo/RelayReviewCard.tsx b/src/components/RelayInfo/RelayReviewCard.tsx index 12695ba..0b1dd67 100644 --- a/src/components/RelayInfo/RelayReviewCard.tsx +++ b/src/components/RelayInfo/RelayReviewCard.tsx @@ -1,4 +1,4 @@ -import { useSecondaryPage } from '@/PageManager' +import { useSmartNoteNavigation } from '@/PageManager' import { getStarsFromRelayReviewEvent } from '@/lib/event-metadata' import { toNote } from '@/lib/link' import { cn } from '@/lib/utils' @@ -20,13 +20,13 @@ export default function RelayReviewCard({ event: NostrEvent className?: string }) { - const { push } = useSecondaryPage() + const { navigateToNote } = useSmartNoteNavigation() const stars = useMemo(() => getStarsFromRelayReviewEvent(event), [event]) return (