mirror of
https://github.com/hoornet/vega.git
synced 2026-07-30 11:48:09 -07:00
Working feed: NDK + relay connection + live notes from Nostr
- Tailwind CSS + Zustand + NDK installed and configured - Sidebar with feed/relays/settings navigation - Global feed view with live notes from relays - Profile fetching with caching and deduplication - Relay connection with timeout handling - Note cards with avatar, name, timestamp, content - Dark theme, monospace, no-slop UI - Devtools enabled for debugging
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { fetchProfile } from "../lib/nostr";
|
||||
|
||||
const profileCache = new Map<string, any>();
|
||||
const pendingRequests = new Map<string, Promise<any>>();
|
||||
|
||||
export function useProfile(pubkey: string) {
|
||||
const [profile, setProfile] = useState<any>(profileCache.get(pubkey) ?? null);
|
||||
|
||||
useEffect(() => {
|
||||
if (profileCache.has(pubkey)) {
|
||||
setProfile(profileCache.get(pubkey));
|
||||
return;
|
||||
}
|
||||
|
||||
// Deduplicate requests for the same pubkey
|
||||
if (!pendingRequests.has(pubkey)) {
|
||||
const request = fetchProfile(pubkey).then((p) => {
|
||||
profileCache.set(pubkey, p ?? null);
|
||||
pendingRequests.delete(pubkey);
|
||||
return p;
|
||||
}).catch(() => {
|
||||
pendingRequests.delete(pubkey);
|
||||
return null;
|
||||
});
|
||||
pendingRequests.set(pubkey, request);
|
||||
}
|
||||
|
||||
pendingRequests.get(pubkey)!.then((p) => {
|
||||
setProfile(p ?? null);
|
||||
});
|
||||
}, [pubkey]);
|
||||
|
||||
return profile;
|
||||
}
|
||||
Reference in New Issue
Block a user