diff --git a/src/components/note/content/extend.tsx b/src/components/note/content/extend.tsx new file mode 100644 index 00000000..f803ad74 --- /dev/null +++ b/src/components/note/content/extend.tsx @@ -0,0 +1,68 @@ +import NoteMetadata from '@components/note/content/metadata'; +import NotePreview from '@components/note/content/preview'; +import { UserLarge } from '@components/user/large'; +import { UserMention } from '@components/user/mention'; + +import destr from 'destr'; +import { memo, useMemo } from 'react'; +import reactStringReplace from 'react-string-replace'; + +export const ContentExtend = memo(function ContentExtend({ data }: { data: any }) { + const content = useMemo(() => { + let parsedContent; + // get data tags + const tags = destr(data.tags); + // remove all image urls + parsedContent = data.content.replace(/(https?:\/\/.*\.(jpg|jpeg|gif|png|webp|mp4|webm)((\?.*)$|$))/gim, ''); + // handle urls + parsedContent = reactStringReplace(parsedContent, /(https?:\/\/\S+)/g, (match, i) => ( + + {match} + + )); + // handle hashtags + parsedContent = reactStringReplace(parsedContent, /#(\w+)/g, (match, i) => ( + + #{match} + + )); + // handle mentions + if (tags.length > 0) { + parsedContent = reactStringReplace(parsedContent, /\#\[(\d+)\]/gm, (match, i) => { + if (tags[match][0] === 'p') { + return ; + } else { + // #TODO: handle mention other note + // console.log(tags[match]); + } + }); + } + + return parsedContent; + }, [data.content, data.tags]); + + return ( +
+ +
+
+
+ {content} +
+ +
+
+
e.stopPropagation()} + className="mt-5 flex items-center border-t border-b border-zinc-800 py-2" + > + +
+
+ ); +}); diff --git a/src/components/note/counter/comments.tsx b/src/components/note/counter/comments.tsx index 5303b9b4..cc648194 100644 --- a/src/components/note/counter/comments.tsx +++ b/src/components/note/counter/comments.tsx @@ -38,10 +38,7 @@ export const CommentsCounter = memo(function CommentsCounter({ const profile = JSON.parse(currentUser.metadata); const openThread = () => { - router.push({ - pathname: '/newsfeed/thread', - query: { id: eventID }, - }); + router.push(`/newsfeed/${eventID}`); }; const submitEvent = () => { diff --git a/src/components/note/form/comment.tsx b/src/components/note/form/comment.tsx index 82717d90..e22a5650 100644 --- a/src/components/note/form/comment.tsx +++ b/src/components/note/form/comment.tsx @@ -3,47 +3,59 @@ import { ImageWithFallback } from '@components/imageWithFallback'; import { dateToUnix } from '@utils/getDate'; -import { SizeIcon } from '@radix-ui/react-icons'; import { useLocalStorage } from '@rehooks/local-storage'; import { getEventHash, signEvent } from 'nostr-tools'; import { useContext, useState } from 'react'; -export default function FormComment() { +export default function FormComment({ eventID }: { eventID: any }) { const relayPool: any = useContext(RelayContext); const [relays]: any = useLocalStorage('relays'); const [currentUser]: any = useLocalStorage('current-user'); const [value, setValue] = useState(''); - - const pubkey = currentUser.id; - const privkey = currentUser.privkey; const profile = JSON.parse(currentUser.metadata); + const submitEvent = () => { + const event: any = { + content: value, + created_at: dateToUnix(), + kind: 1, + pubkey: currentUser.id, + tags: [['e', eventID]], + }; + event.id = getEventHash(event); + event.sig = signEvent(event, currentUser.privkey); + + relayPool.publish(event, relays); + }; + return (
- +
-
+