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>
214 lines
6.2 KiB
TypeScript
214 lines
6.2 KiB
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import { SKATE_SHOP_KIND, SKATE_SPOT_KIND, parseSkateShop, parseSkateSpot, type SkateShop } from '@/lib/types';
|
|
import { useSkateRelays } from '@/hooks/useSkateRelays';
|
|
|
|
export function useShops(limit = 100) {
|
|
const { querySkateContent, getQueryKeySuffix } = useSkateRelays();
|
|
|
|
return useQuery({
|
|
queryKey: ['skate-shops', limit, getQueryKeySuffix()],
|
|
queryFn: async () => {
|
|
const signal = AbortSignal.timeout(10000);
|
|
|
|
console.log('[useShops] Querying for shops');
|
|
|
|
// Query new shop kind (30017)
|
|
const newShops = await querySkateContent(
|
|
[
|
|
{
|
|
kinds: [SKATE_SHOP_KIND],
|
|
'#t': ['skateshop'],
|
|
limit,
|
|
},
|
|
],
|
|
{ signal }
|
|
);
|
|
console.log(`[useShops] Received ${newShops.length} new shops (kind 30017)`);
|
|
|
|
// Query old shops (kind 30818 with 'shop' type) for backward compatibility
|
|
const oldShops = await querySkateContent(
|
|
[
|
|
{
|
|
kinds: [SKATE_SPOT_KIND],
|
|
'#t': ['shop'],
|
|
limit,
|
|
},
|
|
],
|
|
{ signal }
|
|
);
|
|
console.log(`[useShops] Received ${oldShops.length} old shops (kind 30818)`);
|
|
|
|
const allEvents = [...newShops, ...oldShops];
|
|
|
|
const shops: SkateShop[] = [];
|
|
for (const event of allEvents) {
|
|
// Try parsing as new shop (kind 30017)
|
|
let shop = parseSkateShop(event);
|
|
|
|
// If that fails, try parsing as old spot and convert to shop
|
|
if (!shop && event.kind === SKATE_SPOT_KIND) {
|
|
const spot = parseSkateSpot(event);
|
|
if (spot && spot.types.includes('shop')) {
|
|
// Convert old spot-type shop to new shop format
|
|
shop = {
|
|
id: spot.id,
|
|
pubkey: spot.pubkey,
|
|
identifier: spot.identifier,
|
|
name: spot.title,
|
|
description: spot.description,
|
|
geohash: spot.geohash,
|
|
location: spot.location,
|
|
images: spot.images,
|
|
phone: undefined,
|
|
email: undefined,
|
|
website: undefined,
|
|
instagram: undefined,
|
|
hours: undefined,
|
|
createdAt: spot.createdAt,
|
|
event: spot.event,
|
|
};
|
|
}
|
|
}
|
|
|
|
if (shop) {
|
|
shops.push(shop);
|
|
} else {
|
|
console.warn('[useShops] Failed to parse event:', event);
|
|
}
|
|
}
|
|
|
|
console.log('[useShops] Parsed shops:', shops.length);
|
|
|
|
// Sort by created_at descending
|
|
return shops.sort((a, b) => b.createdAt - a.createdAt);
|
|
},
|
|
staleTime: 30000,
|
|
gcTime: 300000,
|
|
refetchOnMount: 'always',
|
|
});
|
|
}
|
|
|
|
export function useShop(identifier: string, pubkey?: string) {
|
|
const { querySkateContent, getQueryKeySuffix } = useSkateRelays();
|
|
|
|
return useQuery({
|
|
queryKey: ['skate-shop', identifier, pubkey, getQueryKeySuffix()],
|
|
queryFn: async () => {
|
|
const signal = AbortSignal.timeout(10000);
|
|
|
|
console.log(`[useShop] Querying for shop: ${identifier}`);
|
|
|
|
// Query new shop format (kind 30017)
|
|
const newFilter: {
|
|
kinds: number[];
|
|
'#d': string[];
|
|
authors?: string[];
|
|
limit: number;
|
|
} = {
|
|
kinds: [SKATE_SHOP_KIND],
|
|
'#d': [identifier],
|
|
limit: 1,
|
|
};
|
|
if (pubkey) newFilter.authors = [pubkey];
|
|
|
|
const newShops = await querySkateContent([newFilter], { signal });
|
|
console.log(`[useShop] Received ${newShops.length} new shops`);
|
|
|
|
// Query old shop format (kind 30818 with 'shop' type) for backward compatibility
|
|
const oldFilter: {
|
|
kinds: number[];
|
|
'#d': string[];
|
|
'#t': string[];
|
|
authors?: string[];
|
|
limit: number;
|
|
} = {
|
|
kinds: [SKATE_SPOT_KIND],
|
|
'#d': [identifier],
|
|
'#t': ['shop'],
|
|
limit: 1,
|
|
};
|
|
if (pubkey) oldFilter.authors = [pubkey];
|
|
|
|
const oldShops = await querySkateContent([oldFilter], { signal });
|
|
console.log(`[useShop] Received ${oldShops.length} old shops`);
|
|
|
|
const allEvents = [...newShops, ...oldShops];
|
|
|
|
if (allEvents.length === 0) {
|
|
console.warn(`[useShop] No events found for identifier: ${identifier}`);
|
|
return null;
|
|
}
|
|
|
|
// If multiple events, take the most recent
|
|
const mostRecent = allEvents.reduce((latest, current) =>
|
|
current.created_at > latest.created_at ? current : latest
|
|
);
|
|
|
|
// Try parsing as new shop first
|
|
let shop = parseSkateShop(mostRecent);
|
|
|
|
// If that fails, try parsing as old spot and convert
|
|
if (!shop && mostRecent.kind === SKATE_SPOT_KIND) {
|
|
const spot = parseSkateSpot(mostRecent);
|
|
if (spot && spot.types.includes('shop')) {
|
|
shop = {
|
|
id: spot.id,
|
|
pubkey: spot.pubkey,
|
|
identifier: spot.identifier,
|
|
name: spot.title,
|
|
description: spot.description,
|
|
geohash: spot.geohash,
|
|
location: spot.location,
|
|
images: spot.images,
|
|
phone: undefined,
|
|
email: undefined,
|
|
website: undefined,
|
|
instagram: undefined,
|
|
hours: undefined,
|
|
createdAt: spot.createdAt,
|
|
event: spot.event,
|
|
};
|
|
}
|
|
}
|
|
|
|
return shop;
|
|
},
|
|
enabled: !!identifier,
|
|
staleTime: 30000,
|
|
refetchOnMount: 'always',
|
|
});
|
|
}
|
|
|
|
export function useUserShops(pubkey: string) {
|
|
const { querySkateContent, getQueryKeySuffix } = useSkateRelays();
|
|
|
|
return useQuery({
|
|
queryKey: ['user-skate-shops', pubkey, getQueryKeySuffix()],
|
|
queryFn: async () => {
|
|
const signal = AbortSignal.timeout(10000);
|
|
|
|
const events = await querySkateContent(
|
|
[
|
|
{
|
|
kinds: [SKATE_SHOP_KIND],
|
|
authors: [pubkey],
|
|
'#t': ['skateshop'],
|
|
limit: 50,
|
|
},
|
|
],
|
|
{ signal }
|
|
);
|
|
|
|
const shops: SkateShop[] = [];
|
|
for (const event of events) {
|
|
const shop = parseSkateShop(event);
|
|
if (shop) shops.push(shop);
|
|
}
|
|
|
|
return shops.sort((a, b) => b.createdAt - a.createdAt);
|
|
},
|
|
enabled: !!pubkey,
|
|
staleTime: 30000,
|
|
refetchOnMount: 'always',
|
|
});
|
|
}
|