feat: check login status before saving relays

This commit is contained in:
codytseng
2025-08-03 15:13:47 +08:00
parent ba4f6b382c
commit f9cbcda7e8

View File

@@ -17,6 +17,7 @@ import {
import { Separator } from '@/components/ui/separator'
import { normalizeUrl } from '@/lib/url'
import { useFavoriteRelays } from '@/providers/FavoriteRelaysProvider'
import { useNostr } from '@/providers/NostrProvider'
import { useScreenSize } from '@/providers/ScreenSizeProvider'
import { TRelaySet } from '@/types'
import { Check, FolderPlus, Plus, Star } from 'lucide-react'
@@ -138,10 +139,15 @@ function RelayItem({ urls }: { urls: string[] }) {
function RelaySetItem({ set, urls }: { set: TRelaySet; urls: string[] }) {
const { isSmallScreen } = useScreenSize()
const { pubkey, startLogin } = useNostr()
const { updateRelaySet } = useFavoriteRelays()
const saved = urls.every((url) => set.relayUrls.includes(url))
const handleClick = () => {
if (!pubkey) {
startLogin()
return
}
if (saved) {
updateRelaySet({
...set,
@@ -175,9 +181,14 @@ function RelaySetItem({ set, urls }: { set: TRelaySet; urls: string[] }) {
function SaveToNewSet({ urls }: { urls: string[] }) {
const { t } = useTranslation()
const { isSmallScreen } = useScreenSize()
const { pubkey, startLogin } = useNostr()
const { createRelaySet } = useFavoriteRelays()
const handleSave = () => {
if (!pubkey) {
startLogin()
return
}
const newSetName = prompt(t('Enter a name for the new relay set'))
if (newSetName) {
createRelaySet(newSetName, urls)