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>
92 lines
No EOL
3.1 KiB
TypeScript
92 lines
No EOL
3.1 KiB
TypeScript
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
import { useNostrPublish } from '@/hooks/useNostrPublish';
|
|
import { NKinds, type NostrEvent } from '@nostrify/nostrify';
|
|
|
|
interface PostCommentParams {
|
|
root: NostrEvent | URL; // The root event to comment on
|
|
reply?: NostrEvent | URL; // Optional reply to another comment
|
|
content: string;
|
|
}
|
|
|
|
/** Post a NIP-22 (kind 1111) comment on an event. */
|
|
export function usePostComment() {
|
|
const { mutateAsync: publishEvent } = useNostrPublish();
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: async ({ root, reply, content }: PostCommentParams) => {
|
|
const tags: string[][] = [];
|
|
|
|
// d-tag identifiers
|
|
const dRoot = root instanceof URL ? '' : root.tags.find(([name]) => name === 'd')?.[1] ?? '';
|
|
const dReply = reply instanceof URL ? '' : reply?.tags.find(([name]) => name === 'd')?.[1] ?? '';
|
|
|
|
// Root event tags
|
|
if (root instanceof URL) {
|
|
tags.push(['I', root.toString()]);
|
|
} else if (NKinds.addressable(root.kind)) {
|
|
tags.push(['A', `${root.kind}:${root.pubkey}:${dRoot}`]);
|
|
} else if (NKinds.replaceable(root.kind)) {
|
|
tags.push(['A', `${root.kind}:${root.pubkey}:`]);
|
|
} else {
|
|
tags.push(['E', root.id]);
|
|
}
|
|
if (root instanceof URL) {
|
|
tags.push(['K', root.hostname]);
|
|
} else {
|
|
tags.push(['K', root.kind.toString()]);
|
|
tags.push(['P', root.pubkey]);
|
|
}
|
|
|
|
// Reply event tags
|
|
if (reply) {
|
|
if (reply instanceof URL) {
|
|
tags.push(['i', reply.toString()]);
|
|
} else if (NKinds.addressable(reply.kind)) {
|
|
tags.push(['a', `${reply.kind}:${reply.pubkey}:${dReply}`]);
|
|
} else if (NKinds.replaceable(reply.kind)) {
|
|
tags.push(['a', `${reply.kind}:${reply.pubkey}:`]);
|
|
} else {
|
|
tags.push(['e', reply.id]);
|
|
}
|
|
if (reply instanceof URL) {
|
|
tags.push(['k', reply.hostname]);
|
|
} else {
|
|
tags.push(['k', reply.kind.toString()]);
|
|
tags.push(['p', reply.pubkey]);
|
|
}
|
|
} else {
|
|
// If this is a top-level comment, use the root event's tags
|
|
if (root instanceof URL) {
|
|
tags.push(['i', root.toString()]);
|
|
} else if (NKinds.addressable(root.kind)) {
|
|
tags.push(['a', `${root.kind}:${root.pubkey}:${dRoot}`]);
|
|
} else if (NKinds.replaceable(root.kind)) {
|
|
tags.push(['a', `${root.kind}:${root.pubkey}:`]);
|
|
} else {
|
|
tags.push(['e', root.id]);
|
|
}
|
|
if (root instanceof URL) {
|
|
tags.push(['k', root.hostname]);
|
|
} else {
|
|
tags.push(['k', root.kind.toString()]);
|
|
tags.push(['p', root.pubkey]);
|
|
}
|
|
}
|
|
|
|
const event = await publishEvent({
|
|
kind: 1111,
|
|
content,
|
|
tags,
|
|
});
|
|
|
|
return event;
|
|
},
|
|
onSuccess: (_, { root }) => {
|
|
// Invalidate and refetch comments
|
|
queryClient.invalidateQueries({
|
|
queryKey: ['comments', root instanceof URL ? root.toString() : root.id]
|
|
});
|
|
},
|
|
});
|
|
} |