- {primaryPages.map(({ name, element, props }) => (
-
- {props ? cloneElement(element as React.ReactElement, props) : element}
-
- ))}
-
- {secondaryStack.map((item, index) => (
+
+
+
+
+
+
+ {primaryPages.map(({ name, element, props }) => (
+
+ {props ? cloneElement(element as React.ReactElement, props) : element}
+
+ ))}
+
+
+ {secondaryStack.map((item, index) => (
+
+ {item.component}
+
+ ))}
- {item.component}
+
- ))}
-
-
-
-
-
+
+
+
)
diff --git a/src/components/PostEditor/SendOnlyToSwitch.tsx b/src/components/PostEditor/SendOnlyToSwitch.tsx
index ea720d8..0377df0 100644
--- a/src/components/PostEditor/SendOnlyToSwitch.tsx
+++ b/src/components/PostEditor/SendOnlyToSwitch.tsx
@@ -3,7 +3,7 @@ import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover
import { Switch } from '@/components/ui/switch'
import { isProtectedEvent } from '@/lib/event'
import { simplifyUrl } from '@/lib/url'
-import { useFeed } from '@/providers/FeedProvider'
+import { useCurrentRelays } from '@/providers/CurrentRelaysProvider'
import client from '@/services/client.service'
import { Info } from 'lucide-react'
import { Event } from 'nostr-tools'
@@ -20,12 +20,12 @@ export default function SendOnlyToSwitch({
setSpecifiedRelayUrls: Dispatch
>
}) {
const { t } = useTranslation()
- const { relayUrls } = useFeed()
+ const { currentRelayUrls } = useCurrentRelays()
const [urls, setUrls] = useState([])
useEffect(() => {
if (!parentEvent) {
- setUrls(relayUrls)
+ setUrls(currentRelayUrls)
return
}
const isProtected = isProtectedEvent(parentEvent)
@@ -34,9 +34,9 @@ export default function SendOnlyToSwitch({
setSpecifiedRelayUrls(seenOn)
setUrls(seenOn)
} else {
- setUrls(relayUrls)
+ setUrls(currentRelayUrls)
}
- }, [parentEvent, relayUrls])
+ }, [parentEvent, currentRelayUrls])
if (!urls.length) return null
diff --git a/src/pages/primary/RelayPage/index.tsx b/src/pages/primary/RelayPage/index.tsx
index 63f798d..7f8a6bf 100644
--- a/src/pages/primary/RelayPage/index.tsx
+++ b/src/pages/primary/RelayPage/index.tsx
@@ -2,12 +2,20 @@ import Relay from '@/components/Relay'
import RelayPageControls from '@/components/RelayPageControls'
import PrimaryPageLayout from '@/layouts/PrimaryPageLayout'
import { normalizeUrl, simplifyUrl } from '@/lib/url'
+import { useCurrentRelays } from '@/providers/CurrentRelaysProvider'
import { Server } from 'lucide-react'
-import { forwardRef, useMemo } from 'react'
+import { forwardRef, useEffect, useMemo } from 'react'
const RelayPage = forwardRef(({ url }: { url?: string }, ref) => {
+ const { setTemporaryRelayUrls } = useCurrentRelays()
const normalizedUrl = useMemo(() => (url ? normalizeUrl(url) : undefined), [url])
+ useEffect(() => {
+ if (normalizedUrl) {
+ setTemporaryRelayUrls([normalizedUrl])
+ }
+ }, [normalizedUrl])
+
return (
void
+}
+
+const CurrentRelaysContext = createContext(undefined)
+
+export const useCurrentRelays = () => {
+ const context = useContext(CurrentRelaysContext)
+ if (!context) {
+ throw new Error('useCurrentRelays must be used within a CurrentRelaysProvider')
+ }
+ return context
+}
+
+export function CurrentRelaysProvider({ children }: { children: React.ReactNode }) {
+ const { current } = usePrimaryPage()
+ const { relayUrls } = useFeed()
+ const [currentRelayUrls, setCurrentRelayUrls] = useState([])
+ const [temporaryRelayUrls, setTemporaryRelayUrls] = useState([])
+
+ useEffect(() => {
+ setCurrentRelayUrls(current === 'relay' ? temporaryRelayUrls : relayUrls)
+ }, [temporaryRelayUrls, current, relayUrls])
+
+ return (
+
+ {children}
+
+ )
+}