Skip to content

Commit

Permalink
fix commenting
Browse files Browse the repository at this point in the history
  • Loading branch information
KoalaSat committed Sep 12, 2024
1 parent 8c6f264 commit d98056b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/app/components/Markdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ export const Markdown: React.FC<MarkdownProps> = ({ text, dTag, loadingAuthors }
},
}

const mentionComponent = (npub: string): JSX.Element => {
const user = new NDKUser({ npub })
const mentionComponent = (bech32: string): JSX.Element => {
// @ts-expect-error
const hexpubkey = nip19.decode(bech32)?.data.pubkey
const user = new NDKUser({ hexpubkey })
const profile = authors?.[user.pubkey] ?? user?.profile
const name: string = profile?.displayName ?? profile?.name ?? t("shared.events.anonymous")
return loadingAuthors ?
<Skeleton.Input size="small" active />
: <Link strong href={`https://njump.me/${npub}`} target="_blank">{name}</Link>
: <Link strong href={`https://njump.me/${user.npub}`} target="_blank">{name}</Link>
}

const eventComponent = (nevent: string): JSX.Element => {
Expand Down Expand Up @@ -148,7 +150,7 @@ export const Markdown: React.FC<MarkdownProps> = ({ text, dTag, loadingAuthors }
const nostrSyntax = (): (tree: any) => void => {
return (tree) => {
visit(tree, 'text', (node) => {
const regex = /(?:nostr:)?((naddr|nevent|npub|nprofile|note1)[a-zA-Z0-9]+)/g
const regex = /(?:nostr:)?((naddr|nevent|npub|nprofile|note)1[a-zA-Z0-9]+)/g
const match = regex.exec(node.value)
if (match) {
node.type = 'root';
Expand Down
12 changes: 9 additions & 3 deletions src/app/pages/Topic/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const Topic: () => JSX.Element = () => {
const [topicEvent, setTopicEvent] = useState<NDKEvent>()
const [rootAuthor, setRootAuthor] = useState<NDKUserProfile | null>()

const [creatingComment, setCreatingComment] = useState<boolean>(false)
const [loadingAuthors, setLoadingAuthors] = useState<boolean>(true)
const [loadingComments, setLoadingComments] = useState<boolean>(true)
const [loadingReactions, setLoadingReactions] = useState<boolean>(true)
Expand Down Expand Up @@ -167,17 +168,19 @@ export const Topic: () => JSX.Element = () => {
}

const createComment = async (): Promise<void> => {
setCreatingComment(true)
const dTag = topicEvent?.dTag
if (topicEvent && dTag && naddr && content && content !== '') {
const newComment = new NDKEvent(ndk)
newComment.kind = 1
newComment.content = content

newComment.tags.push(topicEvent.tagReference())
topicEvent.tags.forEach((t) => {
if (t[0] === 'a') newComment.tags.push(t)
})

if (forumEvent) newComment.tags.push(['a', forumEvent.tagReference()[1]])
if (forumEvent?.kind) newComment.tags.push(['a', forumEvent.tagReference()[1]])
if (replyTo) replyTo.referenceTags().forEach((t) => newComment.tags.push(t))

newComment
Expand All @@ -189,6 +192,9 @@ export const Topic: () => JSX.Element = () => {
setReplyTo(undefined)
setContent('')
})
.finally(() => setCreatingComment(false))
} else {
setCreatingComment(false)
}
}

Expand Down Expand Up @@ -405,7 +411,7 @@ export const Topic: () => JSX.Element = () => {
</Col>
<Col span='22'>
<Row justify="end">
<Button onClick={createComment} disabled={!content || content === ''} type="primary" htmlType="submit" size="large" icon={<CommentIcon />} iconPosition="end" >
<Button loading={creatingComment} onClick={createComment} disabled={!content || content === ''} type="primary" htmlType="submit" size="large" icon={<CommentIcon />} iconPosition="end" >
{t('pages.topic.createComment')}
</Button>
</Row>
Expand All @@ -416,7 +422,7 @@ export const Topic: () => JSX.Element = () => {
</Row>
</Col>
<Col xs={0} md={7}>
<Row gutter={[0, 10]} >
<Row gutter={[0, 10]} style={{ marginTop: 32 }}>
<Col span={24}>
<ActiveUser />
</Col>
Expand Down

0 comments on commit d98056b

Please sign in to comment.