improve: use applesauce-react event models for better profile handling

- Import useEventModel hook and Models from applesauce-core
- Use ProfileModel to automatically fetch and manage user profile data
- Display user name, display_name, or nip05 instead of just public key
- Follow applesauce-react best practices for event model usage
- Improve user experience with proper profile information display
- Maintain fallback to formatted public key if profile data unavailable

This follows the applesauce-react documentation pattern for using
event models instead of manual event parsing.
This commit is contained in:
Gigi
2025-10-02 08:29:38 +02:00
parent 208dbb17cf
commit 9eeda77132

View File

@@ -1,5 +1,7 @@
import React, { useState, useEffect } from 'react'
import { Hooks } from 'applesauce-react'
import { useEventModel } from 'applesauce-react/hooks'
import { Models } from 'applesauce-core'
import { NostrEvent } from 'nostr-tools'
interface Bookmark {
@@ -26,6 +28,9 @@ const Bookmarks: React.FC<BookmarksProps> = ({ addressLoader, onLogout }) => {
const [bookmarks, setBookmarks] = useState<Bookmark[]>([])
const [loading, setLoading] = useState(true)
const activeAccount = Hooks.useActiveAccount()
// Use ProfileModel to get user profile information
const profile = useEventModel(Models.ProfileModel, activeAccount ? [activeAccount.pubkey] : null)
useEffect(() => {
if (addressLoader && activeAccount) {
@@ -125,9 +130,19 @@ const Bookmarks: React.FC<BookmarksProps> = ({ addressLoader, onLogout }) => {
const formatUserDisplay = () => {
if (!activeAccount) return 'Unknown User'
// For now, just show the formatted public key
// TODO: Implement profile fetching through applesauce system
// Use profile data from ProfileModel if available
if (profile?.name) {
return profile.name
}
if (profile?.display_name) {
return profile.display_name
}
if (profile?.nip05) {
return profile.nip05
}
// Fallback to formatted public key
return `${activeAccount.pubkey.slice(0, 8)}...${activeAccount.pubkey.slice(-8)}`
}