- Raise QUERY_TIMEOUT in useSkateSpots from 8s to 15s - Raise AbortSignal.timeout in useLabProfiles and useSkateEvents from 10s to 15s - Add useSkateRelay to AppConfigSchema so it's preserved when reading from localStorage On a fresh phone (no warm WebSocket, no TanStack Query cache), the app needs to: load JS bundle, boot React providers, open a WebSocket to goskatespots.nostr1.com, and receive EOSE — all before the timeout. On slow mobile connections this easily exceeded the old 8-10s limits, causing /home to show empty sections while /map worked (the connection was already warm by then). 15s gives cold connections enough headroom. Co-authored-by: shakespeare.diy <assistant@shakespeare.diy>
112 lines
3.6 KiB
TypeScript
112 lines
3.6 KiB
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import { SKATE_COACH_KIND, SKATE_FILMER_KIND, SKATE_EDITOR_KIND, parseSkateCoach, parseSkateFilmer, parseSkateEditor, type SkateCoach, type SkateFilmer, type SkateEditor } from '@/lib/types';
|
|
import { useSkateRelays } from '@/hooks/useSkateRelays';
|
|
|
|
export type LabProfile = (SkateCoach | SkateFilmer | SkateEditor) & {
|
|
profileType: 'coach' | 'filmer' | 'editor';
|
|
};
|
|
|
|
export function useLabProfiles(limit = 100) {
|
|
const { querySkateContent, getQueryKeySuffix } = useSkateRelays();
|
|
|
|
return useQuery({
|
|
queryKey: ['lab-profiles', limit, getQueryKeySuffix()],
|
|
queryFn: async () => {
|
|
const signal = AbortSignal.timeout(15000);
|
|
|
|
console.log('[useLabProfiles] Querying for coaches and filmers...');
|
|
|
|
const events = await querySkateContent(
|
|
[
|
|
{
|
|
kinds: [SKATE_COACH_KIND, SKATE_FILMER_KIND, SKATE_EDITOR_KIND],
|
|
'#t': ['skatecoach', 'skatefilmer', 'skateeditor'],
|
|
limit: limit * 2,
|
|
},
|
|
],
|
|
{ signal }
|
|
);
|
|
|
|
console.log(`[useLabProfiles] Received ${events.length} events`);
|
|
|
|
const profiles: LabProfile[] = [];
|
|
for (const event of events) {
|
|
if (event.kind === SKATE_COACH_KIND) {
|
|
const coach = parseSkateCoach(event);
|
|
if (coach) {
|
|
profiles.push({ ...coach, profileType: 'coach' });
|
|
}
|
|
} else if (event.kind === SKATE_FILMER_KIND) {
|
|
const filmer = parseSkateFilmer(event);
|
|
if (filmer) {
|
|
profiles.push({ ...filmer, profileType: 'filmer' });
|
|
}
|
|
} else if (event.kind === SKATE_EDITOR_KIND) {
|
|
const editor = parseSkateEditor(event);
|
|
if (editor) {
|
|
profiles.push({ ...editor, profileType: 'editor' });
|
|
}
|
|
}
|
|
}
|
|
|
|
console.log(`[useLabProfiles] Parsed profiles: ${profiles.length} (coaches + filmers + editors)`);
|
|
|
|
return profiles.sort((a, b) => b.createdAt - a.createdAt);
|
|
},
|
|
staleTime: 30000,
|
|
refetchOnMount: 'always',
|
|
});
|
|
}
|
|
|
|
export function useLabProfile(identifier: string, pubkey?: string) {
|
|
const { querySkateContent, getQueryKeySuffix } = useSkateRelays();
|
|
|
|
return useQuery({
|
|
queryKey: ['lab-profile', identifier, pubkey, getQueryKeySuffix()],
|
|
queryFn: async () => {
|
|
const signal = AbortSignal.timeout(10000);
|
|
|
|
const filter: {
|
|
kinds: number[];
|
|
'#d': string[];
|
|
authors?: string[];
|
|
limit: number;
|
|
} = {
|
|
kinds: [SKATE_COACH_KIND, SKATE_FILMER_KIND, SKATE_EDITOR_KIND],
|
|
'#d': [identifier],
|
|
limit: 1,
|
|
};
|
|
|
|
if (pubkey) filter.authors = [pubkey];
|
|
|
|
console.log(`[useLabProfile] Querying for profile: ${identifier}`);
|
|
|
|
const events = await querySkateContent([filter], { signal });
|
|
|
|
console.log(`[useLabProfile] Received ${events.length} events`);
|
|
|
|
if (events.length === 0) {
|
|
console.warn(`[useLabProfile] No events found for identifier: ${identifier}`);
|
|
return null;
|
|
}
|
|
|
|
const event = events[0];
|
|
|
|
if (event.kind === SKATE_COACH_KIND) {
|
|
const coach = parseSkateCoach(event);
|
|
return coach ? { ...coach, profileType: 'coach' as const } : null;
|
|
} else if (event.kind === SKATE_FILMER_KIND) {
|
|
const filmer = parseSkateFilmer(event);
|
|
return filmer ? { ...filmer, profileType: 'filmer' as const } : null;
|
|
} else if (event.kind === SKATE_EDITOR_KIND) {
|
|
const editor = parseSkateEditor(event);
|
|
return editor ? { ...editor, profileType: 'editor' as const } : null;
|
|
}
|
|
|
|
return null;
|
|
},
|
|
enabled: !!identifier,
|
|
staleTime: 30000,
|
|
refetchOnMount: 'always',
|
|
});
|
|
}
|