diff --git a/src/components/form/base.tsx b/src/components/form/base.tsx index e0fa4b2e..9f982d56 100644 --- a/src/components/form/base.tsx +++ b/src/components/form/base.tsx @@ -8,6 +8,7 @@ import { relaysAtom } from '@stores/relays'; import { dateToUnix } from '@utils/getDate'; import { ImageIcon, ResetIcon } from '@radix-ui/react-icons'; +import { sendNotification } from '@tauri-apps/api/notification'; import { useAtom, useAtomValue } from 'jotai'; import { useResetAtom } from 'jotai/utils'; import { getEventHash, signEvent } from 'nostr-tools'; @@ -35,8 +36,12 @@ export default function FormBase() { event.id = getEventHash(event); event.sig = signEvent(event, privkey); + // publish note pool.publish(event, relays); - resetValue; + // reset form + resetValue(); + // send notification + sendNotification('Note has been published successfully'); }; return ( diff --git a/src/components/form/comment.tsx b/src/components/form/comment.tsx index 5c9ee04c..be2a9697 100644 --- a/src/components/form/comment.tsx +++ b/src/components/form/comment.tsx @@ -2,26 +2,22 @@ import { ImageWithFallback } from '@components/imageWithFallback'; import { RelayContext } from '@components/relaysProvider'; import { activeAccountAtom } from '@stores/account'; -import { noteContentAtom } from '@stores/note'; import { relaysAtom } from '@stores/relays'; import { dateToUnix } from '@utils/getDate'; -import EmojiPicker from '@emoji-mart/react'; -import { ImageIcon } from '@radix-ui/react-icons'; +import { sendNotification } from '@tauri-apps/api/notification'; import destr from 'destr'; import { useAtom, useAtomValue } from 'jotai'; -import { useResetAtom } from 'jotai/utils'; import { getEventHash, signEvent } from 'nostr-tools'; -import { useContext } from 'react'; +import { useContext, useState } from 'react'; export default function FormComment({ eventID }: { eventID: any }) { const pool: any = useContext(RelayContext); const relays = useAtomValue(relaysAtom); const [activeAccount] = useAtom(activeAccountAtom); - const [value, setValue] = useAtom(noteContentAtom); - const resetValue = useResetAtom(noteContentAtom); + const [value, setValue] = useState(''); const profile = destr(activeAccount.metadata); @@ -36,8 +32,10 @@ export default function FormComment({ eventID }: { eventID: any }) { event.id = getEventHash(event); event.sig = signEvent(event, activeAccount.privkey); + // publish note pool.publish(event, relays); - resetValue; + // send notification + sendNotification('Comment has been published successfully'); }; return ( diff --git a/src/components/note/comment.tsx b/src/components/note/comment.tsx new file mode 100644 index 00000000..023d66c0 --- /dev/null +++ b/src/components/note/comment.tsx @@ -0,0 +1,79 @@ +import NoteMetadata from '@components/note/metadata'; +import { ImagePreview } from '@components/note/preview/image'; +import { VideoPreview } from '@components/note/preview/video'; +import { NoteRepost } from '@components/note/repost'; +import { UserExtend } from '@components/user/extend'; +import { UserMention } from '@components/user/mention'; + +import destr from 'destr'; +import { memo, useMemo } from 'react'; +import ReactPlayer from 'react-player/lazy'; +import reactStringReplace from 'react-string-replace'; + +export const NoteComment = memo(function NoteComment({ event }: { event: any }) { + const content = useMemo(() => { + let parsedContent = event.content; + // get data tags + const tags = destr(event.tags); + // handle urls + parsedContent = reactStringReplace(parsedContent, /(https?:\/\/\S+)/g, (match, i) => { + if (match.toLowerCase().match(/\.(jpg|jpeg|gif|png|webp)$/)) { + // image url + return ; + } else if (ReactPlayer.canPlay(match)) { + return ; + } else { + return ( + + {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') { + // @-mentions + return ; + } else if (tags[match][0] === 'e') { + // note-mentions + return ; + } else { + return; + } + }); + } + + return parsedContent; + }, [event.content, event.tags]); + + return ( +
+
+ +
+
+
+ {content} +
+
+
+
e.stopPropagation()} className="mt-5 pl-[52px]"> + +
+
+
+ ); +}); diff --git a/src/pages/newsfeed/[id].tsx b/src/pages/newsfeed/[id].tsx index 4207a498..26735c08 100644 --- a/src/pages/newsfeed/[id].tsx +++ b/src/pages/newsfeed/[id].tsx @@ -2,6 +2,7 @@ import BaseLayout from '@layouts/base'; import WithSidebarLayout from '@layouts/withSidebar'; import FormComment from '@components/form/comment'; +import { NoteComment } from '@components/note/comment'; import { NoteExtend } from '@components/note/extend'; import { RelayContext } from '@components/relaysProvider'; @@ -50,12 +51,7 @@ export default function Page() {
- {comments.length > 0 && - comments.map((comment) => ( -

- {comment.id}-{comment.content} -

- ))} + {comments.length > 0 && comments.map((comment) => )}
);