SkateSpots/src/hooks/useMyLabProfile.ts
SkateSpots 84d1ba426d feat(lab): craft profiles are now editable + add a title/headline field
Audit of the Lab 'offer a service' flows found two cross-cutting gaps:
1. Every Lab card showed the name TWICE (the card renders a 'title' line, but
   all forms wrote title = the kind-0 display name). The field is meant to be a
   self-described headline.
2. Only the Skater flow could be edited; the 7 craft roles started blank and
   silently overwrote the previous profile on submit.

Fixes (shared CraftProfileForm -> 7 roles: artist, graffiti, tattoo, trainer,
musician, judge, organizer):
- New useMyLabProfileEvent(kind, identifier) hook; the form prefills from your
  existing profile and becomes an EDIT (button: Update Profile; toast: updated).
- New 'Name / headline' field -> the  tag (defaults to your name).
- Lab ProfileCard only shows the title line when it differs from the name.

Gate: 101 tests, 0 errors/warnings, boot smoke green.
2026-09-27 00:17:05 +07:00

30 lines
1.1 KiB
TypeScript

import { useQuery } from '@tanstack/react-query';
import type { NostrEvent } from '@nostrify/nostrify';
import { useSkateRelays } from '@/hooks/useSkateRelays';
import { useCurrentUser } from '@/hooks/useCurrentUser';
/**
* The current user's existing Lab profile **event** for a given kind + fixed
* `d` identifier, so a "Become …" form can prefill and edit what was already
* published (instead of always starting blank and silently overwriting).
*/
export function useMyLabProfileEvent(kind: number, identifier: string) {
const { querySkateContent, getQueryKeySuffix } = useSkateRelays();
const { user } = useCurrentUser();
return useQuery<NostrEvent | null>({
queryKey: ['my-lab-profile', kind, identifier, user?.pubkey, getQueryKeySuffix()],
enabled: !!user?.pubkey,
staleTime: 30_000,
refetchOnMount: 'always',
queryFn: async () => {
if (!user?.pubkey) return null;
const signal = AbortSignal.timeout(10000);
const events = await querySkateContent(
[{ kinds: [kind], authors: [user.pubkey], '#d': [identifier], limit: 1 }],
{ signal },
);
return events[0] ?? null;
},
});
}