refactor note component & add support for kind 30023
This commit is contained in:
@@ -3,8 +3,6 @@ import { useState } from 'react';
|
||||
import { Button } from '@shared/button';
|
||||
import { Image } from '@shared/image';
|
||||
|
||||
import { FULL_RELAYS } from '@stores/constants';
|
||||
|
||||
import { useNostr } from '@utils/hooks/useNostr';
|
||||
import { useProfile } from '@utils/hooks/useProfile';
|
||||
import { displayNpub } from '@utils/shortenKey';
|
||||
@@ -16,7 +14,7 @@ export function NoteReplyForm({ id, pubkey }: { id: string; pubkey: string }) {
|
||||
const [value, setValue] = useState('');
|
||||
|
||||
const submit = () => {
|
||||
const tags = [['e', id, FULL_RELAYS[0], 'reply']];
|
||||
const tags = [['e', id, '', 'reply']];
|
||||
|
||||
// publish event
|
||||
publish({ content: value, kind: 1, tags });
|
||||
|
||||
@@ -4,9 +4,9 @@ import { NoteActions, NoteContent, SubReply } from '@shared/notes';
|
||||
import { User } from '@shared/user';
|
||||
|
||||
import { parser } from '@utils/parser';
|
||||
import { LumeEvent } from '@utils/types';
|
||||
import { NDKEventWithReplies } from '@utils/types';
|
||||
|
||||
export function Reply({ event, root }: { event: LumeEvent; root?: string }) {
|
||||
export function Reply({ event, root }: { event: NDKEventWithReplies; root?: string }) {
|
||||
const content = useMemo(() => parser(event), [event]);
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,23 +1,20 @@
|
||||
import { NDKEvent } from '@nostr-dev-kit/ndk';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { useNDK } from '@libs/ndk/provider';
|
||||
|
||||
import { NoteSkeleton, Reply } from '@shared/notes';
|
||||
|
||||
interface ReplyEvent extends NDKEvent {
|
||||
replies: Array<NDKEvent>;
|
||||
}
|
||||
import { NDKEventWithReplies } from '@utils/types';
|
||||
|
||||
export function RepliesList({ id }: { id: string }) {
|
||||
const { ndk } = useNDK();
|
||||
const { status, data } = useQuery(['thread', id], async () => {
|
||||
const { status, data } = useQuery(['note-replies', id], async () => {
|
||||
const events = await ndk.fetchEvents({
|
||||
kinds: [1],
|
||||
'#e': [id],
|
||||
});
|
||||
|
||||
const array = [...events] as unknown as ReplyEvent[];
|
||||
const array = [...events] as unknown as NDKEventWithReplies[];
|
||||
|
||||
if (array.length > 0) {
|
||||
const replies = new Set();
|
||||
@@ -74,7 +71,9 @@ export function RepliesList({ id }: { id: string }) {
|
||||
) : (
|
||||
data
|
||||
.reverse()
|
||||
.map((event: NDKEvent) => <Reply key={event.id} event={event} root={id} />)
|
||||
.map((event: NDKEventWithReplies) => (
|
||||
<Reply key={event.id} event={event} root={id} />
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { NDKEvent } from '@nostr-dev-kit/ndk';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import { NoteActions, NoteContent } from '@shared/notes';
|
||||
import { User } from '@shared/user';
|
||||
|
||||
import { parser } from '@utils/parser';
|
||||
import { LumeEvent } from '@utils/types';
|
||||
|
||||
export function SubReply({ event }: { event: LumeEvent }) {
|
||||
export function SubReply({ event }: { event: NDKEvent }) {
|
||||
const content = useMemo(() => parser(event), [event]);
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user