(a) Review queue covers spots/shops/events/tours/gear: added { includeHidden }
(admin-tooling only) to useSkateShops/useSkateEvents/useTours/
useMarketplaceItems; generalised the flags to contentFlags() in spotQuality.ts
(trust/status/photo signals stay spot-only); one component per kind so only the
OPEN tab queries. Reports + trust are kind-agnostic; the label mechanism never
cared about kind.
(b) Photo gate softened: removed the hard block (it punished an honest mapper with
no photo). Publish without a photo is allowed; the spot stays Unverified, the
success toast says so, and the queue's 'no photo' flag lets a human look.
(c) Empty-map nudge: MapPage now distinguishes a FILTER empty ('No spots match')
from a genuinely EMPTY map ('No spots mapped yet — be the first to map your
park', with Add-spot + Near-me). Note: must key off allLocations, not mapSpots
(which derives from filteredSpots).
Verified in the browser: the empty-map nudge renders with its CTAs when no spots
load; the review queue renders 15 spot rows and the tabs switch (Gear shows its
own empty state). tsc/eslint clean, 101 tests, smoke PASS.
83 lines
2.6 KiB
TypeScript
83 lines
2.6 KiB
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import { SKATE_SHOP_KIND, parseSkateShop, type SkateShop } from '@/lib/types';
|
|
import { useSkateRelays } from '@/hooks/useSkateRelays';
|
|
import { useAdminModeration, filterAdminHidden } from '@/hooks/useAdminModeration';
|
|
|
|
/**
|
|
* Hook to fetch skate shops using the skate relay logic
|
|
*/
|
|
export function useSkateShops(limit: number = 100, options: { includeHidden?: boolean } = {}) {
|
|
const { includeHidden = false } = options;
|
|
const { querySkateContent, getQueryKeySuffix } = useSkateRelays();
|
|
const hidden = useAdminModeration();
|
|
|
|
return useQuery<SkateShop[], Error, SkateShop[]>({
|
|
queryKey: ['skate-shops', limit, getQueryKeySuffix()],
|
|
// `includeHidden` is for ADMIN TOOLING only (the review queue) so a hidden
|
|
// item stays visible and its verdict can be undone.
|
|
select: (shops: SkateShop[]) =>
|
|
includeHidden ? shops : filterAdminHidden(shops, SKATE_SHOP_KIND, hidden),
|
|
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();
|
|
const hidden = useAdminModeration();
|
|
|
|
return useQuery<SkateShop | null, Error, SkateShop | null>({
|
|
queryKey: ['skate-shop', pubkey, identifier, getQueryKeySuffix()],
|
|
select: (shop: SkateShop | null) =>
|
|
shop && hidden.has({ coord: `${SKATE_SHOP_KIND}:${shop.pubkey}:${shop.identifier}`, id: shop.id })
|
|
? null
|
|
: shop,
|
|
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,
|
|
});
|
|
}
|