SkateSpots/src/hooks/useSkateShops.ts
shakespeare.diy e29d35f1e4 fix: restore full skate-spots source tree from misplaced src/src/ copy
The entire skate-spots codebase was accidentally copied into src/src/ and
public/public/ instead of src/ and public/ directly. This left the real
src/ directory as blank MKStack template stubs, explaining why the landing
page showed the default template instead of SkateSpots.

Changes made:
- Copied all files from src/src/ up to src/ (App.tsx, AppRouter.tsx, main.tsx,
  all pages, components, hooks, contexts, lib, i18n, test)
- Copied all files from public/public/ up to public/ (images, manifest, etc.)
- Deleted src/src/ and public/public/ nested directories
- Removed HelloWorld.tsx template stub from pages/
- Retained the previously fixed index.css (Tailwind v3 directives)

Full skate-spots feature set is now active:
- All 30+ routes (map, events, spots, coaches, marketplace, wallet, etc.)
- NWCProvider, LanguageProvider, PWAInstallPrompt, AmberCallbackHandler
- Skate community relays (goskatespots.nostr1.com, wotr.relatr.xyz, etc.)
- Outfit Variable font, Amber pre-check in main.tsx
- All hooks (useSkateSpots, useCoaches, useZaps, etc.)
- i18n support (en/es)

Co-authored-by: shakespeare.diy <assistant@shakespeare.diy>
2026-06-15 22:18:28 +07:00

71 lines
1.9 KiB
TypeScript

import { useQuery } from '@tanstack/react-query';
import { SKATE_SHOP_KIND, parseSkateShop, type SkateShop } from '@/lib/types';
import { useSkateRelays } from '@/hooks/useSkateRelays';
/**
* Hook to fetch skate shops using the skate relay logic
*/
export function useSkateShops(limit: number = 100) {
const { querySkateContent, getQueryKeySuffix } = useSkateRelays();
return useQuery<SkateShop[]>({
queryKey: ['skate-shops', limit, getQueryKeySuffix()],
queryFn: async () => {
const signal = AbortSignal.timeout(10000);
const events = await querySkateContent(
[{
kinds: [SKATE_SHOP_KIND],
'#t': ['skateshop'],
limit
}],
{ signal }
);
// Parse events into SkateShop objects
const shops: SkateShop[] = [];
for (const event of events) {
const shop = parseSkateShop(event);
if (shop) shops.push(shop);
}
// Sort by created_at descending
return shops.sort((a, b) => b.createdAt - a.createdAt);
},
staleTime: 60000, // 1 minute
});
}
/**
* Hook to fetch a single skate shop by pubkey and identifier
*/
export function useSkateShop(pubkey: string | undefined, identifier: string | undefined) {
const { querySkateContent, getQueryKeySuffix } = useSkateRelays();
return useQuery<SkateShop | null>({
queryKey: ['skate-shop', pubkey, identifier, getQueryKeySuffix()],
queryFn: async () => {
if (!pubkey || !identifier) return null;
const signal = AbortSignal.timeout(10000);
const events = await querySkateContent(
[{
kinds: [SKATE_SHOP_KIND],
authors: [pubkey],
'#d': [identifier],
limit: 1,
}],
{ signal }
);
if (events.length > 0) {
return parseSkateShop(events[0]);
}
return null;
},
enabled: !!pubkey && !!identifier,
staleTime: 30000,
});
}