feat: remove default favorite relays

This commit is contained in:
codytseng 2025-11-01 15:56:11 +08:00
parent 24348d4f01
commit 38bc425d50
27 changed files with 216 additions and 172 deletions

View file

@ -1,4 +1,4 @@
import { BIG_RELAY_URLS, DEFAULT_FAVORITE_RELAYS } from '@/constants'
import { BIG_RELAY_URLS } from '@/constants'
import { createFavoriteRelaysDraftEvent, createRelaySetDraftEvent } from '@/lib/draft-event'
import { getReplaceableEventIdentifier } from '@/lib/event'
import { getRelaySetFromEvent } from '@/lib/event-metadata'
@ -43,7 +43,7 @@ export function FavoriteRelaysProvider({ children }: { children: React.ReactNode
useEffect(() => {
if (!favoriteRelaysEvent) {
const favoriteRelays: string[] = DEFAULT_FAVORITE_RELAYS
const favoriteRelays: string[] = []
const storedRelaySets = storage.getRelaySets()
storedRelaySets.forEach(({ relayUrls }) => {
relayUrls.forEach((url) => {

View file

@ -1,4 +1,3 @@
import { DEFAULT_FAVORITE_RELAYS } from '@/constants'
import { getRelaySetFromEvent } from '@/lib/event-metadata'
import { isWebsocketUrl, normalizeUrl } from '@/lib/url'
import indexedDb from '@/services/indexed-db.service'
@ -14,7 +13,7 @@ type TFeedContext = {
relayUrls: string[]
isReady: boolean
switchFeed: (
feedType: TFeedType,
feedType: TFeedType | null,
options?: { activeRelaySetId?: string; pubkey?: string; relay?: string | null }
) => Promise<void>
}
@ -31,13 +30,10 @@ export const useFeed = () => {
export function FeedProvider({ children }: { children: React.ReactNode }) {
const { pubkey, isInitialized } = useNostr()
const { relaySets, favoriteRelays } = useFavoriteRelays()
const { relaySets } = useFavoriteRelays()
const [relayUrls, setRelayUrls] = useState<string[]>([])
const [isReady, setIsReady] = useState(false)
const [feedInfo, setFeedInfo] = useState<TFeedInfo>({
feedType: 'relay',
id: DEFAULT_FAVORITE_RELAYS[0]
})
const [feedInfo, setFeedInfo] = useState<TFeedInfo>(null)
const feedInfoRef = useRef<TFeedInfo>(feedInfo)
useEffect(() => {
@ -46,10 +42,7 @@ export function FeedProvider({ children }: { children: React.ReactNode }) {
return
}
let feedInfo: TFeedInfo = {
feedType: 'relay',
id: favoriteRelays[0] ?? DEFAULT_FAVORITE_RELAYS[0]
}
let feedInfo: TFeedInfo = null
if (pubkey) {
const storedFeedInfo = storage.getFeedInfo(pubkey)
if (storedFeedInfo) {
@ -57,6 +50,10 @@ export function FeedProvider({ children }: { children: React.ReactNode }) {
}
}
if (!feedInfo) {
return
}
if (feedInfo.feedType === 'relays') {
return await switchFeed('relays', { activeRelaySetId: feedInfo.id })
}
@ -74,14 +71,27 @@ export function FeedProvider({ children }: { children: React.ReactNode }) {
init()
}, [pubkey, isInitialized])
useEffect(() => {
if (pubkey && !feedInfo) {
switchFeed('following', { pubkey })
}
}, [pubkey, feedInfo])
const switchFeed = async (
feedType: TFeedType,
feedType: TFeedType | null,
options: {
activeRelaySetId?: string | null
pubkey?: string | null
relay?: string | null
} = {}
) => {
if (!feedType) {
setFeedInfo(null)
feedInfoRef.current = null
setRelayUrls([])
return
}
setIsReady(false)
if (feedType === 'relay') {
const normalizedUrl = normalizeUrl(options.relay ?? '')