- Refactor useNostr composable to utilize a centralized Pinia store for connection state and client management. - Update NostrFeed and App components to leverage the new store-based approach for relay configuration and client instantiation. - Remove direct relay URL handling from components, improving maintainability and consistency across the application.
24 lines
No EOL
618 B
TypeScript
24 lines
No EOL
618 B
TypeScript
import { storeToRefs } from 'pinia'
|
|
import { useNostrStore } from '@/stores/nostr'
|
|
import type { NostrClientConfig } from '@/lib/nostr/client'
|
|
|
|
export function useNostr(config?: NostrClientConfig) {
|
|
const store = useNostrStore()
|
|
|
|
// If custom relays are provided, update the store
|
|
if (config?.relays) {
|
|
store.setRelayUrls(config.relays)
|
|
}
|
|
|
|
// Return reactive refs from the store
|
|
const { isConnected, isConnecting, error } = storeToRefs(store)
|
|
|
|
return {
|
|
isConnected,
|
|
isConnecting,
|
|
error,
|
|
connect: store.connect,
|
|
disconnect: store.disconnect,
|
|
getClient: store.getClient
|
|
}
|
|
}
|