From 496b19f0211973f4b80db374f5de817cc1949337 Mon Sep 17 00:00:00 2001 From: Gigi Date: Thu, 2 Oct 2025 07:21:55 +0200 Subject: [PATCH] feat: display user profile name instead of public key - Fetch user profile from nostr relay on login - Display NIP-05, display name, or username instead of public key - Priority: NIP-05 > name > username > public key - Add WebSocket connection to fetch profile events (kind 0) - Update Login component to fetch and pass profile data - Update Bookmarks component to show user-friendly display name - Fallback to formatted public key if no profile available - Improve user experience with recognizable identity --- .cursor/rules/210.mdc | 5 +++ .cursor/rules/always-commit.mdc | 5 +++ .cursor/rules/dry.mdc | 5 +++ dist/index.html | 2 +- src/App.tsx | 6 ++- src/components/Bookmarks.tsx | 32 +++++++++++++--- src/components/Login.tsx | 68 ++++++++++++++++++++++++++++++++- 7 files changed, 114 insertions(+), 9 deletions(-) create mode 100644 .cursor/rules/210.mdc create mode 100644 .cursor/rules/always-commit.mdc create mode 100644 .cursor/rules/dry.mdc diff --git a/.cursor/rules/210.mdc b/.cursor/rules/210.mdc new file mode 100644 index 00000000..b8bbebc4 --- /dev/null +++ b/.cursor/rules/210.mdc @@ -0,0 +1,5 @@ +--- +alwaysApply: true +--- + +Keep files below 210 lines. \ No newline at end of file diff --git a/.cursor/rules/always-commit.mdc b/.cursor/rules/always-commit.mdc new file mode 100644 index 00000000..3662e8ad --- /dev/null +++ b/.cursor/rules/always-commit.mdc @@ -0,0 +1,5 @@ +--- +alwaysApply: true +--- + +Commit all pending changes. Commit using conventional commits. Always commit after each implementation step or change. diff --git a/.cursor/rules/dry.mdc b/.cursor/rules/dry.mdc new file mode 100644 index 00000000..8251ef43 --- /dev/null +++ b/.cursor/rules/dry.mdc @@ -0,0 +1,5 @@ +--- +alwaysApply: true +--- + +Keep things simple. Strive to keep code DRY. diff --git a/dist/index.html b/dist/index.html index c96e1c24..35e5dd00 100644 --- a/dist/index.html +++ b/dist/index.html @@ -5,7 +5,7 @@ Markr - Nostr Bookmarks - + diff --git a/src/App.tsx b/src/App.tsx index 80898fdb..6f0299b5 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -8,6 +8,7 @@ function App() { const [eventStore, setEventStore] = useState(null) const [isAuthenticated, setIsAuthenticated] = useState(false) const [userPublicKey, setUserPublicKey] = useState(null) + const [userProfile, setUserProfile] = useState<{name?: string, username?: string, nip05?: string} | null>(null) useEffect(() => { // Initialize event store @@ -28,16 +29,19 @@ function App() { {!isAuthenticated ? ( - { + { setIsAuthenticated(true) setUserPublicKey(publicKey) + setUserProfile(profile) }} /> ) : ( { setIsAuthenticated(false) setUserPublicKey(null) + setUserProfile(null) }} /> )} diff --git a/src/components/Bookmarks.tsx b/src/components/Bookmarks.tsx index 9098f48a..0f00788e 100644 --- a/src/components/Bookmarks.tsx +++ b/src/components/Bookmarks.tsx @@ -11,12 +11,19 @@ interface Bookmark { tags: string[][] } +interface UserProfile { + name?: string + username?: string + nip05?: string +} + interface BookmarksProps { userPublicKey: string | null + userProfile: UserProfile | null onLogout: () => void } -const Bookmarks: React.FC = ({ userPublicKey, onLogout }) => { +const Bookmarks: React.FC = ({ userPublicKey, userProfile, onLogout }) => { const [bookmarks, setBookmarks] = useState([]) const [loading, setLoading] = useState(true) const eventStore = useContext(EventStoreContext) @@ -104,8 +111,23 @@ const Bookmarks: React.FC = ({ userPublicKey, onLogout }) => { return new Date(timestamp * 1000).toLocaleDateString() } - const formatPublicKey = (publicKey: string) => { - return `${publicKey.slice(0, 8)}...${publicKey.slice(-8)}` + const formatUserDisplay = (profile: UserProfile | null, publicKey: string | null) => { + if (!profile || (!profile.name && !profile.username && !profile.nip05)) { + return publicKey ? `${publicKey.slice(0, 8)}...${publicKey.slice(-8)}` : 'Unknown User' + } + + // Priority: NIP-05 > name > username + if (profile.nip05) { + return profile.nip05 + } + if (profile.name) { + return profile.name + } + if (profile.username) { + return `@${profile.username}` + } + + return publicKey ? `${publicKey.slice(0, 8)}...${publicKey.slice(-8)}` : 'Unknown User' } if (loading) { @@ -115,7 +137,7 @@ const Bookmarks: React.FC = ({ userPublicKey, onLogout }) => {

Your Bookmarks

{userPublicKey && ( -

Logged in as: {formatPublicKey(userPublicKey)}

+

Logged in as: {formatUserDisplay(userProfile, userPublicKey)}

)}