Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/components/EditProfileForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ export const EditProfileForm: React.FC = () => {
// Invalidate queries to refresh the data
queryClient.invalidateQueries({ queryKey: ['logins'] });
queryClient.invalidateQueries({ queryKey: ['author', user.pubkey] });
// The contributor graph caches member profiles under its own key —
// drop it too or the edited avatar stays stale on next graph mount.
queryClient.invalidateQueries({ queryKey: ['member-profile', user.pubkey] });

toast({
title: 'Success',
Expand Down
23 changes: 19 additions & 4 deletions src/components/zaplytics/ContributorNetworkGraph.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Skeleton } from '@/components/ui/skeleton';
import { useState, useMemo } from 'react';
import { useQueries } from '@tanstack/react-query';
import { useQueries, useQueryClient } from '@tanstack/react-query';
import type { MemberStats } from '@/hooks/useCommunityZapStats';
import { formatSats } from '@/lib/zaplytics/utils';
import { useAppContext } from '@/hooks/useAppContext';
import { useNostr } from '@nostrify/react';
import { queryWithNip65Fanout, getNip65ReadRelays } from '@/lib/queryRelays';
import { queryWithNip65Fanout, getNip65ReadRelays, FALLBACK_DISCOVERY_RELAYS } from '@/lib/queryRelays';
import { NSchema as n } from '@nostrify/nostrify';

interface ContributorNetworkGraphProps {
Expand Down Expand Up @@ -260,17 +260,32 @@ export function ContributorNetworkGraph({ members, isLoading }: ContributorNetwo
function useMemberProfiles(pubkeys: string[]): Map<string, { name?: string; picture?: string }> {
const { nostr } = useNostr();
const { config } = useAppContext();
const queryClient = useQueryClient();
const nip65ReadRelays = getNip65ReadRelays(config.relayMetadata);
// Match useAuthor's coverage: member profiles may live only on the
// well-known discovery relays, not the current user's read set.
const profileRelays = [...new Set([...nip65ReadRelays, ...FALLBACK_DISCOVERY_RELAYS])];

const queries = useQueries({
queries: pubkeys.map((pubkey) => ({
queryKey: ['author', pubkey],
// Must NOT share 'author' with useAuthor — that hook caches
// {event, metadata} under the same key and would poison this
// lookup with the wrong shape (member avatars never resolved).
queryKey: ['member-profile', pubkey],
queryFn: async ({ signal }: { signal: AbortSignal }) => {
if (!pubkey) return null;
// Reuse a cached useAuthor result instead of refetching — the
// member table already loads the same profiles. Skip it when the
// entry was invalidated (e.g. profile edit): getQueryData still
// returns the pre-invalidation data while it waits to refetch.
const cacheState = queryClient.getQueryState(['author', pubkey]);
const cached = cacheState?.isInvalidated ? undefined
: queryClient.getQueryData<{ metadata?: { name?: string; display_name?: string; picture?: string } }>(['author', pubkey]);
if (cached?.metadata) return cached.metadata;
let [event] = await queryWithNip65Fanout(
nostr,
[{ kinds: [0], authors: [pubkey], limit: 1 }],
nip65ReadRelays,
profileRelays,
AbortSignal.any([signal, AbortSignal.timeout(1500)]),
);
if (!event) {
Expand Down
Loading